h f-G@sdZddlZddlZddlZddlTddlmZddlmZddlm Z ddl m Z m Z m Z mZddlmZddlTdd lmZdd l mZdd lmZd d ZGddde ZdS)zadistutils.command.sdist Implements the Distutils 'sdist' command (create a source distribution).N)*)glob)warn)Command)dir_utildep_util file_util archive_util)TextFile)FileList)log) convert_pathcCsddlm}ddlm}g}x6|jD](}|jd|d||dfq3W|j||jddS)zoPrint all possible values for the 'formats' option (used by the "--help-formats" command-line option). r) FancyGetopt)ARCHIVE_FORMATSzformats=Nz.List of available source distribution formats:)Zdistutils.fancy_getoptrZdistutils.archive_utilrkeysappendsortZ print_help)rrformatsformatrZd?d@ZdAdBZdCdDZdEdFZdGdHZdIdJZdKdLZd S)Zsdistz6create a source distribution (tarball, zip file, etc.)cCs|jS)zYCallable used for the check sub-command. Placed here so user_options can view it)metadata_check)selfrrrchecking_metadata&szsdist.checking_metadata template=t5name of manifest template file [default: MANIFEST.in] manifest=m)name of manifest file [default: MANIFEST] use-defaultsNRinclude the default file set in the manifest [default; disable with --no-defaults] no-defaults"don't include the default file setprunespecifically exclude files/directories that should not be distributed (build tree, RCS/CVS dirs, etc.) [default; disable with --no-prune]no-prune$don't automatically exclude anything manifest-onlyoEjust regenerate the manifest and then stop (implies --force-manifest)force-manifestfkforcibly regenerate the manifest and carry on as usual. Deprecated: now the manifest is always regenerated.formats=6formats for source distribution (comma-separated list)z keep-tempkz1keep the distribution tree around after creating zarchive file(s) dist-dir=dFdirectory to put the source distribution archive(s) in [default: dist]metadata-check[Ensure that all required elements of meta-data are supplied. Warn if any missing. [default]owner=u@Owner name used when creating a tar file [default: current user]group=gAGroup name used when creating a tar file [default: current group]z help-formatsz#list available distribution formatsZgztarposixzipntcheckcCsyd|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ dS)Nr) templatemanifest use_defaultsr' manifest_onlyZforce_manifestr keep_tempdist_dir archive_filesrownergroup)rrrrinitialize_optionsds            zsdist.initialize_optionsc Cs|jdkrd|_n|jdkr6d|_n|jd|jdkry|jtjg|_Wqtk rtdtjYqXnt j |j}|rt d|n|j dkrd|_ ndS)NZMANIFESTz MANIFEST.inrz}|j}|jds)| rWq)n|jj|q)W|jdS)zRead the manifest file (named by 'self.manifest') and use it to fill in 'self.filelist', the list of files to include in the source distribution. zreading manifest file '%s'#N) r rxrErstrip startswithrSrr{)rrEr|rrrr]xs  zsdist.read_manifestcCs|j|tj||d|jttdrHd}d|}nd}d|}|sntjdn tj|x_|D]W}tj j |stjd|qtj j ||}|j ||d|qW|j jj|dS) aCreate the directory tree that will become the source distribution archive. All directories implied by the filenames in 'files' are created under 'base_dir', and then we hard link or copy (if hard linking is unavailable) those files into place. Essentially, this duplicates the developer's source tree, but in a directory named after the distribution, containing only the files to be distributed. dry_runlinkZhardzmaking hard links in %s...Nzcopying files to %s...z)no files to distribute -- empty manifest?z#'%s' not a regular file -- skipping)ZmkpathrZ create_treerhasattrrOr rrxrZr[rlZ copy_filerXZmetadataZwrite_pkg_info)rrrsrr}filedestrrrmake_release_trees      zsdist.make_release_treec Cs|jj}tjj|j|}|j||jjg}d|j kr}|j j |j j |j j dnxd|j D]Y}|j ||d|d|jd|j}|j ||jjj dd|fqW||_|jstj|d|jndS) aCreate the source distribution(s). First, we create the release tree with 'make_release_tree()'; then, we create all required archive files (according to 'self.formats') from the release tree. Finally, we clean up by blowing away the release tree (unless 'self.keep_temp' is true). The list of archive files created is stored so it can be retrieved later by 'get_archive_files()'. ZtarrrKrLrrN)rXrrOrZrlrIrrSrsrrpopindexZ make_archiverKrLZ dist_filesrJrHrZ remove_treer)rrZ base_namerJZfmtrrrrrUs +    zsdist.make_distributioncCs|jS)zzReturn the list of archive files created when the command was run, or None if the command hasn't run yet. )rJ)rrrrget_archive_filesszsdist.get_archive_files)rrr)r r!r")r#Nr$)r%Nr&)zpruneNr()r)Nr*)r+r,r-)r.r/r0)r1Nr2)r4r5r6)r7Nr8)r9r:r;)r<r=r>)__name__ __module__ __qualname__Z descriptionrZ user_optionsZboolean_optionsrZ help_optionsZ negative_optrNZ sub_commandsrMrRrVrYrTr_r`rarbr\r]rrUrrrrrr"sn             ( P     * r)__doc__rOstringrtypesrwarningsrZdistutils.corerZ distutilsrrrr Zdistutils.text_filer Zdistutils.errorsZdistutils.filelistr r Zdistutils.utilr rrrrrrs    "