D[c@sdZddlmZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z de fdYZdefd YZd efd YZd Zed krendS(s;Classes for working with locally available Debian packages.i(tprint_functionN(tgettext(tStringIOtNoDebArchiveExceptioncBseZdZRS(s9Exception which is raised if a file is no Debian archive.(t__name__t __module__t__doc__(((s//usr/lib/python2.7/dist-packages/apt/debfile.pyR!st DebPackagecBseZdZed\ZZZZdZd"d"dZ dZ dZ dZ edZedZed Zd Zd Zd Zd ZedZedZedZedZdZdZdZedZdZ dZ!dZ"edZ#edZ$e%dZ&e%dZ'eedZ(dZ)dZ*d Z+d"d!Z,RS(#sA Debian Package (.deb file).iicCs}|dkrtj}n||_d|_d|_i|_g|_t|_ d|_ d|_ |ry|j |ndS(Nt( tNonetapttCachet_cachet_debfiletpkgnamet _sectionst _need_pkgstFalset_check_was_runt_failure_stringt _multiarchtopen(tselftfilenametcache((s//usr/lib/python2.7/dist-packages/apt/debfile.pyt__init__1s         cCs|jdd|g|_t|_d|_||_tj|j|_|jj j d}t j ||_ |j d|_t|_dS(s open given debfile is open '%s'RtcontroltPackageN(t_dbgRtsett_installed_conflictsRRtapt_insttDebFileR Rt extractdatatapt_pkgt TagSectionRRRR(RRR((s//usr/lib/python2.7/dist-packages/apt/debfile.pyR?s    cCs |j|S(N(R(Rtkey((s//usr/lib/python2.7/dist-packages/apt/debfile.pyt __getitem__LscCs ||jkS(N(R(RR$((s//usr/lib/python2.7/dist-packages/apt/debfile.pyt __contains__OscsOgy |jjjfdWn"tk rJtd|jgSXS(s$return the list of files in the deb.csj|jS(N(tappendtname(titemtdata(tfiles(s//usr/lib/python2.7/dist-packages/apt/debfile.pytWss(List of files for '%s' could not be read(R R*tgot SystemErrort_R(R((R+s//usr/lib/python2.7/dist-packages/apt/debfile.pytfilelistRs    csUgy |jjjfdWn"tk rJtd|jgSXtS(s, return the list of files in control.tar.gt csj|jS(N(R'R((R)R*(R(s//usr/lib/python2.7/dist-packages/apt/debfile.pyR,css0List of control files for '%s' could not be read(R RR-R.R/Rtsorted(R((Rs//usr/lib/python2.7/dist-packages/apt/debfile.pytcontrol_filelist]s    cCsd|kr|S|js|S|jj|r3|S||jkro|j|jro|j|jjdkro|Sd||jf}||jkr|S|j|jj}|j|j@r|S|r|j|j@ r|S|S(Nt:talls%s:%s( RR tis_virtual_packaget candidatet architecturet_candt multi_archtMULTI_ARCH_FOREIGNtMULTI_ARCH_SAME(RRtin_conflict_checkingtmultiarch_pkgnametcand((s//usr/lib/python2.7/dist-packages/apt/debfile.pyt_maybe_append_multiarch_suffixjs(  c CsL|jdd|x1|D])}|d}|d}|d}|j|}||jkr|jj|r|jdd|x*|jj|D]}|jrtSqWqqn|j|j}|d k rt j |j ||rtS|sxM|jj|dtD]0}|jr |jdd|j |ftSq WqqWt S( sReturn True if at least one dependency of the or-group is satisfied. This method gets an 'or_group' and analyzes if at least one dependency of this group is already satisfied. is_checkOrGroup(): %s iiis+_is_or_group_satisfied(): %s is virtual deptinclude_nonvirtuals'found installed '%s' that provides '%s'N(RR?R R5tget_providing_packagest is_installedtTruet installedR R"t check_deptversionR(R( Rtor_grouptdeptdepnametvertopertpkgtinsttppkg((s//usr/lib/python2.7/dist-packages/apt/debfile.pyt_is_or_group_satisfieds6      $  c Csx|D]}|\}}}|j|}||jkr|jj|sRqn|jj|}t|dkr|qn|dj}n|j|}|jjj|j}|sqnt j |j ||sqn|j dd||j j|tSWd} xn|D]f}| |d7} |rP|rP| d|d|df7} n||t|dkr| d7} qqW|jtd| 7_tS( sTry to satisfy the or_group.iiisNeed to get: %sRs (%s %s)t|s"Dependency is not satisfiable: %s (R?R R5RAtlenR(t _depcachetget_candidate_vert_pkgR"REtver_strRRR'RCRR/R( RRGRHRIRJRKt providersRLR>tor_str((s//usr/lib/python2.7/dist-packages/apt/debfile.pyt_satisfy_or_groups:     cCs|jdd|||f|j|}|jrB|jj}n|jrZ|jj}ntStj |||r|j ||| r|j t d|j 7_ |jdd|j tStS(s@Return True if a pkg conflicts with a real installed/marked pkg.is8_check_single_pkg_conflict() pkg='%s' ver='%s' oper='%s's)Conflicts with the installed package '%s's!conflicts with installed pkg '%s'(RR RBRDRFtmarked_installR6RR"REtreplaces_real_pkgRR/R(RC(RRRJRKRLtpkgver((s//usr/lib/python2.7/dist-packages/apt/debfile.pyt_check_single_pkg_conflicts     cCsA|jdd|x|D]}|d}|d}|d}|j|dt}||jkr|jj|rx|jj|D]s}|jdd|j|j|jkr|jddqn|j|j||r|j j |jqqWqqn|j|||r|j j |qqWt |j S( s5Check the or-group for conflicts with installed pkgs.is _check_conflicts_or_group(): %s iiR<isconflicts virtual check: %ssconflict on self, ignoring( RR?RCR R5RAR(RR\Rtaddtbool(RRGRHRIRJRKRL((s//usr/lib/python2.7/dist-packages/apt/debfile.pyt_check_conflicts_or_groups*    cCs:d}ytj|j|tSWntk r5gSXdS(s4List of package names conflicting with this package.t ConflictsN(R"t parse_dependsRRtKeyError(RR$((s//usr/lib/python2.7/dist-packages/apt/debfile.pyt conflictss  cCsSg}xFdD]>}y$|jtj|j|tWq tk rJq Xq W|S(s7List of package names on which this package depends on.tDependss Pre-Depends(Rds Pre-Depends(textendR"RaRRRb(RtdependsR$((s//usr/lib/python2.7/dist-packages/apt/debfile.pyRf(s  cCs:d}ytj|j|tSWntk r5gSXdS(s<List of virtual packages which are provided by this package.tProvidesN(R"RaRRRb(RR$((s//usr/lib/python2.7/dist-packages/apt/debfile.pytprovides5s  cCs:d}ytj|j|tSWntk r5gSXdS(s4List of packages which are replaced by this package.tReplacesN(R"RaRRRb(RR$((s//usr/lib/python2.7/dist-packages/apt/debfile.pytreplaces>s  cCs|jdd|||f|j|}|jrB|jj}n|jrZ|jj}nd}xd|jD]Y}xP|D]H\}}}||krwt j |||rw|jdd|t SqwWqjWt S(sReturn True if a given non-virtual package is replaced. Return True if the deb packages replaces a real (not virtual) packages named (pkgname, oper, ver). isreplaces_real_pkg() %s %s %ss?we have a replaces in our package for the conflict against '%s'N( RR RBRDRFRYR6R RjR"RERCR(RRRKRJRLR[RGR(((s//usr/lib/python2.7/dist-packages/apt/debfile.pyRZGs   !  cCs6t}x)|jD]}|j|rt}qqW|S(sCheck if there are conflicts with existing or selected packages. Check if the package conflicts with a existing or to be installed package. Return True if the pkg is OK. (RCRcR_R(RtresRG((s//usr/lib/python2.7/dist-packages/apt/debfile.pytcheck_conflicts]s  c Cs;tt|j}tt|dd}|jd}|jd}g|jD]}|dd^qR}xt|jD]\}}||dkr|jjj t||dn|j sq|n|j j } x|j jD]} x| jD]} | j|jkrtj|| j| js|jdd|j|jtd i|jd 6| jd 6| jd 6| jd 67_|jjjtSqqWqWd| jkr|xs| jdD]a} xX| D]P} | jj|jkr| jj|krtj|| j| jr|jdd|j|jtdi|jd 6| jjd6| jd6| jd67_|jjjtSn| jj|kr|j|jkr|jdd||jtdidj |d6|j!d6| jjd6|jd 67_|jjjtSqWqWq|q|W|jjjt"S(s check if installing the package would break exsisting package on the system, e.g. system has: smc depends on smc-data (= 1.4) and user tries to installs smc-data 1.6 i2itVersiont ArchitectureigY@iswould break (depends) %ss]Breaks existing package '%(pkgname)s' dependency %(depname)s (%(deprelation)s %(depversion)s)RRIt deprelationt depversionR`swould break (conflicts) %ssZBreaks existing package '%(pkgname)s' conflict: %(targetpkg)s (%(comptype)s %(targetver)s)t targetpkgtcomptypet targetvers{Breaks existing package '%(pkgname)s' that conflict: '%(targetpkg)s'. But the '%(debfile)s' provides it via: '%(provides)s't,Rhtdebfile(#tfloatRQR tmaxtintRRht enumeratet op_progresstupdateRBRTt current_verRDt dependenciestor_dependenciesR(RR"REtrelationRFRRR/tdoneRt depends_listt target_pkgR7t comp_typet target_vertjoinRRC(RtsizetstepstdebvertdebarchtxRhtiRLRJtdep_orRHtconflicts_ver_listtc_or((s//usr/lib/python2.7/dist-packages/apt/debfile.pytcheck_breaks_existing_packagesksv  $$              cCs%|jdd|jd}|jd}|jdd|||jkr|ry|j|jry|j|jj}n4| r|j|jr|j|jj}n|jS|d k rtj ||}|jdd||dkr|j S|dkr|j S|dkr|j Sqn|jS( s Compare the package to the version available in the cache. Checks if the package is already installed or availabe in the cache and if so in what version, returns one of (VERSION_NONE, VERSION_OUTDATED, VERSION_SAME, VERSION_NEWER). itcompare_to_version_in_cacheRRmis debver: %ss"CompareVersion(debver,instver): %siN( RRR RDRFR6t VERSION_NONER R"tversion_comparet VERSION_SAMEt VERSION_NEWERtVERSION_OUTDATED(Rt use_installedRRtcachevertcmp((s//usr/lib/python2.7/dist-packages/apt/debfile.pyRs(       cCs|jddt|_d|jkrK|jddtd|_tS|jd}|dkr|tjj dkr|tj kr||_ d |j |j f|_ |jdd |q|jdd td ||_tSn|j |jkr/|j|j jr/td |_tSnd|_|jsHtS|jsXtS|j|jsntS|js~tS|jjjdkrtd|_|jjtStS(s$Check if the package is installable.itcheckRnisERROR: no architecture fields$No Architecture field in the packageR4sAPT::Architectures%s:%ssFound multiarch arch: '%s'sERROR: Wrong architecture dude!sWrong architecture '%s's$A later version is already installedRis1Failed to satisfy all dependencies (broken cache)(RRCRRR/RRR"tconfigtfindtget_architecturesRRRRR RDRlRt_satisfy_dependsRfRRt broken_counttclear(Rtarch((s//usr/lib/python2.7/dist-packages/apt/debfile.pyRsD  $       cCs|jtj|tS(s-Satisfy the dependencies in the given string.(RR"RaR(Rt dependsstr((s//usr/lib/python2.7/dist-packages/apt/debfile.pytsatisfy_depends_strscCsytj|jj}|Wntk r0nXx3|D]+}|j|s8|j|sctSq8q8Wxa|jD]V}y|j|j dtWqqt k rt d||_ |jj tSXqqWtS(sSatisfy the dependencies.t from_usersCannot install '%s'(R"t ActionGroupR RRtAttributeErrorRORXRRt mark_installR.R/RRRC(RRft _actiongroupRGRL((s//usr/lib/python2.7/dist-packages/apt/debfile.pyRs"      cCs6|jdd|j|js/tdn|jS(sReturn missing dependencies.isInstalling: %ss-property only available after check() was run(RRRR(R((s//usr/lib/python2.7/dist-packages/apt/debfile.pyt missing_deps5s   cCsg}g}g}|js*tdnx|jD]}|jsL|jr|j|jt}x!|jj D]}||j O}qoW|s|j|jqn|j r4|j|jq4q4W|||fS(sGet the changes required to satisfy the dependencies. Returns: a tuple with (install, remove, unauthenticated) s-property only available after check() was run( RRR RYtmarked_upgradeR'R(RR6toriginsttrustedt marked_delete(RtinstalltremovetunauthenticatedRLt authenticatedtorigin((s//usr/lib/python2.7/dist-packages/apt/debfile.pytrequired_changes>s"   cCsXd}xKt|D]=\}}|ddkr<|d7}n|dt|7}qW|S(NRiPis s%2.2x (Rytord(tin_datathexRtc((s//usr/lib/python2.7/dist-packages/apt/debfile.pytto_hexXs  cCsd}t|tkrgx|D]A}t|dksIt|dkrV|d7}q||7}qWnFxC|D];}|dks|dkr|d7}qn|t|7}qnW|S(NRi it (ttypetstrRtchr(RtsRtb((s//usr/lib/python2.7/dist-packages/apt/debfile.pyt to_strishas $   c Cs|jdr|d}n|j|}|jdr}|r}t|}tjd|}td}||j7}ny|jd}Wn1t k rtd}||j |7}|SX|S(Ns./is.gztfileobjsAutomatically decompressed: sutf-8s,Automatically converted to printable ascii: ( t startswithR!tendswithRtgziptGzipFileR/treadtdecodet ExceptionR( RtpartR(tauto_decompresstauto_hexR*tiotgztnew_data((s//usr/lib/python2.7/dist-packages/apt/debfile.pyt _get_contentts     cCs3y|j|jj|SWntk r.dSXdS(s6 return the content of a specific control.tar.gz file RN(RR Rt LookupError(RR(((s//usr/lib/python2.7/dist-packages/apt/debfile.pytcontrol_contents cCs3y|j|jj|SWntk r.dSXdS(s6 return the content of a specific control.tar.gz file RN(RR R*R(RR(((s//usr/lib/python2.7/dist-packages/apt/debfile.pyt data_contents cCs)||jkr%t|dtjndS(s%Write debugging output to sys.stderr.tfileN(tdebugtprinttsyststderr(Rtleveltmsg((s//usr/lib/python2.7/dist-packages/apt/debfile.pyRscCs|dkr+tjtjddd|jSy|jWntk rV|jnX|j|j}y|j Wntk r|j nX|SdS(sInstall the package.tdpkgs-iN( R tostspawnlptP_WAITRt start_updateRt startUpdatetrunt finish_updatet finishUpdate(Rtinstall_progressRk((s//usr/lib/python2.7/dist-packages/apt/debfile.pyRs   N(-RRRtrangeRRRRRR RRR%R&tpropertyR0R2RR?RORXR\R_RcRfRhRjRZRlRRCRRRRRRt staticmethodRRRRRRR(((s//usr/lib/python2.7/dist-packages/apt/debfile.pyR%sD     . -        W  ;       t DscSrcPackagecBsMeZdZdddZedZedZdZdZ RS(s#A locally available source package.cCsrtj|d|||_g|_g|_t|_d|_g|_ |jdk rn|j |jndS(NR( RRR Rt_dependst _conflictsRRRtbinariesR(RRR((s//usr/lib/python2.7/dist-packages/apt/debfile.pyRs      cCs|jS(s&Return the dependencies of the package(R(R((s//usr/lib/python2.7/dist-packages/apt/debfile.pyRfscCs|jS(s&Return the dependencies of the package(R(R((s//usr/lib/python2.7/dist-packages/apt/debfile.pyRcsc Csyddg}ddg}t|}tj|}zx|D]}x=|D]5}||krbqJn|jjtj||qJWx=|D]5}||krqn|jjtj||qWd|kr|d|_nd|kr|djd|_ nd|kr=|d|j d= 2.3.2), libaio (>= 0.3.96) | libaio1 (>= 0.3.96)N(t apt.cacheR tapt.progress.baseRRR5RAR(RRtargvRRRRRR0RRRR"RaR( R RRtvpRVRLtdtretR((s//usr/lib/python2.7/dist-packages/apt/debfile.pyt_tests.        t__main__(Rt __future__RR RR"RRRRR/RRtIOErrorRtobjectRRRR(((s//usr/lib/python2.7/dist-packages/apt/debfile.pyts"      F %