
    kdk                       d Z dZdZddlZddlmZ ddlZddlmZ ddl	Z	ddl
Z
ddlZ
ddlmZ ddlZddlZddlZddlZddlZddlZddlmZmZ ddlZddlZddlZd	d
lmZ d	dlmZ d	dlmZ ddl m!Z!m"Z"m#Z# ddl$m%Z% d	dlm&Z& d	dl'm(Z(m)Z) d	dl*m+Z+ d	dl,m-Z-m.Z. d	dl/m0Z0 d	dl1m2Z2 d Z3ejh                  dk\  rdZ5dZ6ndZ5dZ6dZ7dZ8dZ9dZ:dZ;dZ<d Z=d!Z>d"Z?d#Z@d$ZAej`                  j                  j                  d%&        ej                  d'd(        e
j                  d)      ZF	 e
j                  j                  d*e
j                  j                  j                  +      ZJeJj                  e
j                          e
j                  d,      ZNeJj                  eN       eFj                  eJ        e
j                         ZR e2d-d.      ZSeRj                  eS       eFj                  eR        e
j                  d/      ZT	  e	j                  e	j                  d0       d2 ZYej                  j                  d3k(  rej                  Z\d4 e_Z         G d5 d6ej                  j                        Z_ G d7 d8e_      Z` G d9 d:ej*                        Za G d; d)e_      Zbd>d<Zcd= Zdy#  Y xY w# e	j                  $ r eFj                  d1       Y w xY w)?aN  
Core components of aptdaemon.

This module provides the following core classes of the aptdaemon:
AptDaemon - complete daemon for managing software via DBus interface
Transaction - represents a software management operation
TransactionQueue - queue for aptdaemon transactions

The main function allows to run the daemon as a command.
z%Sebastian Heinlein <devel@glatzor.de>)
TransactionTransactionQueue	AptDaemon$APTDAEMON_TRANSACTION_DBUS_INTERFACE+APTDAEMON_DBUS_INTERFACEAPTDAEMON_DBUS_PATHAPTDAEMON_DBUS_SERVICEAPTDAEMON_IDLE_CHECK_INTERVALAPTDAEMON_IDLE_TIMEOUTTRANSACTION_IDLE_TIMEOUTTRANSACTION_DEL_TIMEOUT    N)ElementTree)md5)OptionParser)GObjectGLib   )ConfigWriter)errors)enums)inline_callbacksreturn_valueDeferred)dbus_deferred_method)
policykit1)split_package_idset_euid_egid)DummyWorker)	AptWorker.trans_only_installs_pkgs_from_high_trust_repos)mainloop)ColoredFormatterc                 .    t        j                  d|       S )N	aptdaemon)gettextdgettext)msgs    0/usr/lib/python3/dist-packages/aptdaemon/core.py<lambda>r(   G   s      c2     3r$   ngettextugettext	ungettextzorg.debian.aptz/org/debian/aptzorg.debian.apt.transaction<   iX  ,     z$^[a-z0-9][a-z0-9\-+.]+(:[a-z0-9]+)?$z^[0-9][0-9.+\-A-Za-z:~]*$z^[a-zA-Z0-9_\-\.]+$T)set_as_defaultPATHz</usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binr   z/dev/log)addressfacilityz$%(name)s: %(levelname)s: %(message)sz1%(asctime)s %(name)s [%(levelname)s]: %(message)sz%TzAptDaemon.Trans z7Failed to unset LC_ALL. Translations are not available.c                 |    t        | t        j                        rt        j                  | ||       y || ||       y)zHandle exceptions of aptdaemon and avoid tiggering apport crash
    reports for valid DBusExceptions that are sent to the client.
    N)
issubclassr   AptDaemonErrorsys__excepthook__)exc_typeexc_objexc_tbapport_excepthooks       r'   _excepthookr?      s2     (F1128Wf5(GV4r)   r>   c                 &    t        | ||t              S N)r?   r>   )etypeeobjetbs      r'   r(   r(      s    k%s:K/M r)   c                      e Zd ZdZdZej                  j                  ej                  d      d        Z	ej                  j                  ej                  dddd	
      d        Z eej                  ddd      d        Zej                  j                  ej                  dd      d        Zej                  j                  ej                  dd      d        Zd Zd Zy)
DBusObjectz6Enhanced D-Bus object class which supports properties. zsa{sv}asdbus_interface	signaturec                 @    t         j                  d|d|d|       y)a  The signal gets emitted if a property of the object's
        interfaces changed.

        :param property: The name of the interface.
        :param changed_properties: A dictrionary of changed
            property/value pairs
        :param invalidated_properties: An array of property names which
            changed but the value isn't conveyed.

        :type interface: s
        :type changed_properties: a{sv}
        :type invalidated_properties: as
        zEmitting PropertiesChanged: , Nlogdebug)self	interfacechanged_propertiesinvalidated_propertiess       r'   PropertiesChangedzDBusObject.PropertiesChanged   s     " 			02HJ 	Kr)   r5   sobject_path
connection)in_signatureout_signaturepath_keywordconnection_keywordc           	         t         j                  j                  j                  | ||      }t	        j
                  |      }|j                  d      D ]  }| j                  |j                  d         }|j                         D ]  \  }}d|i}	|| j                  v rd|	d<   nd|	d<   t        |t         j                        rd|	d<   nDt        |t         j                        rd|	d<   n#t        |t         j                        rd	|	d<   nt        |t         j                        rd
|	d<   nt        |t         j                         rd|	d<   nt        |t         j"                        rd|	d<   nt        |t         j$                        rd|j&                  z  |	d<   nut        |t         j(                        rd|j&                  z  |	d<   nHt        |t         j*                        rd|j&                  z  |	d<   nt-        dt/        |      d|d      |j1                  t	        j2                  d|	               t	        j4                  |d      }
|
S )NrQ   name	readwriteaccessreadrU   typeuitxbz(%s)za{%s}za%szType z of property z isn't convertablepropertyUTF-8)encoding)dbusserviceObject
Introspectr   
fromstringfindall_get_propertiesattribitemsWRITABLE_PROPERTIES
isinstanceStringUInt32Int32UInt64Int64BooleanStructrJ   
DictionaryArray	Exceptionra   appendElementtostring)rP   rV   rW   dataxmlifacepropskeyvaluerq   new_datas              r'   rm   zDBusObject.Introspect   s    ||""--dKL$$T*[[- 	FE((f)=>E#kkm F
U #$222'2F8$'-F8$eT[[1%(F6Nt{{3%(F6Ntzz2%(F6Nt{{3%(F6Ntzz2%(F6Nt||4%(F6Nt{{3%+eoo%=F6Nt7%,u%>F6Ntzz2%*U__%<F6N#59%[#%G H H[00VDE7F	F< ''g>r)   ssvsenderrX   rY   sender_keywordc                 `    t         j                  d|d|       | j                  ||||      S )ar  Set a property.

        Only the user who intiaited the transaction is
        allowed to modify it.

        :param iface: The interface which provides the property.
        :param name: The name of the property which should be modified.
        :param value: The new value of the property.

        :type iface: s
        :type name: s
        :type value: v
        zSet() was called: rL   )rN   rO   _set_propertyrP   r   r]   r   r   s        r'   SetzDBusObject.Set   s,    " 			e<=!!%uf==r)   za{sv}rX   rY   c                 T    t         j                  d|z         | j                  |      S )z4Get all available properties of the given interface.zGetAll() was called: %srN   rO   rp   rP   r   s     r'   GetAllzDBusObject.GetAll   s'     			+e34##E**r)   ssvc                 `    t         j                  d|d|       | j                  |      |   S )zXReturn the value of the given property provided by the given
        interface.
        zGet() was called: rL   r   )rP   r   rg   s      r'   GetzDBusObject.Get  s+     			x@A##E*844r)   c                 F    t         j                  j                  d|z        );Helper to set a property on the properties D-Bus interface.!Unknown or read only property: %s)rj   
exceptionsDBusExceptionr   s        r'   r   zDBusObject._set_property
  s)    oo++ -;=A-B C 	Cr)   c                     i S )2Helper to get the properties of a D-Bus interface.rG   r   s     r'   rp   zDBusObject._get_properties  s    	r)   N)__name__
__module____qualname____doc__rs   rj   rk   signalPROPERTIES_IFACErT   methodINTROSPECTABLE_IFACErm   r   r   r   r   r   rp   rG   r)   r'   rF   rF      s   @ 
\\(=(=#-  /K/K& 
\\22&(&3,8  :#	:#L $//',B)13>3>$ 
\\..&)  B+B+ 
\\..&*#  ?5?5C
r)   rF   c                   	   e Zd ZdZi ej
                  dej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                   ej"                  ej                  ej$                  ej&                  ej(                  ej&                  ej*                  ej&                  ej,                  ej                  ej.                  ej                  ej0                  ej&                  ej2                  ej                  ej4                  ej6                  ej8                  ej&                  ej:                  ej                  iZdZ	 dmdZ d Z!d Z"d Z#d Z$d	 Z% e&e%e$d
      Z'd Z(d Z) e&e)e(d      Z*d Z+d Z, e&e,e+d      Z-d Z.d Z/ e&e/e.d      Z0d Z1d Z2 e&e2e1d      Z3d Z4d Z5 e&e4e5d      Z6d Z7d Z8 e&e7e8d      Z9d Z:d Z; e&e;e:d       Z<d! Z=d" Z> e&e=e>d#      Z?d$ Z@d% ZA e&e@eAd&      ZBd' ZCd( ZD e&eCeDd)      ZEd* ZFd+ ZG e&eFeGd,      ZHd- ZId. ZJ e&eIeJd/      ZKd0 ZLd1 ZM e&eLeMd2      ZNd3 ZOd4 ZP e&eOePd5      ZQd6 ZRd7 ZS e&eReSd8      ZTd9 ZUd: ZV e&eUeVd;      ZWd< ZXd= ZY e&eXeYd>      ZZd? Z[d@ Z\ e&e[e\dA      Z]dB Z^dC Z_ e&e^e_dD      Z`eaj                  j                  eddEF      dG        Zeeaj                  j                  eddHF      dI        Zfeaj                  j                  eddJF      dK        Zgeaj                  j                  eddJF      dL        ZhdM ZiejdN        ZkdO ZldP Zmeaj                  j                  eddHdQdRS      dT        Zo epeddQdQdRS      dU        ZqejdV        ZrejdW        ZsejdX        ZtejdY        Zu epeddQdQdRS      dZ        Zvejd[        Zw epeddQdQdRS      d\        Zxejd]        Zyejd^        Zzd_ Z{d` Z|da Z} epeddHdQdRS      db        Z~ejdc        Z epeddJdQdRS      dd        Zejde        Zejdf        Zdg Zejdh        Zdi Zdj Zdk Zdl Zy)nr   a  Represents a transaction on the D-Bus.

    A transaction represents a single package management task, e.g.
    installation or removal of packages. This class allows to expose
    information and to controll the transaction via DBus using PolicyKit
    for managing privileges.
    N)	HttpProxyTerminalAllowUnauthenticatedDebconfSocketMetaDataLocaleRemoveObsoleteDependsc           	      
   |t        j                         j                  }d|z  | _        |	du r]|
