o d@sdZddlZddlZddlmZmZddlZddlZddl Zddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlmZddlmZejeZdaddZd d Zd d Zej Z!d dZ"ddZ#ddZ$ddZ%ddZ&ddZ'ddZ(ddZ)ddZ*dd Z+d!d"Z,d#d$Z-d3d&d'Z.d(d)Z/d*d+Z0d,d-Z1td%d%d%d%d%d%d.d.d%d/d%d%dd%d0e1_2d1d2Z3dS)4u& dput — Debian package upload tool. N)md5sha1)crypto) dputhelpercCsi}d}tjt|}ddt|gD}tr tj d||D].}t dj dd|g|d}tr?tj d ||f|}trKtj d ||j ||<q"|S) z7 Import upload method modules and make them available. methodscSsg|] \}}}|s|qSr).0__nameispkgrr/usr/share/dput/dput/dput.py /s z+import_upload_functions..zD: modules_found: %r z{package}.{module}.dput)packagemodulezD: Module: %s (%r) zD: Method name: %s )ospathjoinapp_library_pathpkgutil iter_modulesdebugsysstdoutwrite importlib import_moduleformatupload)upload_methods package_name modules_path modules_found module_namer method_namerrr import_upload_functions)s(   r'cCs|d}|dkr|dn ||||ddks(||}tj|}d|vr}||dd$kr"||d%d&||d%s<||dd$krr binary_uploadarchrrr check_upload_variants rc Csdd}|rtjd|tjd||s"||ddkr>|s.assert_good_signature_or_exitzD: upload control file: {} zD: source control file: {} rGrzChecking signature on .changes zChecking signature on .dsc N)rrrr getboolean) hostchanges_file_path dsc_file_pathrl check_onlyrGrrrrrr verify_signatures$    rc Csd}}d|vrw|d}|rtjd||ddkr#d}||fS|ddkr:|r2tjd|dd\}}|d}|d|}||dd }|r_tjd |tjd ||d kso|d kso|dkso|dkrud}||fSd}||fS)zE Check if a source tarball has to be included in the package or not. rversionzD: Package Version: %s -r*r:zD: Epoch found NzD: Upstream Version: %s zD: Debian Version: %s z0.1rVz1.10ubuntu1)rrrr0r7rfind) r>r include_orig include_tarrepochposupstream_versiondebian_versionrrr source_checks4   rc Csd}} } } g} tj||} |rtjd| zt| d}Wnty8tjd| tdYnwt |}|j t ||}|rJd}n9d}|d d D] }| d }|d d kru|rntjd |tj||}qU|stjdtdz||ddks|rt|||Wn"tjy}ztjdt|tdWYd}~nd}~wwt|| ||||||t||\} } |d d }|dd}|D]}| \}}}}}tj||}|rtjd|t|||kr#|rtjd|tjdt||tjd|tdn |r.tjd|t|tjt|kr\|rTtjd|tjdt|tjtjd|| |q| D]Z}|dddkr| s|rtjd|tjd|ddtjdqd|d dd!kr| s| s|rtjd|tjd"|d dtjd#qd|d$}||d%}|r|r|rtjd&||ft||st d'||f|rtjd| | | | S)(a Run some tests on the files to verify that they are in good shape. :param changes_file_directory: Directory path of the upload control file. :param changes_file_name: Filename of the upload control file. :param host: Configuration host name. :param config: `ConfigParser` instance for this application. :param check_only: If true, no upload is requested. :param check_version: If true, check the package version before upload. :param allow_unsigned_uploads: If true, allow an unsigned upload. :param debug: If true, enable debugging output. :return: A collection of filesystem paths of all files to upload. rz*D: Validating contents of changes file %s rrrrKNr+r,rtz.dscr*zD: dsc-File: %s z-Error: no dsc file found in sourceful upload rOzError in config file: %s rArFzD: File to upload: %s zD: Checksum from .changes: %s zD: Generated Checksum: %s zChecksum doesn't match for %s zD: Checksum for %s is fine zD: size from .changes: %s zD: calculated size: %s zsize doesn't match for %s iz .orig.tar.gzzD: Filename: %s zD: Suffix: %s zPackage includes an .orig.tar.gz file although the debian revision suggests that it might not be required. Multiple uploads of the .orig.tar.gz may be rejected by the upload queue management software. iz.tar.gzzD: Suffix: %s zPackage includes a .tar.gz file although the version suggests that it might not be required. Multiple uploads of the .tar.gz may be rejected by the upload queue management software. distributionrLz(D: Checking: distribution %s matches %s z=Error: uploading files for distribution %s to %s not allowed.)!rrrrrrrarbr:r@rgrr6r7r0r9r version_checkr]NoSectionErrorrfrrrirstatST_SIZErxappendrematchrDputUploadFatalException)changes_file_directorychanges_file_namerrlrrOrGr file_seeninclude_orig_tar_gzinclude_tar_gz binary_onlyfiles_to_uploadrr;r>rrr? file_namerp file_listr check_sumsizerrpriority file_pathrrLrrr verify_files;s             rcCs(tjd|tjtjddS)z# Print the configuration and exit. r,N)rrr)rlrrrr print_configs  rc Cstj|d}tj||d|d}|rtjd|zt|tjr-t |d}nt |d}Wnt yItj d|t dYnw|D]} d tj | d |d |d } || qL|d S)up Write the log file for the upload. :param changes_file_name: File name of package to upload. :param host: Configuration host name. :param fqdn: Fully-qualified domain name of the remote host. :param changes_file_directory: Directory path of the upload control file. :param debug: If true, enable debugging output. :return: ``None``. The upload log file is named ‘basename.hostname.upload’, where “basename” is the package file name without suffix, and “hostname” is the name of the host as specified in the configuration file. For example, uploading ‘foo_1.2.3-1_xyz.deb’ to host ‘bar’ will be logged to ‘foo_1.2.3-1_xyz.bar.upload’. The upload log file is written to the directory containing the upload control file. rr.uploadzD: Writing logfile: %s awzCould not write %s rzSuccessfully uploaded z to z for z. N)rrsplitextrrrraccessR_OKrarbr9r:basenamerg) rrrZrrrchanges_file_name_base log_file_pathlog_filer log_entryrrr create_upload_files>     rcCst|tjrEtdtjr=ttjtj}tjdt dd|gt j kr4tjdt dd Sttj|dStjdd Stjd |t dd S) z> Run lintian on the changes file and stop if it finds errors. z/usr/bin/lintianz+Package is now being checked with lintian. lintianz-iz Lintian says this package is not compliant with the current policy. Please check the current policy and your package. Also see lintian documentation about overrides. rrz1lintian is not installed, skipping package test. zCan't read %s N) rrrsignalSIGPIPESIG_DFLrrrr check_callEXIT_STATUS_SUCCESSr:)r; old_signalrrr run_lintian_test s( rcCs2d}d}td}tj||}zt|d}Wnty-tj d|t dYnw| }|D]} | | } | rB| d}q4|ru|D]+} || d} | sTqI| dD]} || krstrmtj d | | f| SqYqIt|d d dkrtj d |d d |d d Stj d dS)u Guess the host where the package should be uploaded to. :param changes_file_directory: Directory path of the upload control file. :param changes_file_name: Filename of the upload control file. :param config: `ConfigParser` instance for this application. :return: The hostname determined for this upload. This is based on information from the upload control (‘*.changes’) file. rrKz^Distribution: (.*)rrrrJ,z-D: guessing host %s based on distribution %s rArQzTrying to upload package to %s z?Trying to upload package to ftp-master (ftp.upload.debian.org) z ftp-master)rcompilerrrrarbrrrr: readlinessearchgrouprhrir7r6rr8)rrrlnon_usrdist_rerr;lineslinerrr host_dists host_distrrr guess_upload_host%sV            rc Cs|dd||fdd|dddd|g}|r'tjd|||ftjd |t|tjkrrpackages_to_check dpkg_proc dpkg_stdout dpkg_stderr dpkg_outputdpkg_architecturedpkg_stderr_outputr?r dpkg_fieldsr"version_numberversion_to_checkinstalled_versionrrr rs            rFcCs4|r tjd|tj|ddrtd|dS)a  Run a command that the user-defined in the config_file. :param command: Command line to execute. :param position: Position of the command: 'pre' or 'post'. :param debug: If true, enable debugging output. :return: ``None``. zD: Command: %s T)rz Error: %s upload command failed.N)rrrrcallrr)rpositionrrrr execute_commands rc Csd}|ddd|d}|sb|sdtj|sdSzt|} Wnty6tjd|tdYnw| D] } | |dkrFd}q;|rftjd ||ftjd |tddSdSdSdS) a( Check if the user already put this package on the specified host. :param changes_file_path: Filesystem path of upload control file. :param host: Configuration host name. :param fqdn: Fully-qualified domain name of the remote host. :param check_only: If true, no upload is requested. :param run_lintian: If true, a Lintian invocation is requested. :param force_upload: If true, don't check the upload log file. :param debug: If true, enable debugging output. :return: ``None``. rNrrzCouldn't open %s rr*z.Package has already been uploaded to %s on %s zNothing more to do for %s ) rrexistsrarbrrrr:rr0) rrrZrrM force_uploadruploadedupload_logfile_pathupload_logfilerrrr check_upload_logfiles2     rcCstd}|S)z& Make the program usage help message. af Usage: dput [options] [host] Supported options (see man page for long forms): -c: Config file to parse. -d: Enable debug messages. -D: Run dinstall after upload. -e: Upload to a delayed queue. Takes an argument from 0 to 15. -f: Force an upload. -h: Display this help message. -H: Display a list of hosts from the config file. -l: Run lintian before upload. -U: Do not write a .upload file after uploading. -o: Only check the package. -p: Print the configuration. -P: Use passive mode for ftp uploads. -s: Simulate the upload only. -u: Don't check GnuPG signature. -v: Display version information. -V: Check the package version and then upload it. )textwrapdedent)textrrr make_usage_messages r c CsBt}tjD] \}}t|||q t|}t}zt |dddgd\}}Wn#tj yQ}zt j t|dt tjWYd}~nd}~ww|D]\} } | dvrjt j tt tjqT| dvrt j dj||d t tjqT| d vrd ad |_qT| d vrd |_qT| d vr| |_qT| dvrd |_qT| dvrd |_qT| dvrd |_qT| dvrd|_qT| dvrd |_qT| dvrd |_qT| dvrd |_qT| dvrd |_ qT| dvrd |_!qT| dvr| t"tt#dvr| |_$qTt j dt tjqT| dvr d |_%qTt&|dkrt j dt tj||fS)a Parse the command-line arguments to option values. :param argv: The command-line arguments, as a sequence of text strings. :return: A 2-tuple (`options`, `args`), where `options` is the collection of option values; `args` is the remaining arguments after removing all options. The `options` collection is a `SimpleNamespace` instance, with each value represented as a named attribute. rNzc:dDe:fhHlUopPsuvV)rrz check-onlyz check-versionzconfig=forcehelpz host-listrz no-upload-logpassiveprintsimulate uncheckedzdelayed=rr,)z-hz--help)z-vz --versionz{progname} {version} prognamer)z-dz--debugT)z-Dz --dinstall)z-cz--config)z-fz--force)z-Hz --host-list)z-lz --lintian)z-Uz--no-upload-logF)z-oz --check-only)z-pz--print)z-Pz --passive)z-sz --simulate)z-uz --unchecked)z-ez --delayedz;Incorrect delayed argument, dput only understands 0 to 15. )z-Vz--check_versionrz2No package or host has been provided, see dput -h )'typesSimpleNamespaceparse_commandlineoptions_defaultsitemssetattrr get_prognameget_distribution_versiongetopt DputExceptionrr9rrfr:rEX_USAGErr EX_OKrrrNrorconfig_host_listrM upload_logr config_printftp_passive_moderrGmaprange delay_uploadrOr8) argvoptionsr valuerroptsargsroptionargrrr r6s        rrKT)rrOr!rrMrr"preferred_hostrorNr rrGr%rc Csh t}t}trtjdj||dz ttj \}}Wnt y3}z |j WYd}~Sd}~wwdt j vrJt j d}|jrItjd|n$tjdtt d}|jrntjdt tjd|t|j|j}|jrt||jtt j|jrtjd |d d |D]&}d }||d rd||d }tjd|||d||d |fqtjdtt jt|dkr|js|dd} nd|dvrtjd|d|ddd\|d<} nd } ||drtjd||d|d| n |jsy|jr#tjd||drE|jr9tjd|d|d|_|dd} n||dse|d dsetj!d|dtdnx|jrotjdd |_|dd} nd|jrtjd||drtjd|d|d|_|dd} n}|j6rd}|jr=tjd?||dkr7tjd@ntjdA| ||||||j|||dBno|dCkr|jrc|,|dDrctjdE|,|dD}dFdGdHdI||dJdDD}|jrtjdKdL.|d| ||||||j||n!| ||||||jd|dMn|D]}tjdN||||fq|j2s|j7rt8|||| ||jtjdOntjdP|jrtjdQ|j9tjdR|,|dS|,|dSdks|j9r|j2st:||||||jntjdTt||dUdkr0dV}||dU}t/|||jqdS)Wz% Mainline function for this program. zD: {progname} {version} rNUSERz D: Login: %s z+$USER not set, will use login information. rzD: User-ID: %s z Default Method: %s rArDrKrJz, distributions: %sz %s => %s (Upload method: %s%s) rZr,rrz'D: Splitting host argument out of %s. zD: Setting host argument. z5D: Checking if a host was named on the command line. zD: Host %s found in config. z.changeszNo host %s found in config. z"D: No host named on command line. z"D: Checking for the package name. rz>Not a .changes file. Please select a .changes file to upload. zTried to upload: %s rYr[zE: No host %s found in configrMzWarning: The option -o does not automatically include a lintian run any more. Please use the option -ol if you want to include running lintian in your checking. zPackage checked by dput. rSprezD: Default Method: %s zUnknown upload method: %s zD: Host Method: %s rBrCz!D: Login %s from section %s used zD: Default login %s used z4D: Neither host %s nor default login used. Using %s r\rXzUploading to DELAYED/0-day. r*/zDELAYED/z-dayz [DELAYED/]z"Uploading to %s%s (via %s to %s): z D: FQDN: %s zD: Incoming: %s rWftprUzD: FTP port: %s zD: Using passive ftp zD: Using active ftp )progressportrErPzD: Setting compression for scp cSsg|]}|r|qSrr)r yrrr rs zmain..css|]}|VqdS)N)r6)r xrrr s zmain..rTzD: ssh config options: z )r4zUploading with %s: %s to %s:%s z Successfully uploaded packages. zSimulated upload. zD: run_dinstall: %s zD: Host Config: %s rNzWill run dinstall now. rRpost);rrrrrrrrrr& SystemExitcoderenvironpwdgetpwuidgetuidrsror!rr:rrrirhr8rr7 has_sectionr_r-rr9r'rgetcwdrrrMrrrOrGrrrrr%rxrgetintisattyrsplitr"r rrNr)rrr'r*rrBrlrrrJchanges_file_paths host_argumentr!rrrrrZrrrrDr\ first_charrXr4 port_textr5ftp_moderPrTrrrr mainsd                                                                  rJ)F)4__doc__r] email.parserr1hashlibrrrros.pathrr=rrrrzrrrrrKrhelperrrdirname__file__rrr'r@rs hexdigitsryr~rrrrrrrrrrrrrr rrrJrrrr sv    S #, 29" i$Y