
    8.gf                       S SK Jr  S SKrS SKrS SKrS SKrS SKJrJrJ	r	  S SK
JrJr  S SKrS SKrS SKJrJr  S SKJrJrJr   " S S\5      r " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S5      r " S S5      r " S S5      r  " S S5      r! " S S\!5      r" " S S\!5      r# " S S5      r$ " S S 5      r%S%S! jr&S%S" jr'S&S# jr(\)S$:X  a  \(" 5         gg)'    )annotationsN)CallableIteratorKeysView)Anycast)PackageVersion)AcquireProgressInstallProgress
OpProgressc                      \ rS rSrSrSrg)FetchCancelledException&   zAException that is thrown when the user cancels a fetch operation. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       +/usr/lib/python3/dist-packages/apt/cache.pyr   r   &   s    Kr   r   c                      \ rS rSrSrSrg)FetchFailedException*   z-Exception that is thrown when fetching fails.r   Nr   r   r   r   r   r   *   s    7r   r   c                      \ rS rSrSrSrg)UntrustedException.   z>Exception that is thrown when fetching fails for trust reasonsr   Nr   r   r   r   r   r   .       Hr   r   c                      \ rS rSrSrSrg)LockFailedException2   z,Exception that is thrown when locking fails.r   Nr   r   r   r   r#   r#   2   s    6r   r#   c                      \ rS rSrSrSrg)CacheClosedException6   z>Exception that is thrown when the cache is used after close().r   Nr   r   r   r   r&   r&   6   r!   r   r&   c                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)_WrappedLock:   z\Wraps an apt_pkg.FileLock to raise LockFailedException.

Initialized using a directory path.c                    Xl         [        R                  " [        R                  R                  US5      5      U l        g )Nlock)_pathapt_pkgFileLockospathjoin_lock)selfr1   s     r   __init___WrappedLock.__init__?   s(    
%%bggll4&@A
r   c                     U R                   R                  5       $ ! [        R                   a"  n[	        SU R
                  < SU< 35      eS nAff = f)NzFailed to lock directory z: )r3   	__enter__r.   Errorr#   r-   )r4   es     r   r8   _WrappedLock.__enter__C   sG    	::''))}} 	%7;zz1E 	s    AAAc                :    U R                   R                  XU5      $ N)r3   __exit__)r4   typvalue	tracebacks       r   r>   _WrappedLock.__exit__K   s    zz""3y99r   )r3   r-   N)r1   strreturnNonerD   rE   )r?   objectr@   rG   rA   rG   rD   rE   )	r   r   r   r   r   r5   r8   r>   r   r   r   r   r)   r)   :   s    +B:r   r)   c                     \ rS rSrSr   S0       S1S jjrS2S jrS2S jrS3S jrS4S jr	S5S6S	 jjr
S2S
 jrS2S jrS7S jrS8S jrS9S jrS5S:S jjrS;S jrS<S jrS=S jrS>S jrS>S jrS?S jrS@S jrSAS jrSBSCS jjr\S?S j5       r\S?S j5       r\SDS j5       r      SES jr S5       SFS jjr   SG       SHS jjr SIS jr!  SJ       SKS  jjr"    SL         SMS! jjr#      SNS" jr$   SG       SOS# jjr%S2S$ jr&S2S% jr'S2S& jr(SPS' jr)          SQS( jr*SRS) jr+\SSS* j5       r,\S?S+ j5       r-\S?S, j5       r.\S?S- j5       r/\S?S. j5       r0S/r1g)TCacheO   aX  Dictionary-like package cache.

The APT cache file contains a hash table mapping names of binary
packages to their metadata. A Cache object is the in-core
representation of the same. It provides access to APTs idea of the
list of available packages.

The cache can be used like a mapping from package names to Package
objects (although only getting items is supported).

Keyword arguments:
progress -- a OpProgress object,
rootdir  -- an alternative root directory. if that is given the system
sources.list and system lists/files are not read, only file relative
to the given rootdir,
memonly  -- build the cache in memory only.


.. versionchanged:: 1.0

    The cache now supports package names with special architecture
    qualifiers such as :all and :native. It does not export them
    in :meth:`keys()`, though, to keep :meth:`keys()` a unique set.