| _        |
t        j                         | _        t
        j                  j                  t        | j                        }| j                  }nd}
d}d}t        j                  | ||       |sg g g g g g f}|si }|| _        || _        || _        t        j                  d      | _        t        j"                  d      | _        t        j"                  d      | _        || _        || _        t        j                  d      | _        t        j                  d      | _        d| j                  z  }t0        j2                  j5                  |      rt        j                  |      | _        nt        j                  d      | _        || _        d| _        d| _        t        j                  |      | _        t        j@                  d      | _!        t        jD                  dd	
      | _#        t        jD                  dd
      | _$        t        jD                  dd
      | _%        t        j                  tL        jN                        | _(        t        j                  tL        jR                        | _*        t        j                  d      | _+        d| _,        t        jD                  dd
      | _-        t        j"                  d      | _.        t        j"                  d      | _/        t        jD                  dd
      | _0        t        jD                  dd
      | _1        d| _2        t        j"                  d      | _3        t        j"                  d      | _4        t        jj                  d
      | _6        t        jn                  d      | _8        t        jn                  d      | _9        t        jD                  tu        d      D cg c]  }t        jv                  g d
       c}d
      | _<        t        jD                  |D cg c]  }t        jv                  |d
       c}d
      | _=        t        jv                  g t        j|                  d      
      | _?        t        jv                  g t        j|                  d      
      | _@        t        j                  t        | j                        | _E        d| _F        |
r"|
j                  || j                        | _I        nd| _I        || _J        d| _K        d| _L        d| _M        yc c}w c c}w )a  Initialize a new Transaction instance.

        Keyword arguments:
        tid -- The unique identifier
        role -- The role enum of the transaction
        queue -- TransactionQueue instance of the daemon
        pid -- the id of the process which created the transaction
        uid -- the uid of the user who created the transaction
        cmdline -- the cmdline of the calling process
        sender -- the DBus name of the sender who created the transaction
        connect -- if the Transaction should connect to DBus (default is True)
        bus -- the DBus connection which should be used
            (defaults to system bus)
        Nz/org/debian/apt/transaction/%sTr5   Fz/run/user/%d/pk-debconf-socketr   )r   r   r   r   g        r   iixxdxrJ   )r5   r5   r5   r   r   r5   sssxxsr5   r5   r   sv   rU   asasasasasasasasasasasasas)Nuuiduuid4hextidbusrj   	SystemBusrk   BusNamer   rF   __init__queueuidgidru   localerz   allow_unauthenticatedremove_obsoleted_dependscmdlinepid
http_proxyterminalospathexistsdebconfkwargs_translationafter_rolerw   	_progressr{   _progress_details_progress_download_progress_packager   EXIT_UNFINISHED_exitSTATUS_SETTING_UP_status_status_details_error_error_property_cancellable_term_attached_required_medium_config_file_conflict _config_file_conflict_resolution	cancelledpausedr|   
_meta_datary   	_download_spaceranger}   _depends	_packages	Signature_unauthenticated_high_trust_packagesr   timeout_add_secondsr
    _remove_from_connection_no_raise_idle_watchsender_alivewatch_name_owner_sender_owner_changed_sender_watchr   output	simulated_simulated_cb)rP   r   roler   r   r   r   r   r   connectr   packagesr   bus_name	dbus_path	pk_socketrc   pkgss                     r'   r   zTransaction.__init__G  s     ;**,""C3c9d?DH{>>+||++,BDHHMHICHID(I6BBB/HF
kk"o%)\\%%8"(,U(;%++b/B4txx?	77>>)$;;y1DL;;r?DL 
[[&
A!%-A7?"A"&++.D8@#B!%X!F[[!6!67
{{5#:#:;#{{2#{{8tD LL."ll51 $H E%)[[T%J"02-e,ll5)//D9Ajjm.3Ah%8)* &*ZZc%B %8.>@ 2:&<*. '+jj&E &</=? !%

29L M$(JJr9=9L%N!  33$d&K&KM !!$!5!522"4D "&D!/%8&<s   ;T<:Uc                     |sd| _         yy)zPCallback if the owner of the original sender changed, e.g.
        disconnected.FN)r   )rP   rW   s     r'   r   z!Transaction._sender_owner_changed  s      %D r)   c                 *   t         j                  d       	 | j                          	 | j                  j
                  j                  | j                         y# t        $ r"}t         j                  d|z         Y d}~Wd}~ww xY w# t        $ r Y yw xY w)zdVersion of remove_from_connection that does not raise if the
        object isn't exported.
        zRemoving transactionz1remove_from_connection() raised LookupError: '%s'NF)		log_transrO   remove_from_connectionLookupErrorr   limbopopr   KeyError)rP   errors     r'   r   z,Transaction._remove_from_connection_no_raise  s     	./	,'')
	JJ  *   	,OO #%*+ , ,	,  		s(   A /B 	B!A>>B	BBc                 $   g }t        |      D ]  \  }}	 ||   dk(  r%|j                  t        j                  |             n||   dk(  r%|j                  t        j                  |             n||   dk(  r%|j                  t        j
                  |             n||   dk(  r%|j                  t        j                  |             nd||   dk(  r%|j                  t        j                  |             n7||   dk(  r|j                  t        |             nt        d|d||         " t        j                  |t        j                  |            S # t        $ r+}|j                  d	|d
|d|dt        |            d}~ww xY w)zConvert a list to a DBus struct with the given signature. Currently
        integer, long, unsigned long, double, string and boolean are
        supported (ixtdsb).
        rc   re   rd   drf   rU   zValue z with unknown signature zFailed to convert item z of z with signature z: Nr   )	enumerater   rj   rw   ry   rx   Doublerz   get_dbus_stringr~   	__class__strr{   r   )rP   lstrJ   structnumitemr  s          r'   _convert_structzTransaction._convert_struct  s^   
 "3 	IICIS>S(MM$**T"23s^s*MM$**T"23s^s*MM$++d"34s^s*MM$++d"34s^s*MM$,,t"45s^s*MM/$"78#%)9S>%; < <	I, {{6T^^I-FGG  Ioo<?<E<?J'H I IIs   DE	F$&F

Fc                    | j                   t        j                  k7  rt        j                         t        |t        j                        st        j                  d|z        |j                  j                  d      st        j                  d      |j                         D ]  \  }}|| j                  v rt        j                  d|z        t        |j                  d            dkD  st        j                  d      t        |t        j                        ryt        j                  d|z         | j                  j!                  |       | j#                  d	| j                         y )
Nz)The data value has to be a dictionary: %srU   z"Only strings are accepted as keys.zHThe key %s already exists. It is not allowed to overwrite existing data._r   z5The key %s has to be of the format IDENTIFIER-KEYNAMEz The value has to be a string: %sr   )statusr   r   r   TransactionAlreadyRunningrt   rj   r|   InvalidMetaDataErrorrJ   
startswithrr   r   lensplitru   updatePropertyChanged)rP   r   r   r   s       r'   _set_meta_datazTransaction._set_meta_data  sX   ;;%1112244$0-- /?AE/F G G~~((--- /9 : :**, 	HJCdoo%11 3: =@3@ A A syy~&*11 3G H H eT[[111 3?AF3G H H	H 	t$Z9r)   c                     | j                   S rA   )r   rP   s    r'   _get_meta_datazTransaction._get_meta_data  s    r)   zRAllows client applications to store meta data for the transaction in a dictionary.)docc                     | j                   t        j                  k7  rt        j                         t        j                  |      | _         | j                  d| j                          y )NRole)r   r   
ROLE_UNSETr   TransactionRoleAlreadySetrj   ru   r  rP   enums     r'   	_set_rolezTransaction._set_role  sG    ::)))2244[[&
VTZZ0r)   c                     | j                   S rA   )r   r!  s    r'   	_get_rolezTransaction._get_role	      zzr)   zOperation type of transaction.c                 j    | j                  |d      | _        | j                  d| j                         y )Nr   ProgressDetails)r  r   r  )rP   detailss     r'   _set_progress_detailsz!Transaction._set_progress_details  s.    !%!5!5gx!H.0F0FGr)   c                     | j                   S rA   )r   r!  s    r'   _get_progress_detailsz!Transaction._get_progress_details      %%%r)   zzTuple containing detailed progress information: items done, total items, bytes done, total bytes, speed and remaining timec                     || _         | j                  |j                        |j                  z  }| j	                  |j
                  |fd      | _        | j                  d| j                         y )Nr   Error)r   r$   r0  details_argsr  coder   r  )rP   excepr&   s      r'   
