
    \eË                       d dl mZ d dlZd dlZd dlZd dlZd dlmZmZm	Z	 d dl
mZmZ d dlZd dlZd dlmZmZ d dlmZmZmZ  G d de      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d d      Z G d d      Z G d d      Z  G d d      Z! G d de!      Z" G d de!      Z# G d d      Z$ G d d       Z%d%d!Z&d%d"Z'd&d#Z(e)d$k(  r e(        yy)'    )annotationsN)CallableIteratorKeysView)Anycast)PackageVersion)AcquireProgressInstallProgress
OpProgressc                      e Zd ZdZy)FetchCancelledExceptionzAException that is thrown when the user cancels a fetch operation.N__name__
__module____qualname____doc__     +/usr/lib/python3/dist-packages/apt/cache.pyr   r   &   s    Kr   r   c                      e Zd ZdZy)FetchFailedExceptionz-Exception that is thrown when fetching fails.Nr   r   r   r   r   r   *   s    7r   r   c                      e Zd ZdZy)UntrustedExceptionz>Exception that is thrown when fetching fails for trust reasonsNr   r   r   r   r   r   .       Hr   r   c                      e Zd ZdZy)LockFailedExceptionz,Exception that is thrown when locking fails.Nr   r   r   r   r   r   2   s    6r   r   c                      e Zd ZdZy)CacheClosedExceptionz>Exception that is thrown when the cache is used after close().Nr   r   r   r   r    r    6   r   r   r    c                  (    e Zd ZdZddZddZddZy)	_WrappedLockz`Wraps an apt_pkg.FileLock to raise LockFailedException.

    Initialized using a directory path.c                    || _         t        j                  t        j                  j                  |d            | _        y )Nlock)_pathapt_pkgFileLockospathjoin_lock)selfr)   s     r   __init__z_WrappedLock.__init__?   s*    
%%bggll4&@A
r   c                    	 | j                   j                         S # t        j                  $ r }t	        d| j
                  d|      d }~ww xY w)NzFailed to lock directory z: )r+   	__enter__r&   Errorr   r%   )r,   es     r   r/   z_WrappedLock.__enter__C   sG    	::''))}} 	%7;zz1E 	s    AA

Ac                <    | j                   j                  |||      S N)r+   __exit__)r,   typvalue	tracebacks       r   r4   z_WrappedLock.__exit__K   s    zz""3y99r   N)r)   strreturnNoner9   r:   )r5   objectr6   r<   r7   r<   r9   r:   )r   r   r   r   r-   r/   r4   r   r   r   r"   r"   :   s    +B:r   r"   c                  n   e Zd ZdZ	 	 	 d.	 	 	 	 	 	 	 d/dZd0dZd0dZd1dZd2dZd3d4dZ	d0d	Z
d0d
Zd5dZd6dZd7dZd3d8dZd9dZd:dZd;dZd<dZd<dZd=dZd>dZd?dZd@dAdZed=d       Zed=d       ZedBd       Z	 	 	 	 	 	 dCdZ	 d3	 	 	 	 	 	 	 dDdZ	 	 	 dE	 	 	 	 	 	 	 dFdZdGdZ 	 	 dH	 	 	 	 	 	 	 dIdZ!	 	 	 	 dJ	 	 	 	 	 	 	 	 	 dKd Z"	 	 	 	 	 	 dLd!Z#	 	 	 dE	 	 	 	 	 	 	 dMd"Z$d0d#Z%d0d$Z&d0d%Z'dNd&Z(	 	 	 	 	 	 	 	 	 	 dOd'Z)dPd(Z*edQd)       Z+ed=d*       Z,ed=d+       Z-ed=d,       Z.ed=d-       Z/y)RCachea  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           	     \   t        t        j                  d       | _        t        t        j                  d       | _        t        t        j                  d       | _        t        t        j                  d       | _	        i | _
        i | _        t        j                         | _        t        j                         | _        d| _        d | _        | j'                  dd       | j'                  dd       |r t        j(                  j+                  dd       |rYt,        j.                  j1                  |      }t,        j.                  j3                  |dz         r't        j4                  t        j(                  |dz          t,        j.                  j7                  |dz         r't        j8                  t        j(                  |dz          t        j(                  j+                  d	|       t        j(                  j+                  d
|dz          t        j(                  j+                  dt,        j.                  j;                  |ddd             | j=                  |       t        j>                          t        j(                  jA                  d      }tC        |      | _"        | jG                  |       y )Ncache_post_open_inc_changes_countcache_post_changezDir::Cache::pkgcache z/etc/apt/apt.confz/etc/apt/apt.conf.dDirDir::State::status/var/lib/dpkg/statuszDir::bin::dpkgusrbindpkgDir::Cache::Archives)$r   r&   r>   _cacheDepCache	_depcachePackageRecords_records
SourceList_list
_callbacks_callbacks2weakrefWeakValueDictionary_weakrefWeakSet_weakversions_changes_count_sorted_setconnectconfigsetr(   r)   abspathexistsread_config_fileisdirread_config_dirr*   _check_and_create_required_dirsinit_systemfind_dirr"   _archive_lockopen)r,   progressrootdirmemonlyarchive_dirs        r   r-   z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 NN "'',,wuf"M
 009 ! nn--.DE)+6		(r   c                8    | j                   j                          y)zFix broken packages.N)rN   
fix_brokenr,   s    r   rn   zCache.fix_broken   s    !!#r   c                .    | xj                   dz  c_         y)zIncrease the number of changes   N)rZ   ro   s    r   rB   zCache._inc_changes_count   s    q r   c                &   ddg}g d}|D ]=  }t         j                  j                  ||z         r&t        j                  ||z          ? |D ]B  }t         j                  j                  ||z         r&t	        ||z   d      j                          D y)zf
        check if the required apt directories/files are there and if
        not create them
        rG   z/etc/apt/sources.list)z/var/lib/dpkgz	/etc/apt/z/var/cache/apt/archives/partialz/var/lib/apt/lists/partialwN)r(   r)   r`   makedirsrh   close)r,   rj   filesdirsdfs         r   rd   z%Cache._check_and_create_required_dirs   s     ##

  	)A77>>'A+.GaK(	)  	/A77>>'A+.Wq[#&,,.	/r   c                    || j                   v r1| j                   |   D ]  }|dk(  r| j                           |        ! || j                  v r%| j                  |   D ]  \  }}} || g|i |  yy)z!internal helper to run a callbackrB   N)rS   rB   rT   r,   namecallbackargskwdss        r   _run_callbackszCache._run_callbacks   s    4??" OOD1 33++-J	 4###(,(8(8(> .$$---. $r   c                   |(t         j                  j                  j                         }| j	                          || _        | j                  d       t        j                  |      | _	        t        j                  | j                        | _        t        j                  | j                        | _        t        j                         | _        | j                  j!                          d| _        | j%                          t'        t        j(                               dkD  | _        |j-                          | j                  d       y)zTOpen the package cache, after that it can be used like
        a dictionary
        Ncache_pre_openrq   rA   )aptri   baser   ru   op_progressr   r&   r>   rL   rM   rN   rO   rP   rQ   rR   read_main_listr[   _Cache__remaplenget_architectures_have_multi_archdone)r,   ri   s     r   rh   z