Nc           	        [        [        R                  S 5      U l        [        [        R                  S 5      U l        [        [        R                  S 5      U l        [        [        R                  S 5      U l	        0 U l
        0 U l        [        R                  " 5       U l        [        R                  " 5       U l        SU l        S U l        U R'                  SS5        U R'                  SS5        U(       a   [        R(                  R+                  SS5        U(       Ga  [,        R.                  R1                  U5      n[,        R.                  R3                  US-   5      (       a(  [        R4                  " [        R(                  US-   5        [,        R.                  R7                  US-   5      (       a(  [        R8                  " [        R(                  US-   5        [        R(                  R+                  S	U5        [        R(                  R+                  S
US-   5        [,        R.                  R3                  [,        R.                  R;                  USSS5      5      (       a@  [        R(                  R+                  S[,        R.                  R;                  USSS5      5        U R=                  U5        [        R>                  " 5         [        R(                  RA                  S5      n[C        U5      U l"        U RG                  U5        g )Ncache_post_open_inc_changes_countcache_post_changezDir::Cache::pkgcache z/etc/apt/apt.conf/etc/apt/apt.conf.dDirDir::State::status/var/lib/dpkg/statususrbindpkgzDir::bin::dpkgDir::Cache::Archives)$r   r.   rI   _cacheDepCache	_depcachePackageRecords_records
SourceList_list
_callbacks_callbacks2weakrefWeakValueDictionary_weakrefWeakSet_weakversions_changes_count_sorted_setconnectconfigsetr0   r1   abspathexistsread_config_fileisdirread_config_dirr2   _check_and_create_required_dirsinit_systemfind_dirr)   _archive_lockopen)r4   progressrootdirmemonlyarchive_dirs        r   r5   Cache.__init__i   s#    &*'--%>+/0@0@$+G04""D1
 *.g.@.@$)G
FH  	 '') 	 8?7H -1&(<=(*>?NN5r:ggoog.Gww~~g(;;<<((CV9VWww}}W'<<==''BW8WXNNug.NN3W?U5UV ww~~bggll7E5&IJJ""$bggll7E5&&Q
 009 ! nn--.DE)+6		(r   c                8    U R                   R                  5         g)zFix broken packages.N)r[   
fix_brokenr4   s    r   r|   Cache.fix_broken   s    !!#r   c                .    U =R                   S-  sl         g)zIncrease the number of changes   N)rg   r}   s    r   rN   Cache._inc_changes_count   s    q r   c                @   SS/n/ SQnU HC  n[         R                  R                  X-   5      (       a  M+  [         R                  " X-   5        ME     U HG  n[         R                  R                  X-   5      (       a  M+  [	        X-   S5      R                  5         MI     g)zN
check if the required apt directories/files are there and if
not create them
rT   z/etc/apt/sources.list)z/var/lib/dpkgz	/etc/apt/rQ   z/etc/apt/preferences.dz/var/cache/apt/archives/partialz/var/lib/apt/lists/partialwN)r0   r1   rm   makedirsru   close)r4   rw   filesdirsdfs         r   rq   %Cache._check_and_create_required_dirs   s}     ##

 A77>>'+..GK(  A77>>'+..W[#&,,. r   c                    XR                   ;   a5  U R                   U    H"  nUS:X  a  U R                  5         M  U" 5         M$     XR                  ;   a&  U R                  U    H  u  p#nU" U /UQ70 UD6  M     gg)z!internal helper to run a callbackrN   N)r`   rN   ra   r4   namecallbackargskwdss        r   _run_callbacksCache._run_callbacks   sx    ??" OOD133++-J	 2 ###(,(8(8(>$--- )? $r   c                   Uc(  [         R                  R                  R                  5       nU R	                  5         Xl        U R                  S5        [        R                  " U5      U l	        [        R                  " U R                  5      U l        [        R                  " U R                  5      U l        [        R                  " 5       U l        U R                  R!                  5         SU l        U R%                  5         ['        [        R(                  " 5       5      S:  U l        UR-                  5         U R                  S5        g)zDOpen the package cache, after that it can be used like
a dictionary
Ncache_pre_openr   rM   )aptrv   baser   r   op_progressr   r.   rI   rY   rZ   r[   r\   r]   r^   r_   read_main_listrh   _Cache__remaplenget_architectures_have_multi_archdone)r4   rv   s     r   ru   
Cache.open   s     ||((335H

#,-mmH- ))$++6..t{{;'')


!!# #G$=$=$? @1 D-.r   c                   [        U R                  R                  5       5       HR  n U R                  U   n U R                  UR
                  R                  UR
                  R                  4   Ul        MT     [        U R                  5       GH  nUR                  R
                  R                   H  nUR                  UR                  R                  :X  d  M)  UR                  S:X  d@  UR                  R                  S:X  d&  UR                  UR                  R                  :X  d  My  UR                  UR                  R                  :X  d  M  UR                   UR                  R                   :X  d  M  XCl          M     U R                  R#                  U5        GM     g! [         a     GM  f = f! [         a    U R                  U	  GM  f = f)zCalled after cache reopen() to relocate to new cache.

Relocate objects like packages and versions from the old
underlying cache to the new one.
r   N)listrd   keysKeyErrorrY   _pkgr   architectureLookupErrorrf   packageversion_listhash_candsize
multi_archver_strremove)r4   keypkgvervs        r   __remapCache.__remap   sM    **,-CmmC(';;sxx}}chh6K6K'KL . **+C[[%%22 FFciinn,1		!(;qvv?W		(<(<<		SYY%6%66 !I 3 ""))#. ,  
  'MM#&'s"   F$>F6$
F32F36GGc                F    U ? [        [        R                  S5      U l         g)zClose the package cacheN)r]   r   r.   r\   r}   s    r   r   Cache.close  s     MW33T:r   c                    U $ )zEnter the with statementr   r}   s    r   r8   Cache.__enter__  s    r   c                $    U R                  5         g)zExit the with statementN)r   )r4   exc_type	exc_valuerA   s       r   r>   Cache.__exit__  s    

r   c                     [        U5      nU R                  U   nU R                  U5      (       d  [        SU-  5      eU R	                  U5      nU$ ! [         a    [        SU-  5      ef = f)z look like a dictionary (get key)z!The cache has no package named %r)rC   rY   r   _Cache__is_real_pkg_rawpkg_to_pkg)r4   r   rawpkgr   s       r   __getitem__Cache.__getitem__  s|    	Fc(C[[%F
 !!&))>DEE!!&)
  	F>DEE	Fs   A A,c                0     X   $ ! [          a    Us $ f = f)zQReturn *self*[*key*] or *default* if *key* not in *self*.

.. versionadded:: 1.1
)r   )r4   r   defaults      r   get	Cache.get$  s#    
	9 	N	s    c                j    UR                  SS9nU R                  R                  U[        X5      5      $ )zWReturns the apt.Package object for an apt_pkg.Package object.

.. versionadded:: 1.0.0
Tpretty)get_fullnamerd   
setdefaultr	   )r4   r   fullnames      r   r   Cache._rawpkg_to_pkg.  s3    
 &&d&3}}'''$2GHHr   c              #     #    U R                  5        H8  n[        X R                  U   5      nU R                  R	                  X5      v   M:     g 7fr=   )r   r	   rY   rd   r   r4   pkgnamer   s      r   __iter__Cache.__iter__7  s?      yy{G$G 45C--**788 #s   AAc                    UR                   $ )z8Check if the apt_pkg.Package provided is a real package.)has_versions)r4   r   s     r   __is_real_pkgCache.__is_real_pkgA  s    """r   c                
    X;   $ r=   r   r4   r   s     r   has_keyCache.has_keyE  
    {r   c                r     U R                  U R                  [        U5         5      $ ! [         a     gf = fNF)r   rY   rC   r   r   s     r   __contains__Cache.__contains__H  s7    	%%dkk#c(&;<< 		s   &) 
66c                4    [        U R                  5       5      $ r=   )r   r   r}   s    r   __len__Cache.__len__N  s    499;r   c                   ^  T R                   c.  [        U 4S jT R                  R                   5       5      T l         [	        T R                   5      $ )Nc              3  r   >#    U  H,  nTR                  U5      (       d  M  UR                  S S9v   M.     g7f)Tr   N)r   r   ).0pr4   s     r   	<genexpr>Cache.keys.<locals>.<genexpr>S  s3      &-A%%a( ,d+-s   77)rh   sortedrY   packagesr   r}   s   `r   r   
Cache.keysQ  sF    #% &--&  D
 D$$%%r   c                    / nU R                   R                  nU R                  R                   H2  nU" U5      (       a  M  UR	                  U R                  U5      5        M4     U$ )zGet the marked changes)r[   marked_keeprY   r   appendr   )r4   changesr   r   s       r   get_changesCache.get_changesZ  sS    nn00kk**Fv&&t226:; + r   c                z    U R                  5         U R                  R                  U5        U R                  5         g)zUpgrade all packages.

If the parameter *dist_upgrade* is True, new dependencies will be
installed as well (and conflicting packages may be removed). The
default value is False.
N)cache_pre_changer[   upgraderO   )r4   dist_upgrades     r   r   Cache.upgradec  s.     	|, r   c                    U R                   c  [        S5      e[        R                  " U R                  5      n[        R
                  " 5       nUR                  X R                  U R                   5        UR                  $ )z;Get the size of the packages that are required to download.&Cache object used after close() called)	r]   r&   r.   PackageManagerr[   Acquireget_archivesr_   fetch_needed)r4   pmfetchers      r   required_downloadCache.required_downloadn  s\     == &'OPP##DNN3//#
T]];###r   c                .    U R                   R                  $ )z8Get the size of the additional required space on the fs.)r[   usr_sizer}   s    r   required_spaceCache.required_spacex  s     ~~&&&r   c                z   [        5       nU R                  R                  n[        [        R
                  [        R                  45      nU R                  R                   HW  nU" U5      nU(       d  M  UR                  (       a  M'  UR                  U;   d  M9  UR                  UR                  SS95        MY     U$ )zAReturn the packages not downloadable packages in reqreinst state.Tr   )rk   r[   get_candidate_ver	frozensetr.   INSTSTATE_REINSTREQINSTSTATE_HOLD_REINSTREQrY   r   downloadable
inst_stateaddr   )r4   	reqreinstr  statesr   cands         r   req_reinstall_pkgsCache.req_reinstall_pkgs}  s     E	 NN<<(('*J*JK
 ;;''C$S)DtD---#..F2Jc..d.;< ( r   c                ^   Uc   [         R                  R                  SS5      nUR                   Vs/ s H  o3R                  (       a  M  UPM     nnU(       a+  U(       d$  [        SSR                  S U 5       5      -  5      eUR                  5       nSnSnUR                   HT  nUR                  UR                  :X  a  M  UR                  (       a  M2  USUR                   SUR                   S3-  nS	nMV     XQR                  :X  a  [        U5      eU(       a  [        U5      eU$ s  snf )
NzAPT::Get::AllowUnauthenticatedFzUntrusted packages:
%s
c              3  8   #    U  H  oR                   v   M     g 7fr=   )desc_uri)r   is     r   r   %Cache._run_fetcher.<locals>.<genexpr>  s     5T)Qjj)s   rP   zFailed to fetch  T)r.   rj   find_bitems
is_trustedr   r2   runstatus	STAT_DONE	STAT_IDLEr  
error_textRESULT_CANCELLEDr   r   )r4   r   allow_unauthenticateditem	untrustedresfailederr_msgs           r   _run_fetcherCache._run_fetcher  s
    !($+NN$9$93U%! '.mmKmd??Tm	K2$)DII5T)5T,TT 
 kkm MMD{{dnn,~~)$--$//9J"MMGF " ***)'22&w//
3 Ls   D*
D*c                    U R                   c  [        S5      eUR                  XR                  U R                   5      (       d  gU R	                  X5      $ )zfetch the needed archivesr   F)r]   r&   r   r_   r'  )r4   r   r   r!  s       r   _fetch_archivesCache._fetch_archives  sK     == &'OPP w

DMMBB   @@r   c                \   Ub  Ub  [        S5      eUc(  [        R                  R                  R	                  5       nUc  [
        R                  " U5      nU R                     U R                  U[
        R                  " U R                  5      U5      sSSS5        $ ! , (       d  f       g= f)a  Fetch the archives for all packages marked for install/upgrade.

You can specify either an :class:`apt.progress.base.AcquireProgress()`
object for the parameter *progress*, or specify an already
existing :class:`apt_pkg.Acquire` object for the parameter *fetcher*.

The return value of the function is undefined. If an error occurred,
an exception of type :class:`FetchFailedException` or
:class:`FetchCancelledException` is raised.

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.8.0
Nz'Takes a progress or a an Acquire object)
ValueErrorr   rv   textr   r.   r   rt   r*  r   r[   )r4   rv   r   r!  s       r   fetch_archivesCache.fetch_archives  s    , G$7FGG||((88:H?ooh/G''//?AV  s   "1B
B+c                     U R                   U   n[        UR                  =(       a    UR                  (       + 5      $ ! [         a     gf = f)z0Return whether the package is a virtual package.F)rY   boolhas_providesr   r   r   s      r   is_virtual_packageCache.is_virtual_package  sK    	C++g&C ((A1A1A-ABB  		s   > 
A
Ac                   [        5       nU R                  R                  n U R                  U   nUR                  (       a  U(       d  [        U5      $ UR                   HF  u  pxn	U	R                  n
U(       a  X" U
5      :X  d  M&  UR                  U R                  U
5      5        MH     [        U5      $ ! [         a    [        U5      s $ f = f)a  Return a list of all packages providing a package.

Return a list of packages which provide the virtual package of the
specified name.

If 'candidate_only' is False, return all packages with at
least one version providing the virtual package. Otherwise,
return only those packages where the candidate version
provides the virtual package.

If 'include_nonvirtual' is True then it will search for all
packages providing pkgname, even if pkgname is not itself
a virtual pkg.
)rk   r[   r  rY   r   r   r   provides_list
parent_pkgr  r   )r4   r   candidate_onlyinclude_nonvirtual	providersr  vpprovidesprovidesverversionr   s              r   get_providing_packagesCache.get_providing_packages  s    * #&%	 NN<<	#W%B'9I& /1.>.>*H7''F!g1B61J&Jd11&9: /? I  	#	?"	#s   1B5 5CCc                X   [        [        R                  R                  S5      5         U(       Ga   [        R                  R	                  S5      n[        R                  R	                  S5      n[        R                  R	                  S5      n[        R                  R                  S[        R                  R                  U5      5        [        R                  R                  SS5        [        R                  R                  SS5        [        R                  " 5       nUR                  5         OU R                  n Uc(  [        R                  R                  R                  5       n U R                   R#                  XU5      n	U	(       d  U(       a
  ['        5       eU	U(       a`  [        R                  R                  SW5        [        R                  R                  SW5        [        R                  R                  SW5        sSSS5        $ ! [$         a  n
['        U
5      eSn
A
ff = f! U(       aa  [        R                  R                  SW5        [        R                  R                  SW5        [        R                  R                  SW5        f f = f! , (       d  f       g= f)a  Run the equivalent of apt-get update.

You probably want to call open() afterwards, in order to utilise the
new cache. Otherwise, the old cache will be used which can lead to
strange bugs.

The first parameter *fetch_progress* may be set to an instance of
apt.progress.FetchProgress, the default is apt.progress.FetchProgress()
.
sources_list -- Update a alternative sources.list than the default.
Note that the sources.list.d directory is ignored in this case
zDir::State::ListszDir::Etc::sourcelistzDir::Etc::sourcepartszAPT::List-Cleanupxxx0N)r)   r.   rj   rs   findrk   r0   r1   rl   r^   r   r_   r   rv   r   r   rY   updateSystemErrorr   )r4   fetch_progresspulse_intervalraise_on_errorsources_listold_sources_listold_sources_list_dold_cleanupslistr$  r:   s              r   rF  Cache.update  s   & '..112EFG#*>>#6#67M#N %,^^%8%89P%Q"%nn112EF""*BGGOOL,I ""#:EB""#6<**,$$&

I!)%(\\%6%6%F%F%HN2++,,^NSC ~.00NN&&'=?OPNN&&'>@RSNN&&':KH= HG( # 2.q112  NN&&'=?OPNN&&'>@RSNN&&':KH  7 HGsJ   DJ?+H.+HH. A'J
H+H&&H++H..A*JJ
J)c                    UR                  5         [        R                  " 5       nU(       a  [        R
                  " 5          UR                  U5      nU(       a  [        R                  " 5          UR                  5         U$ ! [         a    UR                  5          Nf = f! U(       a  [        R                  " 5         f f = f! [         a    UR                  5          U$ f = f)a!  
The first parameter *pm* refers to an object returned by
apt_pkg.PackageManager().

The second parameter *install_progress* refers to an InstallProgress()
object of the module apt.progress.

This releases a system lock in newer versions, if there is any,
and reestablishes it afterwards.
)
startUpdateAttributeErrorstart_updater.   pkgsystem_is_lockedpkgsystem_unlock_innerr  pkgsystem_lock_innerfinishUpdatefinish_update)r4   r   install_progress
did_unlockr$  s        r   install_archivesCache.install_archivesB  s    	,((* 002
**,	/"&&r*C,,.	-))+ 
#  	,))+	, ,,. 
  	-**,
	-s/   B B$ 2C B! B!$CC$#C$c                   Uc(  [         R                  R                  R                  5       nUc(  [         R                  R                  R	                  5       nUc   e[
        R                  " 5          [
        R                  " U R                  5      n[
        R                  " U5      nU R                      U R                  XTU5      nU R                  XB5      nXdR                  :X  a  OJXdR                  :X  a  [        S5      eXdR                   :X  a  O[        SU-  5      eUR#                  5         M}  SSS5        SSS5        WWR                  :H  $ ! , (       d  f       N%= f! , (       d  f       N.= f)a  Apply the marked changes to the cache.

The first parameter, *fetch_progress*, refers to a FetchProgress()
object as found in apt.progress, the default being
apt.progress.FetchProgress().

The second parameter, *install_progress*, is a
apt.progress.InstallProgress() object.

The keyword-only parameter *allow_unauthenticated* specifies whether
to allow unauthenticated downloads. If not specified, it defaults to
the configuration option `APT::Get::AllowUnauthenticated`.
NzinstallArchives() failedz<internal-error: unknown result code from InstallArchives: %s)r   rv   r   r   r   r.   
SystemLockr   r[   r   rt   r*  r\  RESULT_COMPLETEDRESULT_FAILEDrG  RESULT_INCOMPLETEshutdown)r4   rH  rZ  r!  r   r   r$  s          r   commitCache.commite  s?   4 ! \\..>>@N#"||00@@B+++!''7Boon5G##..w<QRC //EC111 0 00)*DEE 4 44)<>AB 
 $$&%  $ ". b))))) $# "!s&   1AE#4A?E3E#
E 	E##
E1c                8    U R                   R                  5         g)zUnmark all changesN)r[   initr}   s    r   clearCache.clear  s    r   c                &    U R                  S5        g)z>called internally if the cache has changed, emit a signal thenrO   Nr   r}   s    r   rO   Cache.cache_post_change  s    /0r   c                &    U R                  S5        g)zEcalled internally if the cache is about to change, emit
a signal thenr   Nrk  r}   s    r   r   Cache.cache_pre_change  s     	./r   c                    US:w  a  [         R                  " S[        S5        XR                  ;  a  / U R                  U'   U R                  U   R	                  U5        g)zConnect to a signal.

.. deprecated:: 1.0

    Please use connect2() instead, as this function is very
    likely to cause a memory leak.
rN   zAconnect() likely causes a reference cycle, use connect2() instead   N)warningswarnRuntimeWarningr`   r   )r4   r   r   s      r   ri   Cache.connect  sS     ++MMV
 &$&DOOD!$$X.r   c                    XR                   ;  a  / U R                   U'   U R                   U   R                  X#U45        g)a  Connect to a signal.

The callback will be passed the cache as an argument, and
any arguments passed to this function. Make sure that, if you
pass a method of a class as your callback, your class does not
contain a reference to the cache.

Cyclic references to the cache can cause issues if the Cache object
is replaced by a new one, because the cache keeps a lot of objects and
tens of open file descriptors.

currently only used for cache_{post,pre}_{changed,open}.

.. versionadded:: 1.0
N)ra   r   r   s        r   connect2Cache.connect2  s>    $ '''%'DT"%%xt&<=r   c                B    [         R                  " U R                  5      $ )ao  Return an `ActionGroup` object for the current cache.

Action groups can be used to speedup actions. The action group is
active as soon as it is created, and disabled when the object is
deleted or when release() is called.

You can use the action group as a context manager, this is the
recommended way::

    with cache.actiongroup():
        for package in my_selected_packages:
            package.mark_install()

This way, the action group is automatically released as soon as the
with statement block is left. It also has the benefit of making it
clear which parts of the code run with a action group and which
don't.
)r.   ActionGroupr[   r}   s    r   actiongroupCache.actiongroup  s    & ""4>>22r   c                .   [         R                  R                  [        R                  R                  S5      5      n[         R                  " [         R                  R                  US5      5       H!  n[        R                  " US5      (       d  M!    g   g)zReturn True if the dpkg was interrupted

All dpkg operations will fail until this is fixed, the action to
fix the system if dpkg got interrupted is to run
'dpkg --configure -a' as root.
rS   updatesz[0-9]*TF)	r0   r1   dirnamer.   rj   	find_filelistdirr2   fnmatch)r4   dpkg_status_dirr   s      r   dpkg_journal_dirtyCache.dpkg_journal_dirty  sg     ''//NN$$%9:
 BGGLL)DEAq(++ F r   c                .    U R                   R                  $ )z7Return the number of packages with broken dependencies.)r[   broken_countr}   s    r   r  Cache.broken_count  s     ~~***r   c                .    U R                   R                  $ )z2Return the number of packages marked for deletion.)r[   	del_countr}   s    r   delete_countCache.delete_count   s     ~~'''r   c                .    U R                   R                  $ )z6Return the number of packages marked for installation.)r[   
inst_countr}   s    r   install_countCache.install_count       ~~(((r   c                .    U R                   R                  $ )z-Return the number of packages marked as keep.)r[   
keep_countr}   s    r   r  Cache.keep_count
  r  r   )rt   rY   r`   ra   rg   r[   r   r_   r]   rh   rd   rf   r   )NNF)rv   OpProgress | Nonerw   
str | Nonerx   r2  rD   rE   rF   )rw   rC   rD   rE   )r   rC   rD   rE   r=   )rv   r  rD   rE   )rD   rI   )r   rG   r   rG   rA   rG   rD   rE   )r   rG   rD   r	   )r   rG   r   rG   rD   r   )r   apt_pkg.PackagerD   r	   rD   zIterator[Package])r   r  rD   r2  r   rG   rD   r2  rD   int)rD   z	list[str])rD   list[Package])F)r   r2  rD   rE   )rD   zset[str])r   apt_pkg.Acquirer!  bool | NonerD   r  )r   r  r   apt_pkg.PackageManagerr!  r  rD   r  )NNN)rv   AcquireProgress | Noner   zapt_pkg.Acquire | Noner!  r  rD   r  )r   rC   rD   r2  )TF)r   rC   r9  r2  r:  r2  rD   r  )Nr   TN)
rH  r  rI  r  rJ  r2  rK  r  rD   r  )r   r  rZ  r   rD   r  )rH  r  rZ  zInstallProgress | Noner!  r  rD   r2  )r   rC   r   zCallable[..., None] | strrD   rE   )
r   rC   r   zCallable[..., Any]r   rG   r   rG   rD   rE   )rD   zapt_pkg.ActionGroup)rD   r2  )2r   r   r   r   r   r5   r|   rN   rq   r   ru   r   r   r8   r>   r   r   r   r   r   r   r   r   r   r   r   propertyr   r  r  r'  r*  r/  r4  r@  rF  r\  rd  rh  rO   r   ri   rv  rz  r  r  r  r  r  r   r   r   r   rI   rI   O   s   6 '+"	5#5 5 	5
 
5n$!/2./0/@; I9# &	! $ $ ' '  !&!?J!	!N .2	A A #A  +	A
 
A( ,0*.-1	 (  (   +	 
 
 DC  $#(	"" " !	"
 
"L 26##'1I.1I 1I 	1I
 !1I 
1If!(!<K!	!J 2637-1	8*.8* 18*  +	8*
 
8*t10
/$>>#5>>D>NT>	>,3*   + + ( ( ) ) ) )r   rI   c                  ^    \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jrS
rg)ProblemResolveri  zmResolve problems due to dependencies and conflicts.

The first argument 'cache' is an instance of apt.Cache.
c                Z    [         R                  " UR                  5      U l        Xl        g r=   )r.   r  r[   	_resolverrY   r4   caches     r   r5   ProblemResolver.__init__  s     00Ar   c                N    U R                   R                  UR                  5        g)z'Reset the package to the default state.N)r  rh  r   r4   r   s     r   rh  ProblemResolver.clear  s    W\\*r   c                N    U R                   R                  UR                  5        g)z)Protect a package so it won't be removed.N)r  protectr   r  s     r   r  ProblemResolver.protect  s    w||,r   c                N    U R                   R                  UR                  5        g)zMark a package for removal.N)r  r   r   r  s     r   r   ProblemResolver.remove"  s    gll+r   c                    U R                   R                  5         U R                  R                  5         U R                   R	                  5         g)z:Resolve dependencies, try to remove packages where needed.N)rY   r   r  resolverO   r}   s    r   r  ProblemResolver.resolve&  s2    $$& %%'r   c                    U R                   R                  5         U R                  R                  5         U R                   R	                  5         g)z4Resolve dependencies, do not try to remove packages.N)rY   r   r  resolve_by_keeprO   r}   s    r   r  ProblemResolver.resolve_by_keep,  s2    $$&&&(%%'r   c                    U R                   R                  5         U R                  R                  5         U R                   R	                  5         g)zKeep back phased updates.N)rY   r   r  keep_phased_updatesrO   r}   s    r   r  #ProblemResolver.keep_phased_updates2  s2    $$&**,%%'r   )rY   r  Nr  rI   rD   rE   )r   r	   rD   rE   rF   )r   r   r   r   r   r5   rh  r  r   r  r  r  r   r   r   r   r  r    s*    
+-,(((r   r  c                  "    \ rS rSrSrSS jrSrg)Filteri<  zFilter base classc                    g)zYFilter function, return True if the package matchs a
filter criteria and False otherwise
Tr   r4   r   s     r   applyFilter.apply?  s     r   r   Nr   r	   rD   r2  r   r   r   r   r   r  r   r   r   r   r  r  <  s
    r   r  c                  "    \ rS rSrSrSS jrSrg)MarkedChangesFilteriF  z&Filter that returns all marked changesc                l    UR                   (       d"  UR                  (       d  UR                  (       a  gg)NTF)marked_installmarked_deletemarked_upgrader  s     r   r  MarkedChangesFilter.applyI  s!    !2!2c6H6Hr   r   Nr  r  r   r   r   r  r  F  s
    0r   r  c                  "    \ rS rSrSrSS jrSrg)InstalledFilteriP  zEFilter that returns all installed packages.

.. versionadded:: 1.0.0
c                    UR                   $ r=   )is_installedr  s     r   r  InstalledFilter.applyV  s    r   r   Nr  r  r   r   r   r  r  P  s    
 r   r  c                  @    \ rS rSrSrS	S jrS	S jrS
S jrS	S jrSr	g)_FilteredCacheHelperiZ  z:Helper class for FilteredCache to break a reference cycle.c                    0 U l         / U l        UR                  SU R                  5        UR                  SU R                  5        g )NrO   rM   )	_filtered_filtersrv  filter_cache_post_changer  s     r   r5   _FilteredCacheHelper.__init__]  s<     +-&(*D,I,IJ($*G*GHr   c                    0 U l         U HH  nU R                   H5  nUR                  U5      (       d  M  SU R                   UR                  '     MF     MJ     g)zinternal helper to refilterTN)r  r  r  r   )r4   r  r   r   s       r   _reapply_filter$_FilteredCacheHelper._reapply_filtere  sE     C]]773<</3DNN388, # r   c                H    / U l         U R                   R                  U5        gzSet the current active filter.N)r  r   r4   filters     r   
set_filter_FilteredCacheHelper.set_filtero  s    V$r   c                &    U R                  U5        gz;Called internally if the cache changes, emit a signal then.N)r  r  s     r   r  -_FilteredCacheHelper.filter_cache_post_changet  s     	U#r   )r  r  Nr  r  r  rD   rE   )
r   r   r   r   r   r5   r  r  r  r   r   r   r   r  r  Z  s    DI%
$r   r  c                      \ rS rSrSr S     SS jjrSS jrSS jrSS jrSS jr	SS	 jr
SS
 jrSS jrSS jrSS jrSrg)FilteredCacheiz  zTA package cache that is filtered.

Can work on a existing cache or create a new one
Nc                l    Uc  [        U5      U l        OXl        [        U R                  5      U l        g r=   )rI   r  r  _helper)r4   r  rv   s      r   r5   FilteredCache.__init__  s)     =xDJJ+DJJ7r   c                @    [        U R                  R                  5      $ r=   )r   r  r  r}   s    r   r   FilteredCache.__len__  s    4<<))**r   c                     U R                   U   $ r=   r  r   s     r   r   FilteredCache.__getitem__  s    zz#r   c              #  h   #    U R                   R                   H  nU R                  U   v   M     g 7fr=   )r  r  r  )r4   r   s     r   r   FilteredCache.__iter__  s(     ||--G**W%% .s   02c                J    U R                   R                  R                  5       $ r=   )r  r  r   r}   s    r   r   FilteredCache.keys  s    ||%%**,,r   c                
    X;   $ r=   r   r   s     r   r   FilteredCache.has_key  r   r   c                     U R                   U   R                  U R                  R                  ;   $ ! [         a     gf = fr   )r  r   r  r  r   r   s     r   r   FilteredCache.__contains__  s<    	::c?''4<<+A+AAA 		s   /2 
??c                n    U R                   R                  U5        U R                  R                  5         gr  )r  r  r  rO   r  s     r   r  FilteredCache.set_filter  s$    '

$$&r   c                N    U R                   R                  U R                  5        gr  )r  r  r  r}   s    r   r  &FilteredCache.filter_cache_post_change  s    --djj9r   c                .    [        U R                  U5      $ )z)we try to look exactly like a real cache.)getattrr  r   s     r   __getattr__FilteredCache.__getattr__  s    tzz3''r   )r  r  )NN)r  zCache | Nonerv   r  rD   rE   r  )r   rC   rD   r	   r  )rD   zKeysView[str]r  r  rF   )r   rC   rD   r   )r   r   r   r   r   r5   r   r   r   r   r   r   r  r  r  r   r   r   r   r  r  z  sX     IM8!84E8	8+&-'
:(r   r  c                    [        S5        g )Nzcache pre changedprintr  s    r   cache_pre_changedr    s    	
r   c                    [        S5        g )Nzcache post changedr  r  s    r   cache_post_changedr    s    	
r   c                    [        S5        [        R                  " 5         [        [        R
                  R                  R                  5       5      n U R                  S[        5        U R                  S[        5        [        SU ;   5        U S   n[        UR                  5        [        [        U 5      5        U R                  5        H  nX   R                  U:X  a  M   e   U R                  5         U R                  5       n[        [        U5      5        U H  nUR                  (       a  M   e   S H?  n[         R"                  R%                  U5      (       a  M)  [         R&                  " U5        MA     [        R(                  R+                  SS5        [        R,                  " U R.                  5      n[        R0                  " [        R
                  R                  R3                  5       5      nU R5                  XeS5        [        S	5        [7        U 5      nUR8                  R                  S[        5        UR8                  R                  S[        5        UR8                  R                  5         UR;                  [=        5       5        [        [        U5      5        UR                  5        H  nX'U   R                  :X  a  M   e   [        [        U5      5        [        S
5        [7        [        R
                  R>                  R                  5       S9nUR8                  R                  S[        5        UR8                  R                  S[        5        UR8                  R                  5         UR;                  [=        5       5        [        [        U5      5        UR                  5        H  nX'U   R                  :X  a  M   e   [        [        U5      5        g)zInternal test code.zCache self testr   rO   aptitude)/tmp/pytestz/tmp/pytest/partialrX   r  Nz.Testing filtered cache (argument is old cache)z$Testing filtered cache (no argument))rv   ) r  r.   rg  rI   r   rv   r.  r   rv  r  r  r   r   r   r   r   r0   r1   rm   mkdirrj   rk   r   r[   r   r   r*  r  r  r  r  r   )r  r   r   r   r~  r   r   filtereds           r   _testr    s   	
LLN#,,##..01E	NN%'89	NN&(:;	*



C	#((O	#e*::<~""g---   
MMO!G	#g,xxxx  :ww~~g&&HHW : NN-}=				0Boocll//??ABG	't, 

:;U#HNN.0ABNN/1CDNN+-.	#h-==?7+00000 # 
#h-	
01cll&7&7&B&B&DEHNN.0ABNN/1CDNN+-.	#h-==?7+00000 # 
#h-r   __main__r  rF   )*
__future__r   r  r0   rq  rb   collections.abcr   r   r   typingr   r   r.   apt.progress.textr   apt.packager	   r
   apt.progress.baser   r   r   IOErrorr   r   r   r#   	Exceptionr&   r)   rI   r  r  r  r  r  r  r  r  r  r   r   r   r   <module>r     s   , #  	   8 8    ( J JLg L87 8I- I7' 7I9 I: :*~
) ~
)B&( &(X &  f  $ $@1( 1(h 5p z	G r   