_set_errorzTransaction._set_error  sZ    ll5==)E,>,>>#33UZZ4EtLWd&:&:;r)   c                     | j                   S rA   )r   r!  s    r'   
_get_errorzTransaction._get_error"      {{r)   zRaised exception.c                 d   t         j                  | _        t        j                  |      | _        | j                  d| j
                         | j                  | j
                         | j                  r| j                  j                          t        j                  t        | j                         y )N	ExitState)r   STATUS_FINISHEDr  rj   ru   r   r  Finishedr   cancelr   r   r   r   r(  s     r'   	_set_exitzTransaction._set_exit'  s{    ++[[&
[$**5djj!%%' 	  !8!%!F!F	Hr)   c                     | j                   S rA   )r   r!  s    r'   	_get_exitzTransaction._get_exit3  r-  r)   z"The exit state of the transaction.c                     | j                   S rA   )r   r!  s    r'   _get_downloadzTransaction._get_download9      ~~r)   c                 p    t        j                  |      | _        | j                  d| j                         y )NDownload)rj   ry   r   r  rP   sizes     r'   _set_downloadzTransaction._set_download<  s&    D)Z8r)   z%The download size of the transaction.c                     | j                   S rA   )r   r!  s    r'   
_get_spacezTransaction._get_spaceC  r=  r)   c                 p    t        j                  |      | _        | j                  d| j                         y )NSpace)rj   ry   r   r  rK  s     r'   
_set_spacezTransaction._set_spaceF  s&    jj&Wdkk2r)   z+The required disk space of the transaction.c           	          t        j                  |D cg c]  }t        j                  |d       c}d      | _        | j	                  d| j                         y c c}w )NrU   r   asPackages)rj   r{   r}   r   r  )rP   r   r   s      r'   _set_packageszTransaction._set_packagesM  sQ    2:&<*. '+jj&E &</35 	Z8&<   Ac                     | j                   S rA   )r   r!  s    r'   _get_packageszTransaction._get_packagesS  rH  r)   zaPackages which will be explictly installed, reinstalled, removed, purged, upgraded or downgraded.c                     | j                   S rA   )r   r!  s    r'   _get_unauthenticatedz Transaction._get_unauthenticated[      $$$r)   c                 t    t        j                  |d      | _        | j                  d| j                         y )NrU   r   Unauthenticated)rj   r}   r   r  )rP   unauthenticateds     r'   _set_unauthenticatedz Transaction._set_unauthenticated^  s,     $

?c J.0E0EFr)   z,Unauthenticated packages in this transactionc                     | j                   S rA   )r   r!  s    r'   _get_high_trust_packagesz$Transaction._get_high_trust_packagesi  s    (((r)   c                 t    t        j                  |d      | _        | j                  d| j                         y )NrU   r   HighTrustWhitelistedPackages)rj   r}   r   r  )rP   whitelisted_packagess     r'   _set_high_trust_packagesz$Transaction._set_high_trust_packagesl  s3    $(JJ/C9<%>!;!66	8r)   z'High trust packages in this transactionc                     | j                   S rA   )r   r!  s    r'   _get_dependszTransaction._get_dependsw  s    }}r)   c           	          t        j                  |D cg c]  }t        j                  |d       c}d      | _        | j	                  d| j                         y c c}w )NrU   r   rT  Dependencies)rj   r{   r}   r   r  )rP   dependsdepss      r'   _set_dependszTransaction._set_dependsz  sQ    18%:)- &*ZZ%D %:.24 	^T]];%:rW  zIThe additional dependencies: installs, removals, upgrades and downgrades.c                     | j                   S rA   )r   r!  s    r'   _get_statuszTransaction._get_status  s    ||r)   c                 p    t        j                  |      | _        | j                  d| j                         y )NStatus)rj   ru   r   r  r(  s     r'   _set_statuszTransaction._set_status  s&    {{4(Xt||4r)   zThe status of the transaction.c                     | j                   S rA   )r   r!  s    r'   _get_status_detailszTransaction._get_status_details  s    ###r)   c                 \    t        |      | _        | j                  d| j                         y )NStatusDetails)r  r   r  )rP   texts     r'   _set_status_detailszTransaction._set_status_details  s%    .t4_d.B.BCr)   zThe status message from apt.c                     | j                   S rA   )r   r!  s    r'   _get_progresszTransaction._get_progress  rH  r)   c                 p    t        j                  |      | _        | j                  d| j                         y )NProgress)rj   rw   r   r  )rP   percents     r'   _set_progresszTransaction._set_progress  s&    G,Z8r)   z+The progress of the transaction in percent.c                     | j                   S rA   )r   r!  s    r'   _get_progress_packagez!Transaction._get_progress_package  r4  r)   c                 2    | j                  |d      | _        y )Nr   )r  r   )rP   progress_packages     r'   _set_progress_packagez!Transaction._set_progress_package  s    !%!5!56F!Mr)   zbThe last progress update of a currentlyprocessed package. A tuple of package name and status enum.c                     | j                   S rA   )r   r!  s    r'   _get_progress_downloadz"Transaction._get_progress_download  s    &&&r)   c                 j    | j                  |d      | _        | j                  d| j                         y )Nr   ProgressDownload)r  r   r  )rP   progress_downloads     r'   _set_progress_downloadz"Transaction._set_progress_download  s3    "&"6"67H7?#A/1H1HIr)   zThe last progress update of a currentlyrunning download. A tuple of URI, status, short description, full size, partially downloaded size and a status message.c                     | j                   S rA   )r   r!  s    r'   _get_cancellablezTransaction._get_cancellable  s       r)   c                 p    t        j                  |      | _        | j                  d| j                         y )NCancellable)rj   rz   r   r  )rP   cancellables     r'   _set_cancellablezTransaction._set_cancellable  s)     LL5]D,=,=>r)   z4If it's currently allowed to cancel the transaction.c                     | j                   S rA   )r   r!  s    r'   _get_term_attachedzTransaction._get_term_attached  s    """r)   c                 p    t        j                  |      | _        | j                  d| j                         y )NTerminalAttached)rj   rz   r   r  )rP   attacheds     r'   _set_term_attachedzTransaction._set_term_attached  s*    "ll84/1D1DEr)   zVIf the controlling terminal is currently attached to the dpkg call of the transaction.c                     | j                   S rA   )r   r!  s    r'   _get_required_mediumz Transaction._get_required_medium  r\  r)   c                     | j                  |d      | _        | j                  d| j                          | j                  | j                    y )Nr   RequiredMedium)r  r   r  MediumRequired)rP   mediums     r'   _set_required_mediumz Transaction._set_required_medium  sD     $ 4 4VT B-t/D/DET223r)   zWTuple containing the label and the drive of a required CD/DVD to install packages from.c                     | j                   S rA   )r   r!  s    r'   _get_config_file_conflictz%Transaction._get_config_file_conflict  s    )))r)   c                     |t        j                  dd      | _        y | j                  |d      | _        | j	                  d| j                          | j
                  | j                    y )Nr   r   r   ConfigFileConflict)rj   r{   r   r  r  r  )rP   prompts     r'   _set_config_file_conflictz%Transaction._set_config_file_conflict  s_    >)-X)ND&%)%9%9&$%G"143M3MN!;!;<r)   zCTuple containing the old and the new path of the configuration filer   rH   c                 :    t         j                  d|d|       yzThe signal gets emitted if a property of the transaction changed.

        :param property: The name of the property.
        :param value: The new value of the property.

        :type property: s
        :type value: v
        zEmitting PropertyChanged: rL   Nr  rO   rP   rg   r   s      r'   r  zTransaction.PropertyChanged  s     	hNOr)   rU   c                 Z    t         j                  dt        j                  |      z         y)zThe signal gets emitted if the transaction has been finished.

        :param exit_state: The exit state of the transaction, e.g.
            ``exit-failed``.
        :type exit_state: s
        zEmitting Finished: %sN)r  rO   r   get_exit_string_from_enum)rP   
exit_states     r'   rA  zTransaction.Finished  s(     	/77
CD 	Er)   r   c                 :    t         j                  d|d|       y)a  Set and emit the required medium change.

        This method/signal should be used to inform the user to
        insert the installation CD/DVD:

        Keyword arguments:
        medium -- the CD/DVD label
        drive -- mount point of the drive
        zEmitting MediumRequired: rL   Nr  )rP   r  drives      r'   r  zTransaction.MediumRequired  s     	VUKLr)   c                 :    t         j                  d|d|       y)a(  Set and emit the ConfigFileConflict signal.

        This method/signal should be used to inform the user to
        answer a config file prompt.

        Keyword arguments:
        old -- current version of the configuration prompt
        new -- new version of the configuration prompt
        zEmitting ConfigFileConflict: rL   Nr  )rP   oldnews      r'   r  zTransaction.ConfigFileConflict  s     	cJKr)   c                    | j                   t        j                  k7  rt        j                         dt        |      v rt        d      	 t        j                  t        |            \  }}|d}t        j                  |      | _        nt        j                  |d|      | _        t        j                  dd|g      | _        | j                  d	| j                         y# t        $ r  w xY w)
zSet the language and encoding.

        Keyword arguments:
        locale -- specifies language, territory and encoding according
                  to RFC 1766,  e.g. "de_DE.UTF-8"
        /z,Security exception: Absolute path for localeNC.r#   T)fallback	languagesr   )r  r   r   r   r  r  