Cache.open   s     ||((335H

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

!!# #G$=$=$? @1 D-.r   c                   t        | j                  j                               D ]Q  }	 | j                  |   }	 | j                  |j
                  j                  |j
                  j                  f   |_        S t        | j                        D ]  }|j                  j
                  j                  D ]  }|j                  |j                  j                  k(  s'|j                  dk(  s=|j                  j                  dk(  s$|j                  |j                  j                  k(  ss|j                  |j                  j                  k(  s|j                   |j                  j                   k(  s||_          | j                  j#                  |        y# t        $ r Y }w xY w# t        $ r | j                  |= Y w xY w)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)listrW   keysKeyErrorrL   _pkgr|   architectureLookupErrorrY   packageversion_listhash_candsize
multi_archver_strremove)r,   keypkgvervs        r   __remapzCache.__remap   s^    **,- 		'CmmC(';;sxx}}chh6K6K'KL		' **+ 	/C[[%%22 / FFciinn,1		!(;qvv?W		(<(<<		SYY%6%66 !CI/ ""))#.	/  
  'MM#&'s"   F>F%	F"!F"%F?>F?c                F    | ` t        t        j                  d      | _         y)zClose the package cacheN)rP   r   r&   rO   ro   s    r   ru   zCache.close  s     MW33T:r   c                    | S )zEnter the with statementr   ro   s    r   r/   zCache.__enter__	  s    r   c                $    | j                          y)zExit the with statementN)ru   )r,   exc_type	exc_valuer7   s       r   r4   zCache.__exit__  s    

r   c                    	 t        |      }| j                  |   }| j                  |      st        d|z        | j	                  |      }|S # t        $ r t        d|z        w xY w)z look like a dictionary (get key)z!The cache has no package named %r)r8   rL   r   _Cache__is_real_pkg_rawpkg_to_pkg)r,   r   rawpkgr   s       r   __getitem__zCache.__getitem__  sy    	Fc(C[[%F
 !!&)>DEE!!&)
  	F>DEE	Fs   A A&c                0    	 | |   S # t         $ r |cY S w xY w)zaReturn *self*[*key*] or *default* if *key* not in *self*.

        .. versionadded:: 1.1
        )r   )r,   r   defaults      r   getz	Cache.get!  s%    
	9 	N	s    c                r    |j                  d      }| j                  j                  |t        | |            S )zgReturns the apt.Package object for an apt_pkg.Package object.

        .. versionadded:: 1.0.0
        Tpretty)get_fullnamerW   
