o d @sdZddlZddlZddlZddlZddlZddlZddlZGdddeZ Gddde Z dZ dZ dZ d d ZGd d d Zd dZdddZddZddZdS)z Helper code for Dput. Nc@ eZdZdS) DputExceptionN__name__ __module__ __qualname__rr)/usr/share/dput/dput/helper/dputhelper.pyrrc@r)DputUploadFatalExceptionNrrrrr r r r c Os|d}ztj|g|Ri|t}W|StjyP}z.|j}|tkr0tjdj |dntjdj |d |dWYd}~|SWYd}~|Sd}~ww)z1 Wrap `subprocess.check_call` with error output. rzWError: Failed to execute '{path}'. The file may not exist or not be executable. )pathzTWarning: The execution of '{path}' as '{command}' returned a nonzero exit code.  )rcommandN) subprocess check_callEXIT_STATUS_SUCCESSCalledProcessError returncodeEXIT_STATUS_COMMAND_NOT_FOUNDsysstderrwriteformatjoin)argsposargskwargscommand_file_path exit_statusexcrrr r#s2   rc@sFeZdZdZdejddfddZddZdd d Zd d Z d dZ dS)FileWithProgressa Mimics a file (passed as f, an open file), but with progress. FileWithProgress(f, args) args: * ptype = 1,2 is the type ("|/-" or numeric), default 0 (no progress) * progressf = file to output progress to (default sys.stdout) * size = size of file (or -1, the default, to ignore) for numeric output * step = stepsize (default 1024) rcCsD||_d|_d|_||_d|_gd|_||_||_||_d|_ dS)Nr)|/-\) fcount lastupdateptypeppos progresschars progressfsizestepclosed)selfr)r,r/r0r1rrr __init__Hs  zFileWithProgress.__init__cCs t|j|SN)getattrr))r3namerrr __getattr__T zFileWithProgress.__getattr__cCs|j|}|jt||_|j|jdkr|jdkrB|jdt|j|_|j |jdkd|j|j|j |j|_|S|jdkrt |j|j d}|j dkri|dt |j |j d|j d7}|t|jt|dd7}|j |jd||j t||_|S) Nr$r rkr&r)r)readr*lenr+r,r-r.r/rflushstrr1r0min)r3r0asrrr r=Ws4         zFileWithProgress.readcCs|jsA|jd|_|jdkr"|jr |jd|jdSdS|jdkrC|j|jd|jd|jd|jdSdSdS)Nr z r;r:r) r2r)closer,r+r/rr?r-r3rrr rDns    zFileWithProgress.closecCs |dSr5)rDrErrr __del__{r9zFileWithProgress.__del__N)r#) rrr__doc__rstdoutr4r8r=rDrFrrrr r":s   r"cCsFd}t|dr |j}ntd}t|tjr|}|Stj||d}|S)a Make a text stream from the specified stream. :param stream: An open file-like object. :return: A stream object providing text I/O. In the normal case, the specified stream is a stream providing bytes I/O. We create an `io.TextIOWrapper` with the appropriate encoding for the byte stream, and return that wrapper stream. The text encoding is determined by interrogating the file object. If the file object has no declared encoding, the default `locale.getpreferredencoding(False)` is used. If the stream is a `io.TextIOBase` instance, it is already providing text I/O. In this case, the stream is returned as is. NencodingF)rI)hasattrrIlocalegetpreferredencoding isinstanceio TextIOBase TextIOWrapper)streamresultrIrrr make_text_streams   rScCs"|durtj}tj|d}|S)z Get the program name from the command line arguments. :param argv: Sequence of command-line arguments. Defaults to `sys.argv`. :return: The program name used to invoke this program. Nr)rargvosrbasename)rTprognamerrr get_prognamesrXcCstd}|jS)z/ Get the version string for this distribution. dput) pkg_resourcesget_distributionversion) distributionrrr get_distribution_versions r^csl|dd}g}|r2|ddr2|ddkr$|dd} ||fS|ddkr/ ||fS|ddr|ddddvrLdd\}nd}fdd|D}t|dkrctd t|dkrotd |dd rdd |pd }n'drdd|s|std|d}n |durtdd }|d|fnt|ddd}|r(||d}|dkrtd|d|dt|ks||ddkr|d|dd f|dd}n1t|dkr|d|d|ddfd }n|r |d||dfd }ntd||s|r2|dds||fS)Nrr'z--r r;=csg|] }|r|qSr) startswith).0xoptrr szgetopt..zunknown option --%sznon-unique prefix --%sz==r#zoption --%s requires argumentz#option --%s does not take argumentszoption -%s unknown:zoption -%s requires argument)r`popsplitr>rendswithappendfind)r shortoptslongoptsoptlistoptarg prefixmatchrCposrrcr getoptsr   0 .            3rtr5)rGrNrKrUrrtimerZ Exceptionrr rEXIT_STATUS_FAILURErrr"rSrXr^rtrrrr s&E #