ValueErrorr   _parse_localenamerj   ru   r$   translationr   r  )rP   
locale_strlangri   s       r'   _set_localezTransaction._set_locale/  s     ;;%1112244#j/!KLL	8%77JHT8 |"kk$/"kkT8*DE ' 3 3K=A?Cf!FD   4;;7  		s   !C% %C0c              #   >  K   |dk7  r*|j                  d      rd|vrt        j                  |      t        j                  }t        j
                  ||| j                         t        j                  |      | _	        | j                  d| j                         yw)zSet an http network proxy.

        Keyword arguments:
        url -- the URL of the proxy server, e.g. http://proxy:8080
        r5   zhttp://:r   r   N)r  r   InvalidProxyErrorr   PK_ACTION_SET_PROXYcheck_authorization_by_namer   rj   ru   r   r  )rP   urlr   actions       r'   _set_http_proxyzTransaction._set_http_proxyJ  s      "9cnnY73c>**3////44VV9=C 	C++c*[$//:s   BBc                 p    t        j                  |      | _        | j                  d| j                         y)a  Set the handling of the removal of automatically installed
        dependencies which are now obsoleted.

        Keyword arguments:
        remove_obsoleted_depends -- If True also remove automatically installed
            dependencies of to removed packages
        RemoveObsoletedDependsN)rj   rz   r   r  )rP   r   s     r'   _set_remove_obsoleted_dependsz)Transaction._set_remove_obsoleted_dependsY  s0     )-5M(N%5!::	<r)   c                 p    t        j                  |      | _        | j                  d| j                         y)zSet the handling of unauthenticated packages

        Keyword arguments:
        allow_unauthenticated -- True to allow packages that come from a
            repository without a valid authentication signature
        r   N)rj   rz   r   r  )rP   r   s     r'   _set_allow_unauthenticatedz&Transaction._set_allow_unauthenticatede  s0     &*\\2G%H"3!77	9r)   r5   r   r   c                     t         j                  d| j                         	 | j                  j                  |   }|j                  rt        d      | |_        y# t
        $ r t        d      w xY w)a0  Queue the transaction for processing after the given transaction.

        The transaction will also fail if the previous one failed. Several
        transactions can be chained up.

        :param tid: The id of the transaction which should be executed
            before.

        :type tid: s
        Queuing transaction %sz9The given transaction doesn't exist or is already queued!z&There is already an after transaction!N)r  infor   r   r  r  r~   r   )rP   r   r   trans_befores       r'   RunAfterzTransaction.RunAfterq  sr     	/:	/::++C0L DEE!  	/ . / /	/s   A A/c                 d    t         j                  d| j                         | j                  |      S )zTCheck the authentication, simulate and queue the transaction for
        processing.r  )r  r  r   _runrP   r   s     r'   RunzTransaction.Run  s&     	/:yy  r)   c              #     K   | j                  |       | j                          | j                          | j                  j	                  | j
                         t        j                  | _        | j                  }|rn| j                          |j                          | j                  j	                  |j
                         t        j                  |_        |j                  }|rmy y wrA   )
_check_foreign_user_check_simulated_check_authr   putr   r   STATUS_WAITINGr  r   )rP   r   
next_transs      r'   r  zTransaction._run  s     &&v..##%%  

txx **ZZ
''))((**JJNN:>>* % 4 4J#))J s   C,C1/C1c              #      K   | j                   :| j                  j                  j                  sd| _        | j                          y y w)N	   )r   r   workertransprogress_simulate_realr!  s    r'   r  zTransaction._check_simulated  s@     
 >>!
 ::$$** !%%''s   AA
c              #     K   t         j                  | _        | j                  | j                     }|y| j                  t         j
                  t         j                  fv rt        |       rt        j                  }| j                  t         j                  k(  r| j                  t         j                     s| j                  t         j                     sg| j                  t         j                     sJ| j                  t         j                     s-| j                  t         j                     st        j                   }	 | j#                         }|s/t        j$                  | j&                  || j(                         yy# t*        j,                  $ rN}t+        j.                  t         j0                  t3        |            | _        t         j6                  | _        |d}~wt*        j:                  $ rN}t+        j.                  t         j<                  t3        |            | _        t         j6                  | _        |d}~ww xY ww)zCheck silently if one of the high level privileges has been granted
        before to reduce clicks to install packages from third party
        epositories: AddRepository -> UpdateCache -> InstallPackages
        Nr  )r   STATUS_AUTHENTICATINGr  ROLE_ACTION_MAPr   ROLE_INSTALL_PACKAGESROLE_COMMIT_PACKAGESr   r   /PK_ACTION_INSTALL_PACKAGES_FROM_HIGH_TRUST_REPOr   PKGS_INSTALLPKGS_REINSTALLPKGS_REMOVE
PKGS_PURGEPKGS_DOWNGRADEPK_ACTION_UPGRADE_PACKAGES_check_alternative_authr  r   r   r   NotAuthorizedErrorTransactionFailedERROR_NOT_AUTHORIZEDr  r  EXIT_FAILEDexitAuthorizationFailedERROR_AUTH_FAILED)rP   r  
authorizedr  s       r'   r  zTransaction._check_auth  s     11%%dii0> II%55446 6>tDOOFII333MM%"4"45MM%"6"67MM%"3"34MM%"2"23MM%"6"67::F	#;;==J <<T[[=CAEK K  (( 	11%2L2L25e*>DJ))DIL)) 	11%2I2I25e*>DJ))DIL		s9   D7I:AE> <I>H>A	GH>0A	H99H>>Ic              #     K   | j                   t        j                  t        j                  t        j                  t        j
                  t        j                  fvrt        d       t        j                  }t        j                  t        j                  fD ]=  }	 t        j                  | j                  || j                  |       t        d       ? t        d       y# t        j                   $ r Y aw xY ww)z^Check non-interactively if one of the high level privileges
        has been granted.
        F)r   flagsTN)r   r   ROLE_ADD_REPOSITORY"ROLE_ADD_VENDOR_KEY_FROM_KEYSERVERROLE_UPDATE_CACHEr  ROLE_ADD_LICENSE_KEYr   r   CHECK_AUTH_NONE(PK_ACTION_INSTALL_PACKAGES_FROM_NEW_REPO$PK_ACTION_INSTALL_PURCHASED_PACKAGESr  r   r   r   r  )rP   r  r  s      r'   r  z#Transaction._check_alternative_auth  s     
 99U66"EE"44"88"77	9 9
 **!JJ!FFH 
	#F# <<T[[=CAECHJ J T"
	# 	U	 ,, s*   BC</C#
C<#C96C<8C99C<c                 d    t         j                  d| j                         | j                  |      S )zCancel the transaction.zCancelling transaction %s)r  r  r   _cancelr  s     r'   CancelzTransaction.Cancel  s&    
 	2DHH=||F##r)   c              #     K   	 | j                  |       	 | j                  j                  |        t        j                  d       t        j                  | _        t        j                  | _        y # t        j                  $ r7 t        j                  }t        j
                  ||| j                         Y w xY w# t         $ r Y nw xY w| j"                  | j                  j$                  v rt        j                  | _        y | j&                  r9t        j                  d       d| _        t        j                  | _        d| _        y t        j,                  d      w)Nr  zRemoved transaction from queuezSetting cancel eventTFzCould not cancel transaction)r  r   ForeignTransactionr   PK_ACTION_CANCEL_FOREIGNr  r   r   remover  rO   r   STATUS_CANCELLINGr  EXIT_CANCELLEDr  r  r   r  r  r   r   r8   )rP   r   r  s      r'   r  zTransaction._cancel  s%    	G**622
	JJd#OO<=  11DK,,DI (( 	G88F88=AXXG G	G  		 88tzz''',,DIOO23!DN11DKDK##$BCCsG   E!A3 0C  +E!3AB=:E!<B==E! 	C	E!CBE!c                 N    t         j                  d       | j                  |      S )zSimulate a transaction to update its dependencies, download size
        and required disk space.

        Call this method if you want to show changes before queuing the
        transaction.
        zSimulate was called)r  r  	_simulater  s     r'   SimulatezTransaction.Simulate  s      	,-~~f%%r)   c              #      K   | j                   rt        j                         | j                  t        j
                  k7  rt        j                         | j                  |       | j                          y wrA   )	r   r   TransactionAlreadySimulatingr  r   r   r  r  r  r  s     r'   r  zTransaction._simulate'  s_     5577;;%1112244&&v..!!##s   A8A:c              #     K   | j                   rt        j                         | j                  t        j
                  k(  r| j                          | j                  j                  j                  |        t               }| j                  t        j                  | j                         d | _        | j                  j                  j                  d| j                  |      | _         | y w)Nztransaction-simulated)r   r   r
  r   r   ROLE_INSTALL_FILEr  r   r  simulater   r   r   source_remover   _on_transaction_simulated)rP   deferreds     r'   r  zTransaction._simulate_real0  s     557799///""$$

""4(:'t//0!ZZ..66#** s   C,C.c                     || ury | j                   j                  j                  | j                         d | _        |j
                  r|j                  |j
                         y |j                          y rA   )r   r  
disconnectr   _simualted_cbr  errbackcallback)rP   r  r  r  s       r'   r  z%Transaction._on_transaction_simulatedA  sX    