setdefaultr	   )r,   r   fullnames      r   r   zCache._rawpkg_to_pkg+  s5    
 &&d&3}}'''$2GHHr   c              #     K   | j                         D ]9  }t        | | j                  |         }| j                  j	                  ||       ; y wr3   )r   r	   rL   rW   r   r,   pkgnamer   s      r   __iter__zCache.__iter__4  sI      yy{ 	9G$G 45C--**7C88	9s   AAc                    |j                   S )z8Check if the apt_pkg.Package provided is a real package.)has_versions)r,   r   s     r   __is_real_pkgzCache.__is_real_pkg>  s    """r   c                
    || v S r3   r   r,   r   s     r   has_keyzCache.has_keyB      d{r   c                p    	 | j                  | j                  t        |               S # t        $ r Y yw xY wNF)r   rL   r8   r   r   s     r   __contains__zCache.__contains__E  s7    	%%dkk#c(&;<< 		s   &) 	55c                4    t        | j                               S r3   )r   r   ro   s    r   __len__zCache.__len__K  s    499;r   c                      j                   -t         fd j                  j                  D               _         t	         j                         S )Nc              3  d   K   | ]'  }j                  |      r|j                  d        ) yw)Tr   N)r   r   ).0pr,   s     r   	<genexpr>zCache.keys.<locals>.<genexpr>P  s2      &%%a( d+&s   -0)r[   sortedrL   packagesr   ro   s   `r   r   z
Cache.keysN  sF    #% &--&  D
 D$$%%r   c                    g }| j                   j                  }| j                  j                  D ]+  } ||      r|j	                  | j                  |             - |S )zGet the marked changes)rN   marked_keeprL   r   appendr   )r,   changesr   r   s       r   get_changeszCache.get_changesW  sU    nn00kk** 	<Fv&t226:;	< r   c                z    | j                          | j                  j                  |       | j                          y)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_changerN   upgraderC   )r,   dist_upgrades     r   r   zCache.upgrade`  s.     	|, r   c                    | j                   t        d      t        j                  | j                        }t        j
                         }|j                  || j                  | j                          |j                  S )z;Get the size of the packages that are required to download.&Cache object used after close() called)	rP   r    r&   PackageManagerrN   Acquireget_archivesrR   fetch_needed)r,   pmfetchers      r   required_downloadzCache.required_downloadk  s^     == &'OPP##DNN3//#
T]];###r   c                .    | j                   j                  S )z8Get the size of the additional required space on the fs.)rN   usr_sizero   s    r   required_spacezCache.required_spaceu  s     ~~&&&r   c                ^   t               }| j                  j                  }t        t        j
                  t        j                  f      }| j                  j                  D ]J  } ||      }|s|j                  r|j                  |v s*|j                  |j                  d             L |S )zAReturn the packages not downloadable packages in reqreinst state.Tr   )r^   rN   get_candidate_ver	frozensetr&   INSTSTATE_REINSTREQINSTSTATE_HOLD_REINSTREQrL   r   downloadable
inst_stateaddr   )r,   	reqreinstr   statesr   cands         r   req_reinstall_pkgszCache.req_reinstall_pkgsz  s     E	 NN<<(('*J*JK
 ;;'' 	=C$S)DD--#..F2Jc..d.;<	= r   c                   | t         j                  j                  dd      }|j                  D cg c]  }|j                  r| }}|r&|s$t        ddj                  d |D              z        |j                         }d}d}|j                  D ]K  }|j                  |j                  k(  r|j                  r*|d|j                   d|j                   dz  }d	}M ||j                  k(  rt        |      |rt        |      |S c c}w )
NzAPT::Get::AllowUnauthenticatedFzUntrusted packages:
%s
c              3  4   K   | ]  }|j                     y wr3   )desc_uri)r   is     r   r   z%Cache._run_fetcher.<locals>.<genexpr>  s     5TQajj5Ts   rD   zFailed to fetch  T)r&   r]   find_bitems
is_trustedr   r*   runstatus	STAT_DONE	STAT_IDLEr   
error_textRESULT_CANCELLEDr   r   )r,   r   allow_unauthenticateditem	untrustedresfailederr_msgs           r   _run_fetcherzCache._run_fetcher  s    !($+NN$9$93U%! '.mmKd4??TK	K2$)DII5T)5T,TT 
 kkm MM 	D{{dnn,~~)$--$//9J"MMGF	 '***)'22&w//
3 Ls   DDc                    | j                   t        d      |j                  || j                  | j                         sy| j	                  ||      S )zfetch the needed archivesr   F)rP   r    r   rR   r   )r,   r   r   r   s       r   _fetch_archiveszCache._fetch_archives  sM     == &'OPP w

DMMB   *?@@r   c                F   ||t        d      |(t        j                  j                  j	                         }|t        j                  |      }| j                  5  | j                  |t        j                  | j                        |      cddd       S # 1 sw Y   yxY w)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   ri   textr   r&   r   rg   r  r   rN   )r,   ri   r   r   s       r   fetch_archiveszCache.fetch_archives  s    , G$7FGG||((88:H?ooh/G 	''//?AV	 	 	s   0BB c                    	 | j                   |   }t        |j                  xr |j                         S # t        $ r Y yw xY w)z0Return whether the package is a virtual package.F)rL   boolhas_providesr   r   r   s      r   is_virtual_packagezCache.is_virtual_package  sK    	C++g&C ((A1A1A-ABB  		s   5 	A Ac                |   t               }| j                  j                  }	 | j                  |   }|j                  r|st        |      S |j                  D ]@  \  }}}	|	j                  }
|r|	 ||
      k(  s!|j                  | j                  |
             B t        |      S # t        $ r t        |      cY S w xY w)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.
        )r^   rN   r   rL   r   r   r   provides_list
parent_pkgr   r   )r,   r   candidate_onlyinclude_nonvirtual	providersr   vpprovidesprovidesverversionr   s              r   get_providing_packageszCache.get_providing_packages  s    * #&%	 NN<<	#W%B'9I& /1.>.> 	;*Hk7''F!g1B61J&Jd11&9:	; I  	#	?"	#s   'B$ $B;:B;c                   t        t        j                  j                  d            5  |rt        j                  j	                  d      }t        j                  j	                  d      }t        j                  j	                  d      }t        j                  j                  dt        j                  j                  |             t        j                  j                  dd       t        j                  j                  dd       t        j                         }|j                          n| j                  }	 |(t        j                  j                  j                         }	 | j                   j#                  |||      }	|	s|r
t'               |	|r`t        j                  j                  d       t        j                  j                  d       t        j                  j                  d       cddd       S # t$        $ r}
t'        |
      d}
~
ww xY w# |rat        j                  j                  d       t        j                  j                  d       t        j                  j                  d       w w xY w# 1 sw Y   yxY w)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&   r]   rf   findr^   r(   r)   r_   rQ   r   rR   r   ri   r   r   rL   updateSystemErrorr   )r,   fetch_progresspulse_intervalraise_on_errorsources_listold_sources_listold_sources_list_dold_cleanupslistr   r1   s              r   r  zCache.update  s   & '..112EFG 	I#*>>#6#67M#N %,^^%8%89P%Q"%nn112EF""*BGGOOL,I ""#:EB""#6<**,$$&

I!)%(\\%6%6%F%F%HN2++,,^UNSC ~.00NN&&'=?OPNN&&'>@RSNN&&':KH=	I 	I( # 2.q112  NN&&'=?OPNN&&'>@RSNN&&':KH  7	I 	IsJ   DI?8*H#G; HA"I?;	HHHHA%I<<I??Jc                   	 |j                          t        j                         }|rt        j
                          	 |j                  |      }|rt        j                          	 	 |j                          |S # t        $ r |j                          Y w xY w# |rt        j                          w w xY w# t        $ r |j                          Y |S w xY w)aY  
        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)r,   r   install_progress
did_unlockr   s        r   install_archiveszCache.install_archives?  s    	,((* 002
**,	/"&&r*C,,.	-))+ 
#  	,))+	, ,,. 
  	-**,
	-s.   A8 B &B3 8BBB03CCc                   |(t         j                  j                  j                         }|(t         j                  j                  j	                         }|J t        j                         5  t        j                  | j                        }t        j                  |      }| j                  5  	 | j                  |||      }| j                  ||      }||j                  k(  rnI||j                  k(  rt        d      ||j                   k(  rnt        d|z        |j#                          ~	 ddd       ddd       j                  k(  S # 1 sw Y    xY w# 1 sw Y   $xY w)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   ri   r   r   r   r&   
SystemLockr   rN   r   rg   r  r/  RESULT_COMPLETEDRESULT_FAILEDr  RESULT_INCOMPLETEshutdown)r,   r  r-  r   r   r   r   s          r   commitzCache.commitb  s]   4 ! \\..>>@N#"||00@@B+++! 	'''7Boon5G## '..w<QRC //4DECb111 0 00)*DEE 4 44)<>AB 
 $$&%  '	'. b)))))' '	' 	's&   -AE.B E/EE	EE#c                8    | j                   j                          y)zUnmark all changesN)rN   initro   s    r   clearzCache.clear  s    r   c                &    | j                  d       y)z>called internally if the cache has changed, emit a signal thenrC   Nr   ro   s    r   rC   zCache.cache_post_change  s    /0r   c                &    | j                  d       y)zMcalled internally if the cache is about to change, emit
        a signal thenr   Nr;  ro   s    r   r   zCache.cache_pre_change  s     	./r   c                    |dk7  rt        j                  dt        d       || j                  vrg | j                  |<   | j                  |   j	                  |       y)zConnect to a signal.

        .. deprecated:: 1.0

            Please use connect2() instead, as this function is very
            likely to cause a memory leak.
        rB   zAconnect() likely causes a reference cycle, use connect2() instead   N)warningswarnRuntimeWarningrS   r   )r,   r|   r}   s      r   r\   zCache.connect  sU     ++MMV
 t&$&DOOD!$$X.r   c                    || j                   vrg | j                   |<   | j                   |   j                  |||f       y)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)rT   r   r{   s        r   connect2zCache.connect2  sB    $ t'''%'DT"%%xt&<=r   c                @    t        j                  | j                        S )a  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&   ActionGrouprN   ro   s    r   actiongroupzCache.actiongroup  s    & ""4>>22r   c                   t         j                  j                  t        j                  j                  d            }t        j                  t         j                  j                  |d            D ]  }t        j                  |d      s y y)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.
        rF   updatesz[0-9]*TF)	r(   r)   dirnamer&   r]   	find_filelistdirr*   fnmatch)r,   dpkg_status_dirry   s      r   dpkg_journal_dirtyzCache.dpkg_journal_dirty  sh     ''//NN$$%9:
 BGGLL)DE 	Aq(+	 r   c                .    | j                   j                  S )z7Return the number of packages with broken dependencies.)rN   broken_countro   s    r   rP  zCache.broken_count  s     ~~***r   c                .    | j                   j                  S )z2Return the number of packages marked for deletion.)rN   	del_countro   s    r   delete_countzCache.delete_count  s     ~~'''r   c                .    | j                   j                  S )z6Return the number of packages marked for installation.)rN   
