o dS@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z dZddZd d Zd d Zd dZddZddZddZddZdS)u& dcut — Debian command upload tool. N)dput) dputhelper)rmcancel reschedulecCstdttj}|S)z& Make the program usage help message. aO Usage: %s [options] [host] command [, command] Supported options (see man page for long forms): -c file Config file to parse. -d Enable debug messages. -h Display this help message. -s Simulate the commands file creation only. -v Display version information. -m maintaineraddress Use maintainer information in "Uploader:" field. -k keyid Use this keyid for signing. -O file Write commands to file. -U file Upload specified commands file (presently no checks). -i changes Upload a commands file to remove files listed in .changes. Supported commands: mv, rm (No paths or command-line options allowed on ftp-master.) )textwrapdedentr get_prognamesysargv)textr/usr/share/dput/dput/dcut.pymake_usage_messages rcCsd}|dr tjddtjvrEtjdddkr2tjdd}|r(|d 7}|d tjd7}ntjd}|drCtjd ||Sd tjvr~tjd ddkrktjdd}|ra|d 7}|d tjd 7}ntjd }|dr|tjd ||S|drtjd tt }|d}|d dd}z t d }Wn tyd}Ynw|s|drtjdtjddtjd}t|j}| }|rd|||f}|drtjd||S|drtjd|S)u5 Get the system value for the ‘uploader’ option. Ndebugz3D: trying to get maintainer email from environment DEBEMAILzD: Uploader from env: %s EMAILzD: Guessing uploader ,z /etc/mailnamez2D: Guessing uploader: /etc/mailname was a failure z/bin/hostname --fqdnT)shellstdoutz %s <%s@%s>zD: Guessed uploader: %s zD: Couldn't guess uploader )r rwriteosenvironfindgetpwdgetpwuidgetuidsplitopenreadstripIOError subprocessPopenPIPErmake_text_stream)optionsuploaderpwrecusernamefullnamehostnamehostname_subprocesshostname_stdoutrrrget_uploader_from_system5s~  +        r5c Csddddddddddd }ttj}t}dtjddvs)dtjddvr7d|d<tjd||fttjdddgd \}}|D]\}}|dr[tjd ||f|d vrmtjtt t j qI|d vrtjd ||ft t j qI|dvrd|d<qI|dvr||d<qI|dvr||d<qI|dvr||d<qI|dvrd|d<qI|dvrd|d<qI|dvr||d<qI|dvr||d<qI|dkr||d<qI|dvr||d <qItj d!|||ft dqI|ds|r|dt vr|d|d<|drtjd"|d|d=|dst||d<|dsG|ds.|d rGtj d#|tj d$t|d%t d||fS)&Nr) rsimulateconfighostr.keyidpassive filetocreate filetouploadchanges-dr--debugrz D: %s %s zc:dDhsvm:k:PU:O:i:) zconfig=rhelpr6versionzhost=zmaintainteraddress=zkeyid=r:zupload=zoutput=zinput=z$D: processing arg "%s", option "%s" )z-hz--help)z-vz --versionz%s %s )r>r?)z-cz--configr7)z-mz--maintaineraddressr.)z-kz--keyidr9)z-sz --simulater6)z-Pz --passiver:)z-Uz--uploadr<)z-Oz--outputr;z--hostr8)z-iz--inputr=z2%s internal error: Option %s, argument %s unknown z'D: first argument "%s" treated as host zB%s error: command file cannot be created without maintainer email z>%s please set $DEBEMAIL, $EMAIL or use the "-m" option r)rr r r get_distribution_versionrrgetoptrexitrEX_OKstderr validcommandsr5len)r-prognamerAopts argumentsoptionargrrr getoptionsus $                    rNcCsJg}|dd}|dg}|r|dtvr8|dg}|ddkr7t|dkr2|ddkr2|d=n_|dnY|sO|ddkrOtjd|dtdt|dddvrh||dddd |d<|ddvr|r|d rtjd d ||d |g}n||d|d=|s|stjd td|S)Nrrrz--nosearchdirsz --searchdirsz(Error: Could not parse commands at "%s" )r;rrrz$D: Successfully parsed command "%s" rz'Error: no arguments given, see dcut -h ) appendrGrHr rFrrDstrrjoin)rKr-r7commandscurargrrrparse_queuecommandssL         rVc Csjttj}|dr|d}n?tdtttdt j t j }dt j t j }t ||}|d |} |d| tttf}|rNtj||}t|d} | d|d| d d || d g} | d |d|d r| d|d | d||drtjd| zt| W|StjytjdtdY|Sw)aX Write a file of commands for the upload queue daemon. :param commands: Commands to write, as a sequence of text strings. :param options: Program configuration, as a mapping of options `{name: value}`. :param config: `ConfigParser` instance for this application. :param tempdir: Filesystem path to directory for temporary files. :return: Filesystem path of file which was written. Write the specified sequence of commands to a file, in the format required for the Debian upload queue management daemon. Once writing is finished, the file is signed using the 'debsign' command. If not specified in the configuration option 'filetocreate', a default filename is generated. In either case, the resulting filename is returned. r;r________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________r.z.%s.%d.%d.commandswz Uploader: %s zCommands: %s z debsignz-m%sr9z-k%sz%srzD: calling debsign: %s zError: debsign failed. r)rr r r rRrSmapchrrangestring ascii_lettersdigits maketrans translateinttimergetpidpathr%rcloserQrr) check_callCalledProcessErrorrFrD) rTr-r7tempdirrIfilenametranslationorigtranslationdesttranslationmapuploadpartfornamefdebsign_cmdlinerrrwrite_commandssJ       rrcCs4||ddkr d}n||d}|rtjd|dd|dd|vr8tjd|ddtd|rFtjd ||d||d|vr_tjd||dtd||dsl|dd}n||d}||d r||d d kr||d } nG|dd r|dd d kr|dd } n2d tjvrtjd } ntjd t t d} |rtjdt |rtjd|| f|rtjd| ||d} |s}|rtjd|tjd| tjd| |dkr4| |d} |dkr d} | dkr'|r'|dkr!tjdntjd|||| | ||| d'S|dkrp|rI| |drItjd| |d} dddd ||d! d"DD} |||| | ||| | d'S|||| | ||dd'S|D]}tjd#|||| ftjd$|d%d&qd'S)(ap Upload files to the host. :param host: Configuration host name. :param upload_methods: Mapping of {method_name: callable}. :param config: `ConfigParser` instance for this application. :param debug: If true, enable debugging output. :param simulate: If true, simulate the upload only. :param files_to_upload: Collection of file names to upload. :param ftp_passive_mode: If true, enable FTP passive mode. :return: ``None``. Upload the specified files to the host, using the method and credentials from the configuration for the host. methodlocal localhostfqdnzD: Default Method: %s DEFAULTzUnknown upload method: %s rzD: Host Method: %s loginr0USERz+$USER not set, will use login information. rzD: User-ID: %s z4D: Neither host %s nor default login used. Using %s zD: Login to use: %s incomingz D: FQDN: %s z D: Login: %s zD: Incoming: %s ftp passive_ftpzD: Using passive ftp zD: Using active ftp scp scp_compresszD: Setting compression for scp cSsg|]}|r|qSrr).0yrrr s z0upload_stolen_from_dput_main..css|]}|VqdS)N)r')rxrrr s z/upload_stolen_from_dput_main..ssh_config_options zUploading with %s: %s to %s:%s zcat %sT)rN)r r rrrFrD has_optionrrr!r"r# getbooleanr$r)call)r8upload_methodsr7rr6files_to_uploadftp_passive_modervrsrxrzftp_moder~r file_pathrrrupload_stolen_from_dput_main.s                      rc Csvt\}}|drtjdt|d|d}|dsO|ddrO|dd|d<|dr9tjd|d|dsOd|d<|drOtjd |dd}d}t tj }z|d sj|d sjt j |d d }|d s|ds}tjdt d||dstjd|dt dn$||ddr||dd}n|dd}|stjdt d|d r|rtjdd|t dd}|d }|dstjd|n"|drtj}t|||} t| |||}n t|||}t||||}|d s$tt} t|d| ||d|d|g|dW|r/t|dSdS|r:t|ww)NrzD: calling dput.read_configs r7r8rwdefault_host_mainz'D: Using host "%s" (default_host_main) z ftp-masterzD: Using host "%s" (hardcoded) r<r;.)prefixz8Error: No host specified and no default found in config rzNo host %s found in config allow_dcutz4Error: dcut is not supported for this upload queue. zLError: cannot take commands when uploading existing file, "%s" found rz .commandszXError: I'm insisting on the .commands extension, which "%s" doesnt seem to have. r=r6r:)rNr rrr read_configsrr rr r tempfilemkdtemprD has_sectionrrSendswith parse_changescreate_commandsrrrVimport_upload_functionsrshutilrmtree) r-rKr7rjrkrI dcut_allowedrTrremovecommandsrrrrdcuts                  rc Cs|d}|drtjd|zt|d}Wnty-tjd|tdYnw||}|jdtj |g}|d d D]}| d }d|} |dratjd || f| | qG|S) u Get the removal commands from a package changes file. Parse the specified ‘foo.changes’ file and returns commands to remove files named in it. r=rz1D: Parsing changes file (%s) for files to remove rzCan't open changes file: %s rzrm --searchdirs filesrrzD: Will remove %s with '%s' ) r rrr%r(rDrgrrfbasenamer'r$rQ) r-r7rchanges_file_path changes_filer=r file_specrrrrrrs.   r)__doc__rr!rr^r)r rrrdrrhelperrrGrr5rNrVrrrrrrrrrs*   @X)8u Q