$$T%7%78!;;U[[)r)   c                    | j                   t        j                  k7  rt        j                         t        | j                  | j                        5  t        j                  j                  |      dk7  rt        j                  d|z        d}	 t        j                  |t        j                  t        j                  z        }t        j                  |      j                   | j                  k7  r&t        j                  d|d| j                  d      t        j"                  |      r7t%        j&                  |      | _        | j+                  d| j(                         nt        j                  d|z        	 |t        j.                  |       	 ddd       y# t,        $ r t        j                  d|z        w xY w# |t        j.                  |       w w xY w# 1 sw Y   yxY w)	aA  Set the controlling terminal.

        The worker will be attached to the specified slave end of a pty
        master/slave pair. This allows to interact with the

        Can only be changed before the transaction is started.

        Keyword arguments:
        ttyname -- file path to the slave file descriptor
        z/dev/ptsz%s isn't a ttyNzPty device 'z6' has to be owned bythe owner of the transaction (uid z) r   zCould not open %s)r  r   r   r   r  r   r   r   r   r   dirnamer8   openO_RDWRO_NOCTTYfstatst_uidisattyrj   ru   r   r  r~   close)rP   ttynameslave_fds      r'   _set_terminalzTransaction._set_terminalK  s    ;;%1112244488TXX. 	'www':5++,<w,FGGH'777BII,CD 88H%,,8 //?F1R S S 99X&$(KK$8DM((T]]C //0@70JKK D 'HHX&+	' 	'  K++,?',IJJK 'HHX& ()	' 	's7   =G5FB6G<G"F??GGGG(c                    | j                   t        j                  k7  rt        j                         t        | j                  | j                        5  	 t        j                  |      }|j                  | j                  k7  rt        j                  d|z        	 ddd       t        j                  |      | _        | j!                  d| j                         y# t        $ r t        j                  d|z        w xY w# 1 sw Y   exY w)a  Set the socket of the debconf proxy.

        The worker process forwards all debconf commands through this
        socket by using the passthrough frontend. On the client side
        debconf-communicate should be connected to the socket.

        Can only be changed before the transaction is started.

        Keyword arguments:
        debconf_socket: absolute path to the socket
        z;socket '%s' has to be owned by the owner of the transactionz#socket status could not be read: %sNr   )r  r   r   r   r  r   r   r   r   statr  r8   r~   rj   ru   r   r  )rP   debconf_socketr#  s      r'   _set_debconfzTransaction._set_debconfo  s     ;;%1112244488TXX. 
	P	Pww~.
 ;;$((* // 1>@N1O P P +
	P {{>2_dll;  C++ -13A-B C CC
	P 
	Ps$   C?C)1C?"C<<C??Dc                 R    t         j                  d|       | j                  ||      S )a$  Continue paused transaction with the inserted medium.

        If a media change is required to install packages from CD/DVD
        the transaction will be paused and could be resumed with this
        method.

        :param medium: The label of the CD/DVD.
        :type medium: s
        zMedium %s was provided)r  r  _provide_mediumrP   r  r   s      r'   ProvideMediumzTransaction.ProvideMedium  s&     	/8##FF33r)   c              #      K   | j                  |       | j                  st        j                  d      | j                  d   |k(  st        j                  d|z        d| _        y w)Nz There isn't any required medium.r   z The medium '%s' isn't requested.F)r  required_mediumr   r8   r   r(  s      r'   r'  zTransaction._provide_medium  sl     &&v..##''(JKK##A&&0'' )57=)> ? ?s   A'A)c                 V    t         j                  d||       | j                  |||      S )a  Resolve a configuration file conflict and continue the transaction.

        If a config file prompt is detected the transaction will be
        paused and could be resumed with this method.

        :param config: The path to the original config file.
        :param answer: The answer to the configuration file question, can be
            "keep" or "replace"

        :type config: s
        :type answer: s
        zResolved conflict of %s with %s)r  r  _resolve_config_file_conflictrP   configanswerr   s       r'   ResolveConfigFileConflictz%Transaction.ResolveConfigFileConflict  s*      	8&&I11&&&IIr)   c              #     K   | j                  |       | j                  st        j                  d      |dvrt        j                  d|z        | j                  d   |k(  st        j                  d|z        || _        d| _        y w)Nz+There isn't any config file prompt required)keepreplacezInvalid value: %sr   zInvalid config file: %sF)r  config_file_conflictr   r8   config_file_conflict_resolutionr   r.  s       r'   r-  z)Transaction._resolve_config_file_conflict  s     &&v..(('' )3 4 4,, ''(;f(DEE((+v5''(AF(JKK/5,s   B
Bc              #     K   | j                  |       |t        k(  r|dk(  r| j                  |       y
|dk(  r| j                  |       y
|dk(  r| j	                  |       y
|dk(  r| j                  |       y
|dk(  r| j                  |       y
|dk(  r| j                  |       y
|dk(  r| j                  ||       y
t        j                  j                  d|z        t        j                  j                  d	|z        w)z7Helper to set a name on the properties D-Bus interface.r   r   r   r   r  r   r   r   Unknown interface: %sN)r  r   r  r!  r%  r  r  r  r  rj   r   r   r   s        r'   r   zTransaction._set_property  s     &&v..88z!##E*#""5)(!!%(!  '112259////6$$$UF3oo33 5CEI5J K K ////0G0516 7 7s   DDc           
         |t         k(  rMi d| j                  d| j                  d| j                  d| j                  d| j
                  d| j                  d| j                  d| j                  d	| j                  d
| j                  d| j                  d| j                  d| j                  d| j                  d| j                  dt!        j"                  | j$                        d| j&                  | j(                  | j*                  | j,                  | j.                  | j0                  | j2                  | j4                  | j6                  dS i S )r   r%  r|  r/  r  rq  rv  r  r  r  r  r?  r6  r   r   r   Pausedr   )r  r   rU  r   rj  rJ  rQ  r^  )r   r   r  progress_detailsr  r  status_detailsr  term_attachedr+  r5  r  r   r   r   r   rj   rz   r   r   r   r   r   	meta_datark  downloadspacer_  r   s     r'   rp   zTransaction._get_properties  s   88FDII %t'<'< '(>(> dkk	
 $T%8%8 "4#3#3 '(:(: %d&:&: )$*C*C   T11 dkk  $T\\ dll4;;7  +D,F,F!" /3.K.K!% $ $$(LL $!ZZ'+';';1 6 Ir)   c              #      K   t        j                  || j                        }| j                  |k7  rt	        j
                         yw)z6Check if the transaction is owned by the given caller.N)r   get_uid_from_dbus_namer   r   r   r  )rP   	dbus_namer   s      r'   r  zTransaction._check_foreign_user  s@      55iJJ88s?++-- s   AA	c                     || _         y)z3Set the kwargs which will be send to the AptWorker.Nr   )rP   r   s     r'   _set_kwargszTransaction._set_kwargs  s	    r)   c                     | j                   r| j                   S d}t        j                  |t        j                  |      d      S )z1Get a usable translations object, no matter what.r#   T)r  )r   r$   r  bindtextdomain)rP   domains     r'   _get_translationszTransaction._get_translations  sA    $$$ F&&vw/E/Ef/M046 6r)   c                 T    |sy| j                         } t        |t              |      S )zpTranslate the given message to the language of the transaction.
        Fallback to the system default.
        r5   )rJ  getattr_gettext_method)rP   r&   r  s      r'   r$   zTransaction.gettext  s,    
 ,,.4w{O4S99r)   c                 R    | j                         } t        |t              |||      S )zwTranslate the given plural message to the language of the
        transaction. Fallback to the system default.
        )rJ  rL  _ngettext_method)rP   singularpluralcountr  s        r'   r+   zTransaction.ngettext"  s+     ,,.5w{$45hNNr)   )TNNN)r   r   r   r   r   ROLE_PK_QUERYr  r   $PK_ACTION_INSTALL_OR_REMOVE_PACKAGESROLE_REMOVE_PACKAGESr  PK_ACTION_INSTALL_FILEROLE_UPGRADE_PACKAGESr  ROLE_UPGRADE_SYSTEMr  PK_ACTION_UPDATE_CACHEr  ROLE_ADD_VENDOR_KEY_FILEPK_ACTION_CHANGE_REPOSITORYr  ROLE_REMOVE_VENDOR_KEYROLE_FIX_INCOMPLETE_INSTALLROLE_FIX_BROKEN_DEPENDSr  ROLE_RECONFIGURE
ROLE_CLEANPK_ACTION_CLEANROLE_ENABLE_DISTRO_COMPr  r  rs   r   r   r   r  r  r"  rg   r>  r*  r,  r   r1  r3  r;  r:  r<  r  rC  rE  r  rG  rM  r?  rO  rR  r@  rV  rY  r   r[  r`  r_  rb  rf  high_trust_packagesrh  rm  rk  ro  rr  r  rt  rx  r<  rz  r~  r  r  r  r  r  r  r  r  r  r  r  r  r=  r  r  r+  r  r  r5  rj   rk   r   r   r  rA  r  r  r  r   r  r  r  r   r  r   r  r  r  r  r  r  r  r  r  r  r  r!  r%  r)  r'  r1  r-  r   rp   r  rF  rJ  r$   r+   rG   r)   r'   r   r     sF   #>T#>##;;#> 	"";;#> 	--#> 	##11#> 	!!11#> 	--#> 	"";;#>  	&&22##>$ 	0022'#>( 	$$22+#>, 	));;/#>0 	%%;;3#>4 	!!227#>8 	;;;#>< 	&&?#>@ 	%%22C#>D 	"";;G#>OJ4
 @Dc"J&"H<:6 DEI1 Iy.NODH
&   57L%56< Z1DEE
H Iy<>D9 }CEH3 ZFHE9 }*+H
%G 35I$12O)8 ##;#;(56
< |\67G5 k;:<F$D 13F"@BN9 }EGH&N   5 5%<='J
 !!7!7&01!? +-= ./K#F /1C"01M
%4
 35I$+,O
*= $$=$=)IJ 
\\(L#'  )	P)	P 
\\(L#&  (E(E 
\\(L#'  )
M)
M 
\\(L#'  )
L)
L86 ; ;
<	9 
\\=&)(0  2"2", >'))13!3! * *   & &P  2 >'))13$3$
 D D8 >'))13&3& $ $    "'H<: >'*")13434   >'+2)13J3J    7 72@ . .6:Or)   r   c                       e Zd ZdZdej
                  j                  ddfiZd Zd Z	d Z
d Zd	 Zd
 Zd Zed        Zy)r   zQueue for transactions.queue-changedNrG   c                     t         j                   j                  |        t        j                         | _        d| _        || _        i | _        | j                  j                  d| j                         y)z*Intialize a new TransactionQueue instance.r   ztransaction-doneN)
r   r   collectionsdeque_queue_proc_countr  r  r   _on_transaction_done)rP   r  s     r'   r   zTransactionQueue.__init__2  sU      &!'')
.0I0IJr)   c                 ,    t        | j                        S rA   )r  ri  r!  s    r'   __len__zTransactionQueue.__len__<  s    4;;r)   c                 P    t         j                  d       | j                  d       y)zEmit the queued-changed signal.zemitting queue changedre  N)rN   rO   emitr!  s    r'   _emit_queue_changedz$TransactionQueue._emit_queue_changed?  s    		*+		/"r)   c                 t   | j                   j                  |      }|j                  t        j                  |j                         | j
                  j                  r1t        j                  |_	        | j                  j                  |       n| j
                  j                  |       | j                          y)zAdd an item to the queue.N)r  r  r   r   r  r  r  r   r  r  ri  r   runrp  )rP   r   r  s      r'   r  zTransactionQueue.putD  s|    

s#(u001;; //ELKKu%KKOOE"  "r)   c                 b   |j                   t        j                  t        j                  fv r|j                   t        j                  k(  rt        j                  }nt        j                  }|j
                  }|rM| j                  |       ||_         t        j                  |j                        }||_	        |j
                  }|rM	 | j                  j                         }| j                  j                  |       | j#                          y# t        $ r t        j!                  d       Y 1w xY w)z2Mark the last item as done and request a new item.z"There isn't any queued transactionN)r  r   r  r  EXIT_PREVIOUS_FAILEDr   r  get_role_error_from_enumr   r<  ri  popleftr  rr  