inst_countro   s    r   install_countzCache.install_count       ~~(((r   c                .    | j                   j                  S )z-Return the number of packages marked as keep.)rN   
keep_countro   s    r   rY  zCache.keep_count  rW  r   )NNF)ri   OpProgress | Nonerj   
str | Nonerk   r  r9   r:   r;   )rj   r8   r9   r:   )r|   r8   r9   r:   r3   )ri   rZ  r9   r:   )r9   r>   )r   r<   r   r<   r7   r<   r9   r:   )r   r<   r9   r	   )r   r<   r   r<   r9   r   )r   apt_pkg.Packager9   r	   r9   zIterator[Package])r   r\  r9   r  r   r<   r9   r  r9   int)r9   z	list[str])r9   list[Package])F)r   r  r9   r:   )r9   zset[str])r   apt_pkg.Acquirer   bool | Noner9   r`  )r   rb  r   apt_pkg.PackageManagerr   rc  r9   r`  )NNN)ri   AcquireProgress | Noner   zapt_pkg.Acquire | Noner   rc  r9   r`  )r   r8   r9   r  )TF)r   r8   r  r  r  r  r9   ra  )Nr   TN)
r  re  r  r`  r  r  r  r[  r9   r`  )r   rd  r-  r   r9   r`  )r  re  r-  zInstallProgress | Noner   rc  r9   r  )r|   r8   r}   zCallable[..., None] | strr9   r:   )
r|   r8   r}   zCallable[..., Any]r~   r<   r   r<   r9   r:   )r9   zapt_pkg.ActionGroup)r9   r  )0r   r   r   r   r-   rn   rB   rd   r   rh   r   ru   r/   r4   r   r   r   r   r   r   r   r   r   r   r   propertyr   r   r   r   r  r  r
  r  r  r/  r6  r9  rC   r   r\   rC  rF  rN  rP  rS  rV  rY  r   r   r   r>   r>   O   s   6 '+"	4#4 4 	4
 
