o 4f @sdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z ddlmZddlmZmZmZmZmZmZmZmZmZmZmZddlZddlZddlm Z m!Z!dd lm"Z#d Z$d d Z%Gd dde&Z'Gddde'Z(Gddde)Z*Gdddee*Z+Gddde)Z,GdddeeefZ-Gddde)Z.Gdddee.Z/Gddde)Z0edd Z1e2d!kre1dSdS)"z"Functionality related to packages.)print_functionN) BadStatusLine) HTTPError)urlopen) AnyIterableIteratorListOptionalSetTupleUnion no_type_checkMappingSequence)AcquireProgressInstallProgress)gettext)BaseDependency DependencyOriginPackageRecordVersion VersionListcCsXtj|r*tj||kr*t|}t|j|kWdS1s%wYdS)z(Return ``True`` if the file is the same.NF)ospathexistsgetsizeopenapt_pkgHasheshashes)rsizer"fobjr%-/usr/lib/python3/dist-packages/apt/package.py _file_is_same6s   r'c@eZdZdZdS) FetchErrorz(Raised when a file could not be fetched.N__name__ __module__ __qualname____doc__r%r%r%r&r)?r)c@r()UntrustedErrorz/Raised when a file did not have a trusted hash.Nr*r%r%r%r&r0Cr/r0c@seZdZdZGdddeZddZddZdd Ze d d Z e d d Z e ddZ e ddZ e ddZe ddZe ddZe ddZe ddZdS)rzA single dependency.c@ eZdZdZddZddZdS)zBaseDependency.__dstraQCompare helper for compatibility with old third-party code. Old third-party code might still compare the relation with the previously used relations (<<,<=,==,!=,>=,>>,) instead of the curently used ones (<,<=,=,!=,>=,>,). This compare helper lets < match to <<, > match to >> and = match to ==. cCs\t||rdSt|drtd|St|dr td|St|dr,td|SdS) NTz>>=z==F)str__eq__selfotherr%r%r&r6Ss       zBaseDependency.__dstr.__eq__cCs || SN)r6r7r%r%r&__ne__` zBaseDependency.__dstr.__ne__N)r+r,r-r.r6r;r%r%r%r&__dstrJs r=cCs||_||_dSr:)_version_dep)r8versiondepr%r%r&__init__ds zBaseDependency.__init__cCd|j|jfSNz%s: %srawtyperawstrr8r%r%r&__str__izBaseDependency.__str__cCsd|j|j|j|jfS)Nz;)namerelationr@rFrHr%r%r&__repr__mszBaseDependency.__repr__cCs |jjjS)zThe name of the target package.)r? target_pkgrKrHr%r%r&rKr zBaseDependency.namecCs||jjS)zThe relation (<, <=, =, !=, >=, >, '') in mathematical notation. The empty string will be returned in case of an unversioned dependency. )_BaseDependency__dstrr? comp_typerHr%r%r&rLxszBaseDependency.relationcC|jjS)avThe relation (<<, <=, =, !=, >=, >>, '') in Debian notation. The empty string will be returned in case of an unversioned dependency. For more details see the Debian Policy Manual on the syntax of relationship fields: https://www.debian.org/doc/debian-policy/ch-relationships.html#s-depsyntax # noqa .. versionadded:: 1.0.0 )r? comp_type_debrHr%r%r& relation_debs zBaseDependency.relation_debcCrR)zThe target version or an empty string. Note that the version is only an empty string in case of an unversioned dependency. In this case the relation is also an empty string. )r? target_verrHr%r%r&r@szBaseDependency.versioncCsJg}|j}|D]}|j}|jjj}||}t||}||q |S)zfA list of all Version objects which satisfy this dependency. .. versionadded:: 1.0.0 ) r? all_targets parent_pkgr>package_pcache_rawpkg_to_pkgrappend)r8tvers_tvers_tver_pkgcachepkgtverr%r%r&target_versionss     zBaseDependency.target_versionscCdd|jDS)iA list of all installed Version objects which satisfy this dep. .. versionadded:: 1.0.0 cSg|]}|jr|qSr% is_installed.0rbr%r%r& z.rcrHr%r%r&installed_target_versionsz(BaseDependency.installed_target_versionscCs |jr d|j|j|jfS|jS)aString represenation of the dependency. Returns the string representation of the dependency as it would be written in the debian/control file. The string representation does not include the type of the dependency. Example for an unversioned dependency: python3 Example for a versioned dependency: python3 >= 3.2 .. versionadded:: 1.0.0 z%s %s %s)r@rKrTrHr%r%r&rGszBaseDependency.rawstrcCrR)zType of the dependency. This should be one of 'Breaks', 'Conflicts', 'Depends', 'Enhances', 'PreDepends', 'Recommends', 'Replaces', 'Suggests'. Additional types might be added in the future. r?dep_type_untranslatedrHr%r%r&rFs zBaseDependency.rawtypecCs |jjdkS)zWhether this is a PreDepends. PreDependsrprHr%r%r& pre_depend zBaseDependency.pre_dependN)r+r,r-r.r5rPrBrIrMpropertyrKrLrTr@rcrnrGrFrsr%r%r%r&rGs0         rcsleZdZdZfddZddZddZedd Zed d Z ed d Z eddZ eddZ Z S)raMRepresent an Or-group of dependencies. Attributes defined here: or_dependencies - The possible choices rawstr - String represenation of the Or-group of dependencies rawtype - The type of the dependencies in the Or-group target_version - A list of Versions which satisfy this Or-group of deps cs tt||||_||_dSr:)superrrBr>_rawtype)r8r@ base_depsrF __class__r%r&rBs zDependency.__init__cCrCrDrErHr%r%r&rIrJzDependency.__str__cCdddd|DS)Nz, cs|]}t|VqdSr:)reprrjbdr%r%r& z&Dependency.__repr__..joinrHr%r%r&rMzDependency.__repr__cCs|Sr:r%rHr%r%r&or_dependenciesszDependency.or_dependenciescCsddd|DS)axString represenation of the Or-group of dependencies. Returns the string representation of the Or-group of dependencies as it would be written in the debian/control file. The string representation does not include the type of the Or-group of dependencies. Example: python2 >= 2.7 | python3 .. versionadded:: 1.0.0 z | css|]}|jVqdSr:)rGrr%r%r&rsz$Dependency.rawstr..rrHr%r%r&rGszDependency.rawstrcC|jS)aType of the Or-group of dependency. This should be one of 'Breaks', 'Conflicts', 'Depends', 'Enhances', 'PreDepends', 'Recommends', 'Replaces', 'Suggests'. Additional types might be added in the future. .. versionadded:: 1.0.0 )rwrHr%r%r&rF s zDependency.rawtypecCs0g}|D]}|jD] }||vr||q q|S)zlA list of all Version objects which satisfy this Or-group of deps. .. versionadded:: 1.0.0 )rcr[)r8r\rrbr%r%r&rcs  zDependency.target_versionscCrd)recSrfr%rgrir%r%r&rk,rlz8Dependency.installed_target_versions..rmrHr%r%r&rn%roz$Dependency.installed_target_versions)r+r,r-r.rBrIrMrurrGrFrcrn __classcell__r%r%ryr&rs      rc@r1)raThe origin of a version. Attributes defined here: archive - The archive (eg. unstable) component - The component (eg. main) label - The Label, as set in the Release file origin - The Origin, as set in the Release file codename - The Codename, as set in the Release file site - The hostname of the site. trusted - Boolean value whether this is trustworthy. cCsd|j|_|j|_|j|_|j|_|j|_|j|_|j|_|jj |}|r-|j r-d|_ dSd|_ dSNTF) archive componentlabelorigincodenamesite not_automaticrY_list find_index is_trustedtrusted)r8ra packagefile indexfiler%r%r&rB<s   zOrigin.__init__cCs d|j|j|j|j|j|jfS)NzH)rrrrrrrHr%r%r&rMLs zOrigin.__repr__N)r+r,r-r.rBrMr%r%r%r&r/s rc@sbeZdZdZddZddZddZdd Zd d Zd d Z ddZ dddZ ddZ ddZ dS)ra"Record in a Packages file Represent a record as stored in a Packages file. You can use this like a dictionary mapping the field names of the record to their values:: >>> record = Record("Package: python-apt\nVersion: 0.8.0\n\n") >>> record["Package"] 'python-apt' >>> record["Version"] '0.8.0' For example, to get the tasks of a package from a cache, you could do:: package.candidate.record["Tasks"].split() Of course, you can also use the :attr:`Version.tasks` property. cCst||_dSr:)r TagSection_rec)r8 record_strr%r%r&rBhrJzRecord.__init__cC t|jSr:)hashrrHr%r%r&__hash__l zRecord.__hash__cCrr:)r5rrHr%r%r&rIprzRecord.__str__cCs |j|Sr:rr8keyr%r%r& __getitem__trzRecord.__getitem__cC ||jvSr:rrr%r%r& __contains__xrzRecord.__contains__cCst|jSr:)iterrkeysrHr%r%r&__iter__|zRecord.__iter__ccs&|jD] }||j|fVqdS)z6An iterator over the (key, value) items of the record.N)rrrr%r%r& iteritemsszRecord.iteritemsNcCs|j||S)zReturn record[key] if key in record, else *default*. The parameter *default* must be either a string or None. )rgetr8rdefaultr%r%r&rsz Record.getcCr)z deprecated form of ``key in x``.rrr%r%r&has_keys zRecord.has_keycCrr:)lenrrHr%r%r&__len__rzRecord.__len__r:)r+r,r-r.rBrrIrrrrrrrr%r%r%r&rTs  rc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZeddZeddZeddZeddZed d!Zed"d#Zed$d%Zed&d'Zed(d)Zed*d+Zed,d-Zed.d/Zed0d1Zed2d3Zed4d5Zed6d7Zed8d9Z ed:d;Z!dd?Z#ed@dAZ$edBdCZ%edDdEZ&edFdGZ'edHdIZ(edJdKZ)edLdMZ*edNdOZ+edPdQZ,edRdSZ-dTdUZ.edVdWZ/edXdYZ0 [ [dad\d]Z1 ^ [dbd_d`Z2d[S)crzRepresentation of a package version. The Version class contains all information related to a specific package version. .. versionadded:: 0.7.9 cCs ||_||_|jjj|dSr:)rX_candrY _weakversionsadd)r8rXcandr%r%r&rBszVersion.__init__c Csz |jj}|jj}||krWdS||krWdSt|jj|jWSty@z t|jj|WYSty?t YYSww)a:Compares against another apt.Version object or a version string. This method behaves like Python 2's cmp builtin and returns an integer according to the outcome. The return value is negative in case of self < other, zero if self == other and positive if self > other. The comparison includes the package name and architecture if other is an apt.Version object. If other isn't an apt.Version object it'll be assumed that other is a version string (without package name/arch). .. versionchanged:: 1.0.0 ) rXfullnamer version_comparerver_strr@AttributeError TypeErrorNotImplemented)r8r9 self_name other_namer%r%r&_cmps   z Version._cmpcCs||dkSNrrr7r%r%r&r6rzVersion.__eq__cCs||dkSrrr7r%r%r&__ge__rzVersion.__ge__cCs||dkSrrr7r%r%r&__gt__rzVersion.__gt__cCs||dkSrrr7r%r%r&__le__rzVersion.__le__cCs||dkSrrr7r%r%r&__lt__rzVersion.__lt__cCs(z||dkWStytYSwr)rrrr7r%r%r&r;s  zVersion.__ne__cCrRr:)rrrHr%r%r&rszVersion.__hash__cCd|jj|jfS)Nz%s=%srXrKr@rHr%r%r&rIszVersion.__str__cCr)Nz rrHr%r%r&rMszVersion.__repr__cCs*|jjj|jjdstd|jjjS)z=Internal helper that moves the Records to the right position.rzCould not lookup record)rXrY_recordslookupr file_list LookupErrorrHr%r%r&rs zVersion._recordscCs.|jj}|jjj|jdr|jjjSdS)z2Internal helper to get the translated description.rN)rtranslated_descriptionrXrYrrrpop)r8 desc_iterr%r%r&_translated_recordss zVersion._translated_recordscCrR)z.Return the size of the package when installed.)rinstalled_sizerHr%r%r&rzVersion.installed_sizecCrR)z$Return the homepage for the package.)rhomepagerHr%r%r&rrzVersion.homepagecCrR)zReturn the size of the package.)rr#rHr%r%r&r# rz Version.sizecCrR)z/Return the architecture of the package version.)rarchrHr%r%r& architecturerzVersion.architecturecC t|jjS)z:Return whether the version of the package is downloadable.)boolr downloadablerHr%r%r&rrtzVersion.downloadablecCs |jj}|duo|jj|jjkS)zkReturn wether this version of the package is currently installed. .. versionadded:: 1.0.0 N)rX installedrid)r8inst_verr%r%r&rhszVersion.is_installedcCrR)zReturn the version as a string.)rrrHr%r%r&r@(rzVersion.versioncCs|j}|dur |jSdS)z0Return the short description (one line summary).N)r short_desc)r8recordsr%r%r&summary.szVersion.summarycCrR)z"return the long description (raw).)r long_descrHr%r%r&raw_description5rzVersion.raw_descriptioncCrR)z"Return the section of the package.)rsectionrHr%r%r&r;rzVersion.sectionc Cs:d}|j}|dur |jnd}|std|jjSz t|ts#|d}Wnty@}ztd|jj|fWYd}~Sd}~wwt | d}t ||D]L}| dkr`| ds_|d7}qN|d r|| dssd |d d}n#d |d d}n|d r| ds|dkr|dd}n|}n|}||7}qN|S)zReturn the formatted long description. Return the formatted long description according to the Debian policy (Chapter 5.6.13). See http://www.debian.org/doc/debian-policy/ch-controlfields.html for more information. Nz+Missing description for '%s'.Please report.utf-8z.)r provides_listrHr%r%r&providesszVersion.providescC |dS)z4Return the list of enhances for the package version.Enhancesr rHr%r%r&enhancesrOzVersion.enhancescCs |ddS)z/Return the dependencies of the package version.rrDependsrrHr%r%r& dependenciesrtzVersion.dependenciescCr)z-Return the recommends of the package version. RecommendsrrHr%r%r& recommendsrOzVersion.recommendscCr)z+Return the suggests of the package version.SuggestsrrHr%r%r&suggestsrOzVersion.suggestscCs,g}|jjD] \}}|t|j|q|S)z1Return a list of origins for the package version.)rrr[rrX)r8originsr_unusedr%r%r&rszVersion.originscCrR)zZReturn the path to the file inside the archive. .. versionadded:: 0.7.10 )rfilenamerHr%r%r&rzVersion.filenamecCrR)zKReturn the md5sum of the binary. .. versionadded:: 0.7.10 )rmd5_hashrHr%r%r&md5rz Version.md5cCrR)zLReturn the sha1sum of the binary. .. versionadded:: 0.7.10 )r sha1_hashrHr%r%r&sha1rz Version.sha1cCrR)zNReturn the sha256sum of the binary. .. versionadded:: 0.7.10 )r sha256_hashrHr%r%r&sha256rzVersion.sha256cCst|jdS)zGet the tasks of the package. A set of the names of the tasks this package belongs to. .. versionadded:: 0.8.0 Task)setrrrHr%r%r&taskss z Version.tasksccs<|jjD]\}}|jjj|}|r||jjVqdS)zVReturn an iterator over all available urls. .. versionadded:: 0.7.10 N) rrrXrYrr archive_urirr)r8rrrr%r%r&_urissz Version._uriscCs t|S)z^Return a list of all available uris for the binary. .. versionadded:: 0.7.10 )listr'rHr%r%r&uriss z Version.uriscCs(z tt|WStyYdSw)zNReturn a single URI for the binary. .. versionadded:: 0.7.10 N)rrr' StopIterationrHr%r%r&uri"s  z Version.urirNc Cs>|dur tjdd}tj|jj}tj||}t ||j |jj r0t d|tj|S|jjd\}}|jjj|}|sW|rG|jsWtd|jj|jt|ddf|js^td |jj } |sm| jsmtd |t|pvtjj !} tj"| |j| |j ||d } | #| j$| j%krt&d | j'| j(ftj|S) aCFetch the binary version of the package. The parameter *destdir* specifies the directory where the package will be fetched to. The parameter *progress* may refer to an apt_pkg.AcquireProgress() object. If not specified or None, apt.progress.text.AcquireProgress() is used. The keyword-only parameter *allow_unauthenticated* specifies whether to allow unauthenticated downloads. If not specified, it defaults to the configuration option `APT::Get::AllowUnauthenticated`. .. versionadded:: 0.7.10 NAPT::Get::AllowUnauthenticatedF"Ignoring already existing file: %sr>Could not fetch %s %s source package: Source %r is not trusteddescribezzNo URI for this binary.8The item %r could not be fetched: No trusted hash found.destfile$The item %r could not be fetched: %s))r configfind_brrbasenamerrrr'r#r"loggingdebugabspathrrrXrYrrrr0rKr@getattrr+ ValueErrorusableAcquireaptprogresstextr AcquireFilerunstatus STAT_DONEr)r2 error_text) r8destdirr?allow_unauthenticatedbaser2pfileoffsetindexr"acqacqfiler%r%r& fetch_binary.sD        zVersion.fetch_binaryTc Cs|dur tjdd}t}t|ptjj}d}|j }|j p%|j j } |j p,|jj} || } | rE| |jkrE|| } | rE| |jks9| sMtd|t} |sd|jjsdtd|j j|j|jjf|jD]H} tj| j}tj||}| jdkr~|}t|| j | j!rt"#d|qg|s| j!j$std|| %tj&||j'| j| j!| j ||d qg|(|durtd||j)D]}|j*|j+krt,d |j-|j.fq|r|j d t/|j}tj||}t01d d ||gtj2|Stj2|S)a9Get the source code of a package. The parameter *destdir* specifies the directory where the source will be fetched to. The parameter *progress* may refer to an apt_pkg.AcquireProgress() object. If not specified or None, apt.progress.text.AcquireProgress() is used. The parameter *unpack* describes whether the source should be unpacked (``True``) or not (``False``). By default, it is unpacked. If *unpack* is ``True``, the path to the extracted directory is returned. Otherwise, the path to the .dsc file is returned. The keyword-only parameter *allow_unauthenticated* specifies whether to allow unauthenticated downloads. If not specified, it defaults to the configuration option `APT::Get::AllowUnauthenticated`. Nr,FzNo source for %rr.rr-r0r1r3-z dpkg-sourcez-x)3r r4r5 SourceRecordsr=r>r?r@rrrrXrrrrrr@r;r(rKrr0rKr/filesrrr6rtyper'r#r"r7r8r<r[rAr&rBitemsrCrDr)r2rEupstream_version subprocess check_callr9)r8rFr?unpackrGsrcrLrrrr source_lookuprQfilrHr2itemoutdirr%r%r& fetch_sourcedsl                  zVersion.fetch_source)rNN)rNTN)3r+r,r-r.rBrr6rrrrr;rrIrMrurrrrr#rrrhr@rrrrrrrrrr rrrrrrrrr r"r%r'r)r+rNr]r%r%r%r&rs             5                      6rc@sdeZdZdZdddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dddZ dS)raProvide a mapping & sequence interface to all versions of a package. This class can be used like a dictionary, where version strings are the keys. It can also be used as a sequence, where integers are the keys. You can also convert this to a dictionary or a list, using the usual way of dict(version_list) or list(version_list). This is useful if you need to access the version objects multiple times, because they do not have to be recreated this way. Examples ('package.versions' being a version list): '0.7.92' in package.versions # Check whether 0.7.92 is a valid version. package.versions[0] # Return first version or raise IndexError package.versions[0:2] # Return a new VersionList for objects 0-2 package.versions['0.7.92'] # Return version 0.7.92 or raise KeyError package.versions.keys() # All keys, as strings. max(package.versions) NcCs(||_|jj|_|r|j||_dSdSr:)_packager_ version_list _versions)r8rXslice_r%r%r&rBs  zVersionList.__init__cCsvt|tr ||j|Sz t|j|j|WSty4|jD]}|j|kr1t|j|YSq Ynwtd|)NzVersion: %r not found.) rslicerzr^rr`rrrr8r[verr%r%r&rs     zVersionList.__getitem__cCr{)Nz[%s]r|csr}r:)r5rjrdr%r%r&rrz&VersionList.__str__..rrHr%r%r&rIrzVersionList.__str__cCs d|S)Nz)rrHr%r%r&rMr<zVersionList.__repr__csfddjDS)z*Return an iterator over all value objects.c3s|] }tj|VqdSr:)rr^rerHr%r&rsz'VersionList.__iter__..r`rHr%rHr&rszVersionList.__iter__cCs0t|tr|j}|jD] }|j|krdSq dSr)rrr@r`rrcr%r%r&rs   zVersionList.__contains__cCst|t|kSr:)r(r7r%r%r&r6rJzVersionList.__eq__cCrr:)rr`rHr%r%r&rrzVersionList.__len__cCrd)z*Return a list of all versions, as strings.cSsg|]}|jqSr%)rrer%r%r&rksz$VersionList.keys..rfrHr%r%r&rszVersionList.keyscCs"z||WSty|YSw)zReturn the key or the default.)rrr%r%r&rs   zVersionList.getr:)r+r,r-r.rBrrIrMrrr6rrrr%r%r%r&rs  rc@seZdZdZddZddZddZdd Zed d Z e j d d Z ed dZ eddZ eddZ eddZeddZeddZddZeddZeddZedd Zed!d"Zed#d$Zed%d&Zed'd(Zed)d*Zed+d,Zed-d.Zed/d0ZdJd2d3Zed4d5Zed6d7Zed8d9Z ed:d;Z!d)r_rKrrrHr%r%r&rM"szPackage.__repr__cCs |j|jkSr:rjr7r%r%r&r'r<zPackage.__lt__cCs&|jj|j}|durt||SdS)zReturn the candidate version of the package. This property is writeable to allow you to set the candidate version of the package. Just assign a Version() object, and it will be set as the candidate version. N)rYrget_candidate_verr_r)r8rr%r%r& candidate+s  zPackage.candidatecCs,|j|jj|j|j|jdS)z)Set the candidate version of the package.N)rYcache_pre_changerset_candidate_verr_rcache_post_change)r8r@r%r%r&rl9s cCs|jjdur t||jjSdS)z`Return the currently installed version of the package. .. versionadded:: 0.7.9 N)r_ current_verrrHr%r%r&rAs zPackage.installedcC |jdS)a}Return the name of the package, possibly including architecture. If the package is not part of the system's preferred architecture, return the same as :attr:`fullname`, otherwise return the same as :attr:`shortname` .. versionchanged:: 0.7.100.3 As part of multi-arch, this field now may include architecture information. Tr_ get_fullnamerHr%r%r&rKLs z Package.namecCrq)zReturn the name of the package, including architecture. Note that as for :meth:`architecture`, this returns the native architecture for Architecture: all packages. .. versionadded:: 0.7.100.3FrrrHr%r%r&r\s zPackage.fullnamecCrR)zZReturn the name of the package, without architecture. .. versionadded:: 0.7.100.3)r_rKrHr%r%r&rgzPackage.shortnamecCrR)znReturn a uniq ID for the package. This can be used eg. to store additional information about the pkg.)r_rrHr%r%r&rortz Package.idcCrR)z>Return True if the package is an essential part of the system.)r_ essentialrHr%r%r&ruwrzPackage.essentialcCrR)aReturn the Architecture of the package. Note that for Architecture: all packages, this returns the native architecture, as they are internally treated like native packages. To get the concrete architecture, look at the :attr:`Version.architecture` attribute. .. versionchanged:: 0.7.100.3 This is now the package's architecture in the multi-arch sense, previously it was the architecture of the candidate version and deprecated. )r_rrHr%r%r&r}szPackage.architecturecC|jj|jS)z5Return ``True`` if the package is marked for install.)rYrmarked_installr_rHr%r%r&rwzPackage.marked_installcCrv)z5Return ``True`` if the package is marked for upgrade.)rYrmarked_upgrader_rHr%r%r&ryrxzPackage.marked_upgradecCrv)z4Return ``True`` if the package is marked for delete.)rYr marked_deleter_rHr%r%r&rzrxzPackage.marked_deletecCrv)z2Return ``True`` if the package is marked for keep.)rYr marked_keepr_rHr%r%r&r{rxzPackage.marked_keepcCrv)z! Package is marked for downgrade )rYrmarked_downgrader_rHr%r%r&r|rxzPackage.marked_downgradecCrv)z7Return ``True`` if the package is marked for reinstall.)rYrmarked_reinstallr_rHr%r%r&r}rxzPackage.marked_reinstallcCs |jjduS)z,Return ``True`` if the package is installed.N)r_rprHr%r%r&rhrtzPackage.is_installedcCs|jo |jj|jS)z-Return ``True`` if the package is upgradable.)rhrYr is_upgradabler_rHr%r%r&r~szPackage.is_upgradablecCs|js|jo |jj|jS)zReturn ``True`` if the package is no longer required. If the package has been installed automatically as a dependency of another package, and if no packages depend on it anymore, the package is no longer required. )rhrwrYr is_garbager_rHr%r%r&is_auto_removables zPackage.is_auto_removablecCrv)z@Return whether the package is marked as automatically installed.)rYris_auto_installedr_rHr%r%r&rrxzPackage.is_auto_installedc Csx|j|jfD]3}d|}z$t|d}|ddWdWS1s*wYWqty9YqwgS)zReturn a list of files installed by the package. Return a list of unicode names of the files which have been installed by this package z/var/lib/dpkg/info/%s.listrbrrN)rKrrreadrrEnvironmentError)r8rKrrr%r%r&installed_filess * zPackage.installed_filesNc Cs|jdkr|jS|jstdS|dur;|jjdjdkrd}n|jjdjdkr+d}ntd}t|tr6|S|d S|jj}d }|jj }|jj }zt }Wn t yXYn,w||r|jsbqY|jj |jkrp|j}|j }nt |j|dkr|j}|j }||s^|d d } t| d kr| d}~ |d} |d rd |d} |dd } t| d krd| d d}~ ||| ||d}t} zztd|r|rWWt| dSt|} d}dt|} |r|rWWt| dS| }|snL|d }t||}|rJt|jdd}|r(d|vr(|dd d }| d }|r=d|vr=|dd d }|rJt ||dkrJn||7}qt|dkretd}t|tse|d }||_Wnft!y|jjdjdkrtd||f}ntd}t|tr|YWt| S|d YWt| St"t#fytd}t|tr|YWt| S|d YWt| SwWt| |jSt| w)a Download the changelog of the package and return it as unicode string. The parameter *uri* refers to the uri of the changelog file. It may contain multiple named variables which will be substitued. These variables are (src_section, prefix, src_pkg, src_ver). An example is the Ubuntu changelog:: "http://changelogs.ubuntu.com/changelogs/pool" \ "/%(src_section)s/%(prefix)s/%(src_pkg)s" \ "/%(src_pkg)s_%(src_ver)s/changelog" The parameter *cancel_lock* refers to an instance of threading.Event, which if set, prevents the download. rz$The list of changes is not availableNrDebianzshttp://packages.debian.org/changelogs/pool/%(src_section)s/%(prefix)s/%(src_pkg)s/%(src_pkg)s_%(src_ver)s/changelogUbuntuzuhttp://changelogs.ubuntu.com/changelogs/pool/%(src_section)s/%(prefix)s/%(src_pkg)s/%(src_pkg)s_%(src_ver)s/changelogrmain/rlib:) src_sectionprefixsrc_pkgsrc_verrz^%s \((.*)\)(.*)$Tr@zThe list of changes is not available yet. Please use http://launchpad.net/ubuntu/+source/%s/%s/+changelog until the changes become available or try again later.zOFailed to download the list of changes. Please check your Internet connection.)$rgrlrrrrr5rrrrr rP SystemErrorrr@rrrrrsocketgetdefaulttimeoutsetdefaulttimeoutis_setrreescapereadlinematchr:rgrouprIOErrorr)r8r+ cancel_lockresrrrr src_records section_splitr src_ver_splittimeoutchangelog_file changelogregexpline_rawrrr changelog_verr%r%r& get_changelogs             A 8               zPackage.get_changelogcCst|S)zcReturn a VersionList() object for all available versions. .. versionadded:: 0.7.9 )rrHr%r%r&versionsrzPackage.versionscCrv)z5Return True if the to-be-installed package is broken.)rYris_inst_brokenr_rHr%r%r&rrxzPackage.is_inst_brokencCrv)z/Return True if the installed package is broken.)rYr is_now_brokenr_rHr%r%r&rrxzPackage.is_now_brokencCs|jjtjkS)z8Checks whether the package is is the config-files state.)r_ current_stater CURSTATE_CONFIG_FILESrHr%r%r&has_config_filesszPackage.has_config_filescCs(|j|jj|j|jdS)zMark a package for keep.N)rYrmr mark_keepr_rorHr%r%r&rs zPackage.mark_keepTFcCsv|j|jj|j||r4|jjjdkr4t|jj}||j| |j| |j| |j dS)a+Mark a package for deletion. If *auto_fix* is ``True``, the resolver will be run, trying to fix broken packages. This is the default. If *purge* is ``True``, remove the configuration files of the package as well. The default is to keep the configuration. rN) rYrmr mark_deleter_ broken_countr ProblemResolverclearprotectremoveresolvero)r8auto_fixpurgefixr%r%r&rs    zPackage.mark_deletecCsn|j|jj|j|||r0|jjjdkr0t|jj}||j| |j| d|j dS)a0Mark a package for install. If *autoFix* is ``True``, the resolver will be run, trying to fix broken packages. This is the default. If *autoInst* is ``True``, the dependencies of the packages will be installed automatically. This is the default. If *fromUser* is ``True``, this package will not be marked as automatically installed. This is the default. Set it to False if you want to be able to automatically remove the package at a later stage when no other package depends on it. rTN) rYrmr mark_installr_rr rrrrro)r8r auto_inst from_userfixerr%r%r&rs    zPackage.mark_installcCs>|jr|j}|j|d||dStjd|jjdS)zMark a package for upgrade.)rz4MarkUpgrade() called on a non-upgradeable pkg: '%s' N) r~rr mark_autosysstderrwriter_rK)r8rautor%r%r& mark_upgrades  zPackage.mark_upgradecCs|jj|j|dS)aMark a package as automatically installed. Call this function to mark a package as automatically installed. If the optional parameter *auto* is set to ``False``, the package will not be marked as automatically installed anymore. The default is ``True``. N)rYrrr_)r8rr%r%r&rszPackage.mark_autocCs|jj||dS)aCommit the changes. The parameter *fprogress* refers to a apt_pkg.AcquireProgress() object, like apt.progress.text.AcquireProgress(). The parameter *iprogress* refers to an InstallProgress() object, as found in apt.progress.base. N)rYrcommit)r8 fprogress iprogressr%r%r&rs zPackage.commit)NNTF)TTT)T)(r+r,r-r.rBrIrMrrurlsetterrrKrrrrurrwryrzr{r|r}rhr~rrrrrrrrrrrrrrr%r%r%r&rsz                    /        rc Cstdddl}ttjj}t|}|d}td|j td|j td|j j td|j j td |j jtd |j jtd |j jtd |j jtd |j jtd|jtd|j jtd|j jtd|j jtd|j jtd|j jtd|j jtd|j j|j jD]}tddd|jDqtd|j jtd|j jtd|j jt|ddD],}td||D]}|j r|!dddkr|"|qtd |j#j$td!|j#j%qtdD]K}td"|t|}|&D](}|!dddkr?z ||'|Wqt(y>td#|Yqwqtd |j#j$td$|j#j)qdS)%z Self-test.zSelf-test for the Package modulrNz apt-utilsz Name: %s zID: %s zPriority (Candidate): %s zPriority (Installed): %s zInstalled: %s zCandidate: %s zCandidateDownloadable: %szCandidateOrigins: %szSourcePkg: %s z Section: %s z Summary: %szDescription (formatted) : %szDescription (unformatted): %szInstalledSize: %s zPackageSize: %s zDependencies: %szRecommends: %s,css(|]}d|j|j|j|jfVqdS)z%s (%s) (%s) (%s)N)rKr@rLrs)rjor%r%r&r#s z_test..zarch: %sz homepage: %szrec: 2vcardrz8Running install on random upgradable pkgs with AutoFix: rz Broken: %s zInstCount: %s z.Randomly remove some packages with AutoFix: %szError trying to remove: %s z DelCount: %s )*printrandomr initr>r?r@ OpProgressCacherKrrlrrr@rrrrrrrrr#rrrrrrrrr~randintrrr inst_countrrr del_count)rr?r`rarAirKr%r%r&_testsn          r__main__)3r. __future__rr7rrrrrU threading http.clientr urllib.errorrurllib.requestrtypingrrrr r r r r rrrr apt.progress.textr>apt.progress.baserrrr__all__r' Exceptionr)r0objectrrrrrrrrr+r%r%r%r&sR    4  S%D!Z| :