IndexErrorrN   rO   rp  )rP   r  r  r  _transr&   r  s          r'   rk  z%TransactionQueue._on_transaction_doneP  s    
 ::%++U-A-ABBzzU...11++[[FF#"44UZZ@(+% 	(,,.J KKOOJ'  "	  	<II:;	<s   D D.-D.c                 Z    | j                   j                  |       | j                          y)z)Remove the specified item from the queue.N)ri  r  rp  rP   transactions     r'   r  zTransactionQueue.removei  s     ;'  "r)   c                 z    | j                   D ]  }|j                           | j                   j                          y)z Remove all items from the queue.N)ri  r   clearrz  s     r'   r}  zTransactionQueue.clearn  s1    ;; 	;K88:	;r)   c                 ,    t        | j                        S )z*Return a list containing all queued items.)listri  r!  s    r'   rr   zTransactionQueue.itemst  s     DKK  r)   )r   r   r   r   r   SignalFlags	RUN_FIRST__gsignals__r   rm  rp  r  rk  r  r}  rg   rr   rG   r)   r'   r   r   *  s`    !#g&9&9&C&C&*&(&* +LK #

##2#
 ! !r)   r   c                   8   e Zd ZdZd5dZd Zej                  j                  e	d      d        Z
ej                  j                  e	d      d	        Zd
 Zed6d       Z ee	ddd      d        Z ee	ddd      d        Z ee	ddd      d        Z ee	ddd      d        Z ee	ddd      d        Z ee	ddd      d        Z ee	ddd      d        Z ee	ddd      d        Z ee	ddd      d        Z ee	ddd      d        Z ee	ddd      d        Z ee	ddd      d        Z ee	d dd      d!        Z ee	ddd      d"        Z ee	d#dd      d$        Z ee	d%dd      d&        Z ee	ddd      d'        Z  ee	ddd      d(        Z!ed)        Z"ej                  jG                  e	dd*      d+        Z$ej                  jG                  e	ddd,      d-        Z% ee	d.dd      d/        Z&ed0        Z'd1 Z(d2 Z)d3 Z*d4 Z+y)7r   zProvides a system daemon to process package management tasks.

    The daemon is transaction based. Each package management tasks runs
    in a separate transaction. The transactions can be created,
    monitored and managed via the D-Bus interface.
    Nc                 P   t         j                  d       t        j                  t        j                  t
        j                  | j                  d       t        j                  d       || _
        d| _        |du rK|t        j                         }|| _        t        }	 t        j                   j#                  t$        |d      }nd}d}t>        jA                  | ||       |jB                  rtE               | _#        n,|jH                   }	 ddl%m&}  ||jN                  |      | _#        tS        | jF                        | _*        | jT                  jW                  d| jX                         | jF                  j[                         | _.        t         j_                  d       y# t        j&                  j(                  $ r | j                  j*                  du r*t         j-                  d       t/        j0                  d       t         j3                  d	       |j5                  t$        t              }|j7                  t8        d
       t;        j<                  d       t        j                   j#                  t$        |d      }Y w xY w#  tQ        |jN                  |      | _#        Y |xY w)a   Initialize a new AptDaemon instance.

        Keyword arguments:
        options -- command line options of the type optparse.Values
        connect -- if the daemon should connect to the D-Bus (default is True)
        bus -- the D-Bus to connect to (defaults to the system bus)
        zInitializing daemonN   T)do_not_queueFz!Another daemon is already runningr   z Replacing already running daemonr/   )rI   timeout)AptPackageKitWorkerre  zDaemon was initialized)0rN   r  r   unix_signal_addPRIORITY_HIGHr   SIGTERM_sigquitr   niceoptions
packagekitrj   r   r   APTDAEMON_DBUS_PATHrk   r   r   r   NameExistsExceptionr4  criticalr9   r  warning
get_objectQuitAPTDAEMON_DBUS_INTERFACEtimesleeprF   r   dummyr   r  disable_pluginsworker.pkworkerr  chrootr   r   r   r   _on_queue_changedis_reboot_required_reboot_requiredrO   )	rP   r  r   r   bus_pathr   the_other_guyload_pluginsr  s	            r'   r   zAptDaemon.__init__  s    	&' 	T//!]]D	2 	
d?{nn&DH*HC<<//0F03=A 0 C" HHD(H5==%-DK&666LF@1'..2>@ &dkk2


?D,B,BC $ > > @		*+? ??66 C<<''50LL!DEHHQK>? #/E/B!D""2J+. # 0

1<<//0F03=A 0 CC2F'Es   &F J C JJJ%c                    | j                   j                         | j                  k7  r;| j                   j                         | _        | j                  d| j                         | j                  j                   j
                  r+| j                  j                   j
                  j                  }nd}| j                  j                  D cg c]  }|j                   }}| j                  ||       yc c}w )z)Callback for a changed transaction queue.RebootRequiredr5   N)	r  r  r  r  r   r  r   rr   ActiveTransactionsChanged)rP   r   currentr  queueds        r'   r  zAptDaemon._on_queue_changed  s     ;;))+t/D/DD$(KK$B$B$DD!  !143H3HI::""jj''--11GG)-)9)9:%))::&&w7 ;s   C0r   rH   c                 :    t         j                  d|d|       yr  rM   r  s      r'   r  zAptDaemon.PropertyChanged  s     			%HIr)   sasc                 2    t         j                  d||       y)a!  The currently processed or the queued transactions changed.

        :param current: The path of the currently running transaction or
            an empty string.
        :param queued: List of the ids of the queued transactions.

        :type current: s
        :type queued: as
        z1Emitting ActiveTransactionsChanged signal: %s, %sNrM   )rP   r  r  s      r'   r  z#AptDaemon.ActiveTransactionsChanged  s     			E6	#r)   c                 :   | j                   j                  du r9t        j                  d       t	        j
                  t        | j                         t        j                  d       	 t        j                          y# t        $ r | j                  d       Y yw xY w)z&Start the daemon and listen for calls.FzUsing inactivity checkzWaiting for callsN)r  disable_timeoutrN   rO   r   r   r   _check_for_inactivityr    rr  KeyboardInterruptr  r!  s    r'   rr  zAptDaemon.run  sq    <<''50II./$$%B%)%?%?A		%&	LLN  	IIdO	s   (A= =BBc              #   Z  K   t        j                  || j                        \  }}}}t        j                         j
                  }	t        |	|| j                  |||||||| j                        }