4l$!/../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   r>   c                  H    e Zd ZdZd
dZddZddZddZddZddZ	ddZ
y	)ProblemResolverzuResolve problems due to dependencies and conflicts.

    The first argument 'cache' is an instance of apt.Cache.
    c                Z    t        j                  |j                        | _        || _        y r3   )r&   rh  rN   	_resolverrL   r,   caches     r   r-   zProblemResolver.__init__  s     00Ar   c                N    | j                   j                  |j                         y)z'Reset the package to the default state.N)rj  r9  r   r,   r   s     r   r9  zProblemResolver.clear  s    W\\*r   c                N    | j                   j                  |j                         y)z)Protect a package so it won't be removed.N)rj  protectr   rn  s     r   rp  zProblemResolver.protect  s    w||,r   c                N    | j                   j                  |j                         y)zMark a package for removal.N)rj  r   r   rn  s     r   r   zProblemResolver.remove  s    gll+r   c                    | j                   j                          | j                  j                          | j                   j	                          y)z:Resolve dependencies, try to remove packages where needed.N)rL   r   rj  resolverC   ro   s    r   rs  zProblemResolver.resolve#  s2    $$& %%'r   c                    | j                   j                          | j                  j                          | j                   j	                          y)z4Resolve dependencies, do not try to remove packages.N)rL   r   rj  resolve_by_keeprC   ro   s    r   ru  zProblemResolver.resolve_by_keep)  s2    $$&&&(%%'r   c                    | j                   j                          | j                  j                          | j                   j	                          y)zKeep back phased updates.N)rL   r   rj  keep_phased_updatesrC   ro   s    r   rw  z#ProblemResolver.keep_phased_updates/  s2    $$&**,%%'r   Nrl  r>   r9   r:   )r   r	   r9   r:   r;   )r   r   r   r   r-   r9  rp  r   rs  ru  rw  r   r   r   rh  rh    s*    