|
| j                  j                  |
j                  <   t        |
j                         yw)z9Helper method which returns the tid of a new transaction.)r   r   r   N)r   get_proc_info_from_dbus_namer   r   r   r   r   r   r  r   r   )rP   r   r   r   r   r   r   r   r   r   r  s              r'   _create_transzAptDaemon._create_trans  s      99&$((KK 	S#wjjltzz3S'6f$((< ',

#UYYs   B)B+r5   rU   r   r   c                 l    t         j                  d       | j                  t        j                  |      S )aN  Try to complete cancelled installations. This is equivalent to a
        call of ``dpkg --configure -a``.

        Requires the ``org.debian.apt.install-or-remove-packages``
        :ref:`PolicyKit privilege <policykit>`.

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        zFixIncompleteInstall() called)rN   r  r  r   r]  r  s     r'   FixIncompleteInstallzAptDaemon.FixIncompleteInstall  s*     	01!!%"C"CVLLr)   c                 l    t         j                  d       | j                  t        j                  |      S )a#  Try to resolve unsatisfied dependencies of installed packages.

        Requires the ``org.debian.apt.install-or-remove-packages``
        :ref:`PolicyKit privilege <policykit>`.

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        zFixBrokenDepends() called)rN   r  r  r   r^  r  s     r'   FixBrokenDependszAptDaemon.FixBrokenDepends  s*     	,-!!%"?"?HHr)   c                 x    t         j                  d       ddi}| j                  t        j                  ||      S )aL  Download the latest information about available packages from the
        repositories and rebuild the package cache.

        Requires the ``org.debian.apt.update-cache``
        :ref:`PolicyKit privilege <policykit>`.

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        zUpdateCache() was calledsources_listNrE  rN   r  r  r   r  )rP   r   r   s      r'   UpdateCachezAptDaemon.UpdateCache'  s@     	+, $'!!%"9"96)/ " 1 	1r)   c                 x    t         j                  d       d|i}| j                  t        j                  ||      S )aL  Update the cache from the repositories defined in the given
        sources.list only.

        Requires the ``org.debian.apt.update-cache``
        :ref:`PolicyKit privilege <policykit>`.

        :param sources_list: The absolute path to a sources.list, e.g.
            :file:`/etc/apt/sources.list.d/ppa-aptdaemon.list` or the name
            of the snippet in :file:`/etc/apt/sources.list.d/`, e.g.
            :file:`ppa-aptdaemon.list`.
        :type sources_list: s

        :returns: The D-Bus path of the new transaction object which
            performs this action.
         z!UpdateCachePartially() was calledr  rE  r  )rP   r  r   r   s       r'   UpdateCachePartiallyzAptDaemon.UpdateCachePartially:  s@    & 	45 ,/!!%"9"96)/ " 1 	1r)   rT  c           
          t         j                  d|       | j                  |       | j                  t        j
                  |g g |g g g f      S )a  Remove the given packages from the system. The configuration files
        will be kept by default. Use :func:`CommitPackages()` to also purge the
        configuration files.

        Requires the ``org.debian.apt.install-or-packages``
        :ref:`PolicyKit privilege <policykit>`.

        :param package_names: packages to be removed
        :type package_names: as

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        z!RemovePackages() was called: '%s'r   )rN   r  _check_package_namesr  r   rU  rP   package_namesr   s      r'   RemovePackageszAptDaemon.RemovePackagesS  sU    " 	4mD!!-0!!%"<"<f,.M2r2+N " P 	Pr)   rf   c                 z    t         j                  d|z         | j                  t        j                  |d|i      S )a  Apply all available upgrades and try to resolve conflicts.

        Requires the ``org.debian.apt.upgrade-packages``
        :ref:`PolicyKit privilege <policykit>`.

        :param safe_mode: If True only already installed packages will be
            updated. Updates which require to remove installed packages or to
            install additional packages will be skipped.

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        z-UpgradeSystem() was called with safe mode: %s	safe_moderE  )rN   r  r  r   rX  )rP   r  r   s      r'   UpgradeSystemzAptDaemon.UpgradeSystemj  sI      	 !" 	#!!%";";V*5y)A " C 	Cr)   r   c           	          t         j                  d||||||       d }||||||fD 	cg c]
  }	 ||	       }
}	|
D ]  }| j                  |        | j                  t        j
                  ||
      S c c}	w )a  Perform several package changes at the same time.

        The version number and target release of the packages can be specified
        using the traditional apt-get syntax, e.g. "xterm=281.1" to force
        installing the version 281.1 of xterm or "xterm/experimental" to
        force installing xterm from the experimental release.

        Requires the ``org.debian.apt.install-or-remove-packages``
        :ref:`PolicyKit privilege <policykit>`.

        :param install: Packages to be installed.
        :param reinstall: Packages to be re-installed
        :param remove: Packages to be removed
        :param purge: Package to be removed including theirs configuration
            files.
        :param upgrade: Packages to be upgraded.
        :param downgrade: Packages to be downgraded. You
            have to append the target version to the package name separated
            by "="

        :type install: as
        :type reinstall: as
        :type remove: as
        :type purge: as
        :type upgrade: as
        :type downgrade: as

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        z3CommitPackages() was called: %s, %s, %s, %s, %s, %sc                     | dgk(  rg S | S )Nr5   rG   )r  s    r'   check_empty_listz2AptDaemon.CommitPackages.<locals>.check_empty_list  s    rd{	
r)   r  )rN   r  r  r  r   r  )rP   install	reinstallr  purgeupgrade	downgrader   r  r  packages_lstr   s               r'   CommitPackageszAptDaemon.CommitPackages  s    J 	F)VUGY	H	
 ;B9:@%:A:C:E F#(- F F % 	0H%%h/	0!!%"<"<f+7 " 9 	9Fs   A4c           
          t         j                  d|z         | j                  |       | j                  t        j
                  ||g g g g g f      S )a  Fetch and install the given packages from the repositories.

        The version number and target release of the packages can be specified
        using the traditional apt-get syntax, e.g. "xterm=281.1" to force
        installing the version 281.1 of xterm or "xterm/experimental" to
        force installing xterm from the experimental release.

        Requires the ``org.debian.apt.install-or-remove-packages``
        :ref:`PolicyKit privilege <policykit>`.

        :param package_names: Packages to be upgraded
        :type package_names: as

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        z InstallPackages() was called: %sr  )rN   r  r  r  r   r  r  s      r'   InstallPackageszAptDaemon.InstallPackages  sX    ( 	3mCD!!-0!!%"="=v,92r2r2+N " P 	Pr)   c           
          t         j                  d|z         | j                  |       | j                  t        j
                  |g g g g |g f      S )a  Upgrade the given packages to their latest version.

        The version number and target release of the packages can be specified
        using the traditional apt-get syntax, e.g. "xterm=281.1" to force
        installing the version 281.1 of xterm or "xterm/experimental" to
        force installing xterm from the experimental release.

        Requires the ``org.debian.apt.upgrade-packages``
        :ref:`PolicyKit privilege <policykit>`.

        :param package_names: Packages to be upgraded
        :type package_names: as

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        z UpgradePackages() was called: %sr  )rN   r  r  r  r   rW  r  s      r'   UpgradePackageszAptDaemon.UpgradePackages  sX    ( 	3mCD!!-0!!%"="=v,.BM2+N " P 	Pr)   r   c                 z    t         j                  d||       | j                  t        j                  |||d      S )a%  Download and install the key of a software vendor. The key is
        used to authenticate packages of the vendor.

        Requires the ``org.debian.apt.change-repositories``
        :ref:`PolicyKit privilege <policykit>`.

        :param keyid: The id of the GnuPG key (e.g. 0x0EB12F05)
        :param keyserver: The server to get the key from (e.g.
            keyserver.ubuntu.com)

        :type keyid: s
        :type keyserver: s

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        z1InstallVendorKeyFromKeyserver() was called: %s %s)keyid	keyserverrE  )rN   r  r  r   r  )rP   r  r  r   s       r'   AddVendorKeyFromKeyserverz#AptDaemon.AddVendorKeyFromKeyserver  sH    ( 	D		#!!%"J"J"(5?H2J " K 	Kr)   c                 z    t         j                  d|z         | j                  t        j                  |d|i      S )a  Install the key file of a software vendor. The key is
        used to authenticate packages of the vendor.

        Requires the ``org.debian.apt.change-repositories``
        :ref:`PolicyKit privilege <policykit>`.

        :param path: The absolute path to the key file.
        :type path: s

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        z%InstallVendorKeyFile() was called: %sr   rE  )rN   r  r  r   rZ  )rP   r   r   s      r'   AddVendorKeyFromFilezAptDaemon.AddVendorKeyFromFile  sA      	84?@!!%"@"@"(&$ " A 	Ar)   c                 z    t         j                  d|z         | j                  t        j                  |d|i      S )a  Remove the given key of a software vendor. The key is used to
        authenticate packages of the vendor.

        Requires the ``org.debian.apt.change-repositories``
        :ref:`PolicyKit privilege <policykit>`.

        :param fingerprint: The fingerprint of the key.
        :type fingerprint: s

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        z RemoveVendorKey() was called: %sfingerprintrE  )rN   r  r  r   r\  )rP   r  r   s      r'   RemoveVendorKeyzAptDaemon.RemoveVendorKey  sB      	3kAB!!%">">"(-1M " O 	Or)   sbc                 |    t         j                  d|z         | j                  t        j                  |||d      S )a  Install the given local package file.

        Requires the ``org.debian.apt.install-file``
        :ref:`PolicyKit privilege <policykit>`.

        :param path: The absolute path to the package file.
        :param force: If the installation of a package which violates the
            Debian/Ubuntu policy should be forced.

        :type path: s
        :type force: b

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        zInstallFile() was called: %s)r   forcerE  )rN   r  r  r   r  )rP   r   r  r   s       r'   InstallFilezAptDaemon.InstallFile0  sH    & 	/$67 !!%"9"9"($;@2B " C 	Cr)   c                 l    t         j                  d       | j                  t        j                  |      S )zRemove downloaded package files.

        Requires the ``org.debian.apt.clean``
        :ref:`PolicyKit privilege <policykit>`.

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        zClean() was called)rN   r  r  r   r`  r  s     r'   CleanzAptDaemon.CleanK  s*     	%&!!%"2"2F;;r)   assc           
          t         j                  ddj                  |      z         | j                  t        j
                  |g |g g g g gd|i      S )a:  Reconfigure already installed packages.

        Requires the ``org.debian.apt.install-or-remove-packages``
        :ref:`PolicyKit privilege <policykit>`.

        :param packages: List of package names which should be reconfigure.
        :param priority: The minimum debconf priority of question to be
            displayed. Can be of value "low", "medium", "high", "critical",
            "default".

        :type packages: as
        :type priority: s

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        zReconfigure() was called: %s priority)r   r   )rN   r  joinr  r   r_  )rP   r   r  r   s       r'   ReconfigurezAptDaemon.Reconfigure[  s[    ( 	/#((82DDE!!%"8"8&,."b"b+I*4h)? " A 	Ar)   sssasssc                     t         j                  d||||||       | j                  t        j                  |||||||d      S )aa  Add given repository to the sources list.

        Requires the ``org.debian.apt.change-repositories``
        :ref:`PolicyKit privilege <policykit>`.

        :param src_type: The type of the repository (deb, deb-src).
        :param uri: The main repository URI
            (e.g. http://archive.ubuntu.com/ubuntu)
        :param dist: The distribution to use (e.g. stable or lenny-backports).
        :param comps: List of components (e.g. main, restricted).
        :param comment: A comment which should be added to the sources.list.
        :param sourcesfile: (Optoinal) filename in sources.list.d.

        :type src_type: s
        :type uri: s
        :type dist: s
        :type comps: as
        :type comment: s
        :type sourcesfile: s

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        zaAddRepository() was called: type='%s' uri='%s' dist='%s' comps='%s' comment='%s' sourcesfile='%s')src_typeuridistcompscommentsourcesfilerE  )rN   r  r  r   r  )rP   r  r  r  r  r  r  r   s           r'   AddRepositoryzAptDaemon.AddRepositoryu  s`    8 	 F3eWk	C !!%";";V6>s265<9D*F " G 	Gr)   c                 v    t         j                  d|       | j                  t        j                  |d|i      S )a  Enable the component in the distribution repositories. This will
        not affect third-party repositories.

        The repositories of a distribution are often separated into
        different components because of policy reasons. E.g. Debian uses main
        for DFSG-free software and non-free for re-distributable but not free
        in the sense of the Debian Free Software Guidelines.

        Requires the ``org.debian.apt.change-repositories``
        :ref:`PolicyKit privilege <policykit>`.

        :param component: The component, e,g, main or non-free.
        :type component: s
        :returns: The D-Bus path of the new transaction object which
            performs this action.
        z-EnableComponent() was called: component='%s' 	componentrE  )rN   r  r  r   rb  )rP   r  r   s      r'   EnableDistroComponentzAptDaemon.EnableDistroComponent  s?    ( 	@)L!!%"?"?*5y)A " C 	Cr)   c                 N    t         j                  d       | j                  |      S )a  Get the list of the installed vendor keys which are used to
        authenticate packages.

        Requires the ``org.debian.apt.get-trusted-vendor-keys``
        :ref:`PolicyKit privilege <policykit>`.

        :returns: Fingerprints of all installed keys.
        z!GetTrustedVendorKeys() was called)rN   r  _get_trusted_vendor_keysr  s     r'   GetTrustedVendorKeyszAptDaemon.GetTrustedVendorKeys  s"     	45,,V44r)   c              #      K   t         j                  }t        j                  ||| j                         | j                  j                         }t        |       y w)Nr  )r   !PK_ACTION_GET_TRUSTED_VENDOR_KEYSr  r   r  get_trusted_vendor_keysr   )rP   r   r  fingerprintss       r'   r  z"AptDaemon._get_trusted_vendor_keys  sK     ==44VV9=C 	C{{::<\"s   AAr   c                 8   t         j                  d       | j                  j                  D cg c]  }|j                   }}| j                  j
                  j                  r.| j                  j
                  j                  j                  }||fS d}||fS c c}w )z^Return the currently running transaction and the list of queued
        transactions.
        z"GetActiveTransactions() was calledr5   )rN   rO   r   rr   r   r  r  )rP   r  r  r  s       r'   GetActiveTransactionszAptDaemon.GetActiveTransactions  s     			67)-)9)9:%))::::""jj''--11G  G ;s   Bcaller_namec                     t         j                  d       t         j                  d       t        j                          t         j                  d       y)z!Request a shutdown of the daemon.zQuitting was requestedzQuitting main loop...ExitN)rN   r  rO   r    quit)rP   r  s     r'   r  zAptDaemon.Quit  s3    
 	)*		)*		&r)   sssc                 x    t         j                  d       | j                  t        j                  ||||d      S )a  Install a license key to use a piece of proprietary software.

        Requires the ``org.debian.apt.install-or-remove-packages``
        :ref:`PolicyKit privilege <policykit>`.

        :param pkg_name: The name of the package which requires the license
        :type pkg_name: s
        :param json_token: The oauth token to use with the server in
            json format
        :type pkg_name: s
        :param server_name: The name of the server to use (ubuntu-production,
            ubuntu-staging)
        :type pkg_name: s

        :returns: The D-Bus path of the new transaction object which
            performs this action.
        zAddLicenseKey() was called)pkg_name
json_tokenserver_namerE  )rN   r  r  r   r  )rP   r  r  r  r   s        r'   AddLicenseKeyzAptDaemon.AddLicenseKey  sD    * 	-.!!%"<"<f6>8B9D*F " G 	Gr)   c              #   (  K   t         j                  }t        j                  ||| j                         |t        k(  r/|dk(  r0| j
                  j                  |t        j                  |             y
|dk(  r1| j
                  j                  |t        j                  |      d       y
|dk(  r1| j
                  j                  |t        j                  |      d       y
|dk(  r1| j
                  j                  |t        j                  |      d       y
|dk(  r1| j
                  j                  |t        j                  |      d       y
t        j                  j                  d|z        t        j                  j                  d	|z        w)r   r  PopConParticipationAutoUpdateInterval
10periodicAutoDownloadAutoCleanIntervalUnattendedUpgrader   r8  N)r   PK_ACTION_CHANGE_CONFIGr  r   r  r  
set_configrj   rz   rw   r   r   )rP   r   r]   r   r   r  s         r'   r   zAptDaemon._set_property  sM     3344VV9=C 	C,,,,&&tT\\%-@A--&&tTZZ->M'&&tT\\%-@,O,,&&tTZZ->M,,&&tT\\%-@,Ooo33 5CEI5J K K ////0G0516 7 7s   FFc                    |D ]  }t        |      \  }}}|j                  d      \  }}}|dvrt        j                  d|z        t	        j
                  t        |      st        j                  d|z        |2t	        j
                  t        |      st        j                  d|z        |t	        j
                  t        |      rt        j                  d|z         y)zTCheck if the package names are valid. Otherwise raise an
        exception.
        #)r5   autoz%s isn't a valid flagz%s isn't a valid package nameNz%s isn't a valid versionz%s isn't a valid release)	r   	partitionr   r8   rematchREGEX_VALID_PACKAGENAMEREGEX_VALID_VERSIONREGEX_VALID_RELEASE)rP   	pkg_namesfullnamer]   versionreleasesep	auto_flags           r'   r  zAptDaemon._check_package_names  s     " 	5H%5h%?"D'7#'>>##6 D#y,++,C,5-6 7 7883T:++,K,0-1 2 2#!4g>++,F,3-4 5 5#!4g>++,F,3-4 5 5	5r)   c           	      :   |t         k(  rt        j                  | j                  j	                  d            t        j
                  | j                  j	                  d            t        j                  | j                  j	                  d            t        j                  | j                  j	                  d            t        j
                  | j                  j	                  d            t        j
                  | j                  j                               dS i S )z/Helper get the properties of a D-Bus interface.r	  r  r  r  r  )r	  r  r  r  r  r  )r  rj   rw   r  
get_configrz   r  r   s     r'   rp   zAptDaemon._get_properties/  s    ,,&*jjKK**+?@'B $KK**>:!<%)ZZKK**+>?&A%)ZZKK**+>?&A'+||KK**+@A(C"&,,KK224#67 7 Ir)   c                 &    | j                  d       y)z&Internal callback for the quit signal.N)r  )rP   r   s     r'   r  zAptDaemon._sigquitB  s    		$r)   c                    t         j                  d       | j                  j                  j                  }| j                  j                  j
                  sst        j                         j                         sQt        j                         |z
  t        kD  r3| j                  s't         j                  d       | j                  d       yy)zjShutdown the daemon if it has been inactive for time specified
        in APTDAEMON_IDLE_TIMEOUT.
        zChecking for inactivityzQuitting due to inactivityNFT)rN   rO   r   r  last_action_timestampr  r   main_context_defaultpendingr  r	   r  r  )rP   	timestamps     r'   r  zAptDaemon._check_for_inactivityF  s     			+,JJ%%;;	

!!''--/779		i'*@@JJHH12IIdOr)   )TN)NN),r   r   r   r   r   r  rj   rk   r   r  r  r  rr  r   r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r   r  rp   r  r  rG   r)   r'   r   r   z  s   <,|8 
\\(@#'  )	J)	J 
\\(@#(  *#*#
 	  	  2'))13M3M 2'))13
I3
I 2'))13131  2'*#)13131, 2'+3)13P3P( 2'*#)13C3C& 2'5S)1319319h 2'+3)13P3P. 2'+3)13P3P. 2'+3)13K3K0 2'*#)13A3A$ 2'*#)13O3O$ 2'+3)13C3C0 2'))13
<3
< 2',C)13A3A. 2'0)13 G3 GF 2'*#)13C3C, 2'))13
53
5 # # 
\\1&(  ?
?
 
\\1&((5  77 2',C)13G3G0 7 7.5,&r)   c                     	 t        j                  |       S # t        $ r( t        j                  | j                  |d            cY S w xY w)z<Convert the given string or unicode object to a dbus.String.ignore)rj   ru   UnicodeDecodeErrordecode)rw  ri   s     r'   r  r  V  s?    <{{4   <{{4;;x:;;<s    .AAc                  ~   t               } | j                  dddddt        d             | j                  dd	ddd
t        d             | j                  dddddt        d             | j                  dddddt        d             | j                  dddddt        d             | j                  ddddddt        d             | j                  dddddd t        d!             | j                  d"ddd#t        d$             | j                         \  }}|j                  d%u r$t
        j                  t        j                         nFt
        j                  t        j                         t        j                  t        j                         |j                  rt        j                         }nd}t        ||&      }|j                  r[d'dl}|j!                         }|j#                  |j$                         |j'                  |j                         |j)                          y|j%                          y)(z.Allow to run the daemon from the command line.z-tz--disable-timeoutF
store_truer  z0Do not shutdown the daemon because of inactivity)defaultr  desthelpr5   z--disable-pluginsr  zDo not load any pluginsz-dz--debugrO   z$Show internal processing informationz-rz	--replacer4  z*Quit and replace an already running daemonz--session-bussession_busz9Listen on the DBus session bus (Only required for testingz--chrootNstorestringr  z&Perform operations in the given chroot)r-  r  ra   r.  r/  z-pz	--profileprofilez)Store profile stats in the specified filez--dummyr  zADo not make any changes to the system (Only of use to developers)Tr  r   )r   
add_optionr  
parse_argsrO   rN   setLevelloggingDEBUGINFO_console_handlerr0  rj   
SessionBusr   r3  Profileruncallrr  
dump_statsprint_stats)parserr  argsr   daemonr3  profilers          r'   mainrD  ^  s?   ^F
d/#)0A * +  ,
 b-#)0A67  9 dI#) + ,  -
 dK#)	 & '  (
 b/#) + ,  -
 b*d$8( & '  ( dK#$8) $ %  &
 i#) 5 6  7
 %%'MGT}}W]]#W\\"!!',,/oowC(F??$$GOO,

r)   )rh   )er   
__author____all__rg  	xml.etreer   r$   hashlibr   r   r7  logging.handlersoptparser   r   r  r   r9   r  r   gi.repositoryr   r   dbus.exceptionsrj   dbus.servicedbus.mainloop.glibr/  r   r5   r   r   deferr   r   r   defer.utilsr   r   utilsr   r   r  r   worker.aptworkerr   r   loopr    loggerr!   r  r  rM  rO  r  r  r   r   r   r	   r
   r   r  r  r  glibDBusGMainLoopputenv	getLoggerrN   handlersSysLogHandler
LOG_DAEMON_syslog_handlerr6  r9  	Formatter_syslog_formattersetFormatter
addHandlerStreamHandlerr:  _console_formatterr  	setlocaleLC_ALLr6  r  r?   
excepthookr   r>   rk   rl   rF   r   r   r   r  rD  rG   r)   r'   <module>rf     s  	4 5
B  !      ! 	 	  
   '        : : ,  2 O  $ 3;;#O! O"+ ' ) 'C $ "        A  2 +           5 
		&
HJ g$$&&44!!//:: 5 <O W\\*))) +8 9  !23 NN?#(7((* % '4&*,    0 1   G/0	KFV]]B'

5 >>11MCNs$$ slSO* SOl M!w M!`Y
 Yx<;M?	 || KKKIJKs    A9J 9J J KK