+-,(((r   rh  c                      e Zd ZdZddZy)FilterzFilter base classc                     y)ziFilter function, return True if the package matchs a
        filter criteria and False otherwise
        Tr   r,   r   s     r   applyzFilter.apply<  s     r   Nr   r	   r9   r  r   r   r   r   r}  r   r   r   rz  rz  9  s
    r   rz  c                      e Zd ZdZddZy)MarkedChangesFilterz&Filter that returns all marked changesc                N    |j                   s|j                  s|j                  ryy)NTF)marked_installmarked_deletemarked_upgrader|  s     r   r}  zMarkedChangesFilter.applyF  s!    !2!2c6H6Hr   Nr~  r  r   r   r   r  r  C  s
    0r   r  c                      e Zd ZdZddZy)InstalledFilterzMFilter that returns all installed packages.

    .. versionadded:: 1.0.0
    c                    |j                   S r3   )is_installedr|  s     r   r}  zInstalledFilter.applyS  s    r   Nr~  r  r   r   r   r  r  M  s    
 r   r  c                  0    e Zd ZdZddZddZddZddZy)	_FilteredCacheHelperz:Helper class for FilteredCache to break a reference cycle.c                    i | _         g | _        |j                  d| j                         |j                  d| j                         y )NrC   rA   )	_filtered_filtersrC  filter_cache_post_changerk  s     r   r-   z_FilteredCacheHelper.__init__Z  s<     +-&(*D,I,IJ($*G*GHr   c                    i | _         |D ]?  }| j                  D ].  }|j                  |      sd| j                   |j                  <    ? A y)zinternal helper to refilterTN)r  r  r}  r|   )r,   rl  r   ry   s       r   _reapply_filterz$_FilteredCacheHelper._reapply_filterb  sM      	C]] 773</3DNN388,	r   c                H    g | _         | j                   j                  |       yzSet the current active filter.N)r  r   r,   filters     r   
set_filterz_FilteredCacheHelper.set_filterl  s    V$r   c                &    | j                  |       yz;Called internally if the cache changes, emit a signal then.N)r  rk  s     r   r  z-_FilteredCacheHelper.filter_cache_post_changeq  s     	U#r   Nrx  r  rz  r9   r:   )r   r   r   r   r-   r  r  r  r   r   r   r  r  W  s    DI%
$r   r  c                  n    e Zd ZdZ	 d	 	 	 	 	 ddZddZddZddZddZddZ	dd	Z
dd
ZddZddZy)FilteredCachez\A package cache that is filtered.

    Can work on a existing cache or create a new one
    Nc                l    |t        |      | _        n|| _        t        | j                        | _        y r3   )r>   rl  r  _helper)r,   rl  ri   s      r   r-   zFilteredCache.__init__}  s+     =xDJDJ+DJJ7r   c                @    t        | j                  j                        S r3   )r   r  r  ro   s    r   r   zFilteredCache.__len__  s    4<<))**r   c                     | j                   |   S r3   rl  r   s     r   r   zFilteredCache.__getitem__  s    zz#r   c              #  d   K   | j                   j                  D ]  }| j                  |     y wr3   )r  r  rl  )r,   r   s     r   r   zFilteredCache.__iter__  s.     ||-- 	&G**W%%	&s   .0c                J    | j                   j                  j                         S r3   )r  r  r   ro   s    r   r   zFilteredCache.keys  s    ||%%**,,r   c                
    || v S r3   r   r   s     r   r   zFilteredCache.has_key  r   r   c                    	 | j                   |   j                  | j                  j                  v S # t        $ r Y yw xY wr   )rl  r|   r  r  r   r   s     r   r   zFilteredCache.__contains__  s<    	::c?''4<<+A+AAA 		s   .1 	==c                n    | j                   j                  |       | j                  j                          yr  )r  r  rl  rC   r  s     r   r  zFilteredCache.set_filter  s$    '

$$&r   c                N    | j                   j                  | j                         yr  )r  r  rl  ro   s    r   r  z&FilteredCache.filter_cache_post_change  s    --djj9r   c                .    t        | j                  |      S )z)we try to look exactly like a real cache.)getattrrl  r   s     r   __getattr__zFilteredCache.__getattr__  s    tzz3''r   )NN)rl  zCache | Noneri   rZ  r9   r:   r_  )r   r8   r9   r	   r]  )r9   zKeysView[str]r^  r  r;   )r   r8   r9   r   )r   r   r   r   r-   r   r   r   r   r   r   r  r  r  r   r   r   r  r  w  sX     IM8!84E8	8+&-'
:(r   r  c                    t        d       y )Nzcache pre changedprintr  s    r   cache_pre_changedr    s    	
r   c                    t        d       y )Nzcache post changedr  r  s    r   cache_post_changedr    s    	
r   c                    t        d       t        j                          t        t        j
                  j                  j                               } | j                  dt               | j                  dt               t        d| v        | d   }t        |j                         t        t        |              | j                         D ]  }| |   j                  |k(  rJ  | j                          | j                         }t        t        |             |D ]  }|j                  rJ  dD ]7  }t         j"                  j%                  |      r#t!        j&                  |       9 t        j(                  j+                  dd       t        j,                  | j.                        }t        j0                  t        j
                  j                  j3                               }| j5                  ||d       t        d	       t7        |       }|j8                  j                  dt               |j8                  j                  dt               |j8                  j                          |j;                  t=                      t        t        |             |j                         D ]  }|||   j                  k(  rJ  t        t        |             t        d
       t7        t        j
                  j>                  j                               }|j8                  j                  dt               |j8                  j                  dt               |j8                  j                          |j;                  t=                      t        t        |             |j                         D ]  }|||   j                  k(  rJ  t        t        |             y)zInternal test code.zCache self testr   rC   aptitude)/tmp/pytestz/tmp/pytest/partialrK   r  Nz.Testing filtered cache (argument is old cache)z$Testing filtered cache (no argument))ri   ) r  r&   r8  r>   r   ri   r  r   rC  r  r  r|   r   r   r   r   r(   r)   r`   mkdirr]   r^   r   rN   r   r   r  r  rl  r  r  r   )rl  r   r   r   rI  r   r   filtereds           r   _testr    s   	
LLN#,,##..01E	NN%'89	NN&(:;	*



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

:;U#HNN.0ABNN/1CDNN+-.	#h-==? 1(7+000001 
#h-	
01cll&7&7&B&B&DEHNN.0ABNN/1CDNN+-.	#h-==? 1(7+000001 
#h-r   __main__rx  r;   )*
__future__r   rL  r(   r?  rU   collections.abcr   r   r   typingr   r   r&   apt.progress.textr   apt.packager	   r
   apt.progress.baser   r   r   IOErrorr   r   r   r   	Exceptionr    r"   r>   rh  rz  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: :*{
) {
)|&( &(X &  f  $ $@1( 1(h 5p z	G r   