
    ӭhf                    *   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        G d2 d3ej                  j                        Z[ G d4 d5e[      Z\ G d6 d7ej*                        Z] G d8 d)e[      Z^d;d9Z_d: Z`y#  Y xY w# e	j                  $ r eFj                  d1       Y {w xY w)<aB  
Core components of aptkit.

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

The main function allows to run the daemon as a command.
z%Sebastian Heinlein <devel@glatzor.de>)
TransactionTransactionQueueAptKit!APTKIT_TRANSACTION_DBUS_INTERFACE%APTKIT_DBUS_INTERFACEAPTKIT_DBUS_PATHAPTKIT_DBUS_SERVICEAPTKIT_IDLE_CHECK_INTERVALAPTKIT_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aptkit)gettextdgettext)msgs    -/usr/lib/python3/dist-packages/aptkit/core.py<lambda>r(   G   s      3/     3r$   ngettextugettext	ungettextz
org.aptkitz/org/aptkitzorg.aptkit.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AptKit.Trans z7Failed to unset LC_ALL. Translations are not available.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 )NrB   name	readwriteaccessreadrF   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Structr;   
DictionaryArray	ExceptionrR   appendElementtostring)rA   rG   rH   dataxmlifacepropskeyvaluerb   new_datas              r'   r^   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rI   rJ   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: r=   )r?   r@   _set_propertyrA   ru   rN   rx   r{   s        r'   SetzDBusObject.Set   s,    " 			e<=!!%uf==r)   za{sv}rI   rJ   c                 T    t         j                  d|z         | j                  |      S )z4Get all available properties of the given interface.zGetAll() was called: %sr?   r@   ra   rA   ru   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: r=   r   )rA   ru   rX   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)r[   
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.r8   r   s     r'   ra   zDBusObject._get_properties   s    	r)   N)__name__
__module____qualname____doc__rd   r[   r\   signalPROPERTIES_IFACErE   methodINTROSPECTABLE_IFACEr^   r   r   r   r   r   ra   r8   r)   r'   r7   r7      s   @ 
\\(=(=#-  /K/K& 
\\22&(&3,8  :#	:#L $//',B)13>3>$ 
\\..&)  B+B+ 
\\..&*#  ?5?5C
r)   r7   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/aptkit/transaction/%sTr5   Fz/run/user/%d/pk-debconf-socketr   )r   r   r   r   g        r   iixxdxr;   )r5   r5   r5   r   r   r5   sssxxsr5   r5   r   sv   rF   asasasasasasasasasasasasas)Nuuiduuid4hextidbusr[   	SystemBusr\   BusNamer   r7   __init__queueuidgidrf   localerk   allow_unauthenticatedremove_obsoleted_dependscmdlinepid
http_proxyterminalospathexistsdebconfkwargs_translationafter_rolerh   	_progressrl   _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pausedrm   
_meta_datarj   	_download_spacerangern   _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)rA   r   roler   r   r   r   r   r{   connectr   packagesr   bus_name	dbus_path	pk_socketrT   pkgss                     r'   r   zTransaction.__init__5  s     ;**,""C/#5d?DH{>>+||++,?JH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   )rA   rH   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_transr@   remove_from_connectionLookupErrorr   limbopopr   KeyError)rA   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).
        rT   rV   rU   drW   rF   zValue z with unknown signature zFailed to convert item z of z with signature z: Nr   )	enumeraterp   r[   rh   rj   ri   Doublerk   get_dbus_stringro   	__class__strrl   r   )rA   lstr;   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: %srF   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   TransactionAlreadyRunningre   r[   rm   InvalidMetaDataErrorr;   
startswithrc   r   lensplitrf   updatePropertyChanged)rA   rs   rw   rx   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 N)r   rA   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   TransactionRoleAlreadySetr[   rf   r  rA   enums     r'   	_set_rolezTransaction._set_role  sG    ::)))2244[[&
VTZZ0r)   c                     | j                   S r  )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  )rA   detailss     r'   _set_progress_detailsz!Transaction._set_progress_details  s.    !%!5!5gx!H.0F0FGr)   c                     | j                   S r  )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$   r"  details_argsr  coder   r  )rA   excepr&   s      r'   
_set_errorzTransaction._set_error
  sZ    ll5==)E,>,>>#33UZZ4EtLWd&:&:;r)   c                     | j                   S r  )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  r[   rf   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 r  )r   r  s    r'   	_get_exitzTransaction._get_exit!  r  r)   z"The exit state of the transaction.c                     | j                   S r  )r   r  s    r'   _get_downloadzTransaction._get_download'      ~~r)   c                 p    t        j                  |      | _        | j                  d| j                         y )NDownload)r[   rj   r   r  rA   sizes     r'   _set_downloadzTransaction._set_download*  s&    D)Z8r)   z%The download size of the transaction.c                     | j                   S r  )r   r  s    r'   
_get_spacezTransaction._get_space1  r/  r)   c                 p    t        j                  |      | _        | j                  d| j                         y )NSpace)r[   rj   r   r  r=  s     r'   
_set_spacezTransaction._set_space4  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 )NrF   r   asPackages)r[   rl   rn   r   r  )rA   r   r   s      r'   _set_packageszTransaction._set_packages;  sQ    2:&<*. '+jj&E &</35 	Z8&<   Ac                     | j                   S r  )r   r  s    r'   _get_packageszTransaction._get_packagesA  r:  r)   zaPackages which will be explictly installed, reinstalled, removed, purged, upgraded or downgraded.c                     | j                   S r  )r   r  s    r'   _get_unauthenticatedz Transaction._get_unauthenticatedI      $$$r)   c                 t    t        j                  |d      | _        | j                  d| j                         y )NrF   r   Unauthenticated)r[   rn   r   r  )rA   unauthenticateds     r'   _set_unauthenticatedz Transaction._set_unauthenticatedL  s,     $

?c J.0E0EFr)   z,Unauthenticated packages in this transactionc                     | j                   S r  )r   r  s    r'   _get_high_trust_packagesz$Transaction._get_high_trust_packagesW  s    (((r)   c                 t    t        j                  |d      | _        | j                  d| j                         y )NrF   r   HighTrustWhitelistedPackages)r[   rn   r   r  )rA   whitelisted_packagess     r'   _set_high_trust_packagesz$Transaction._set_high_trust_packagesZ  s3    $(JJ/C9<%>!;!66	8r)   z'High trust packages in this transactionc                     | j                   S r  )r   r  s    r'   _get_dependszTransaction._get_dependse  s    }}r)   c           	          t        j                  |D cg c]  }t        j                  |d       c}d      | _        | j	                  d| j                         y c c}w )NrF   r   rF  Dependencies)r[   rl   rn   r   r  )rA   dependsdepss      r'   _set_dependszTransaction._set_dependsh  sQ    18%:)- &*ZZ%D %:.24 	^T]];%:rI  zIThe additional dependencies: installs, removals, upgrades and downgrades.c                     | j                   S r  )r   r  s    r'   _get_statuszTransaction._get_statusr  s    ||r)   c                 p    t        j                  |      | _        | j                  d| j                         y )NStatus)r[   rf   r   r  r  s     r'   _set_statuszTransaction._set_statusu  s&    {{4(Xt||4r)   zThe status of the transaction.c                     | j                   S r  )r   r  s    r'   _get_status_detailszTransaction._get_status_details|  s    ###r)   c                 \    t        |      | _        | j                  d| j                         y )NStatusDetails)r   r   r  )rA   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 r  )r   r  s    r'   _get_progresszTransaction._get_progress  r:  r)   c                 p    t        j                  |      | _        | j                  d| j                         y )NProgress)r[   rh   r   r  )rA   percents     r'   _set_progresszTransaction._set_progress  s&    G,Z8r)   z+The progress of the transaction in percent.c                     | j                   S r  )r   r  s    r'   _get_progress_packagez!Transaction._get_progress_package  r&  r)   c                 2    | j                  |d      | _        y )Nr   )r  r   )rA   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 r  )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  )rA   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 r  )r   r  s    r'   _get_cancellablezTransaction._get_cancellable  s       r)   c                 p    t        j                  |      | _        | j                  d| j                         y )NCancellable)r[   rk   r   r  )rA   cancellables     r'   _set_cancellablezTransaction._set_cancellable  s)     LL5]D,=,=>r)   z4If it's currently allowed to cancel the transaction.c                     | j                   S r  )r   r  s    r'   _get_term_attachedzTransaction._get_term_attached  s    """r)   c                 p    t        j                  |      | _        | j                  d| j                         y )NTerminalAttached)r[   rk   r   r  )rA   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 r  )r   r  s    r'   _get_required_mediumz Transaction._get_required_medium  rN  r)   c                     | j                  |d      | _        | j                  d| j                          | j                  | j                    y )Nr   RequiredMedium)r  r   r  MediumRequired)rA   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 r  )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)r[   rl   r   r  r  r  )rA   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   r9   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: r=   Nr   r@   rA   rX   rx   s      r'   r  zTransaction.PropertyChanged  s     	hNOr)   rF   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   r@   r   get_exit_string_from_enum)rA   
exit_states     r'   r3  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: r=   Nr  )rA   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: r=   Nr  )rA   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_localenamer[   rf   r$   translationr   r  )rA   
locale_strlangrZ   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 3H=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   r[   rf   r   r  )rA   urlr{   actions       r'   _set_http_proxyzTransaction._set_http_proxy8  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)r[   rk   r   r  )rA   r   s     r'   _set_remove_obsoleted_dependsz)Transaction._set_remove_obsoleted_dependsG  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)r[   rk   r   r  )rA   r   s     r'   _set_allow_unauthenticatedz&Transaction._set_allow_unauthenticatedS  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   ro   r   )rA   r   r{   trans_befores       r'   RunAfterzTransaction.RunAfter_  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rA   r{   s     r'   RunzTransaction.Runx  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r  )
_check_foreign_user_check_simulated_check_authr   putr   r   STATUS_WAITINGr  r   )rA   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)rA   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  )rA   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   r@   r   STATUS_CANCELLINGr  EXIT_CANCELLEDr  r  r   r   r  r   r   AptKitError)rA   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  !?@@sG   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r  )	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)rA   deferreds     r'   r  zTransaction._simulate_real  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 r  )r   r  
disconnectr   _simualted_cbr   errbackcallback)rA   r  r  r  s       r'   r  z%Transaction._on_transaction_simulated/  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   dirnamer  openO_RDWRO_NOCTTYfstatst_uidisattyr[   rf   r   r  ro   close)rA   ttynameslave_fds      r'   _set_terminalzTransaction._set_terminal9  s    ;;%1112244488TXX. 	'www':5(()9G)CDDH'777BII,CD 88H%,,8 ,,?F.R S S 99X&$(KK$8DM((T]]C ,,-=-GHH D 'HHX&+	' 	'  H(()<w)FGGH '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  r  ro   r[   rf   r   r  )rA   debconf_socketr  s      r'   _set_debconfzTransaction._set_debconf]  s     ;;%1112244488TXX. 
	P	Pww~.
 ;;$((* ,, .>@N.O 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rA   r  r{   s      r'   ProvideMediumzTransaction.ProvideMediumz  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   r  r   r  s      r'   r  zTransaction._provide_medium  sl     &&v..##$$%GHH##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rA   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   r  config_file_conflict_resolutionr   r!  s       r'   r   z)Transaction._resolve_config_file_conflict  s     &&v..(($$ &3 4 4,, $$%86%ABB((+v5$$%>%GHH/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  r[   r   r   r   s        r'   r   zTransaction._set_property  s     &&v..55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  rn  r!  ry  rc  rh  r  r  r  r  r1  r(  r   r   r   Pausedr   )r  r   rG  r   r\  r<  rC  rP  )r   r   r  progress_detailsrz  r  status_detailsr  term_attachedr  r(  r  r   r   r   r   r[   rk   r   r   r   r   r   	meta_datar]  downloadspacerQ  r   s     r'   ra   zTransaction._get_properties  s   55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  )rA   	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   )rA   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)rA   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   )r=  getattr_gettext_method)rA   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.
        )r=  r?  _ngettext_method)rA   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  rd   r   r   r   r  r  r  rX   r1  r  r  r   r#  r%  r.  r,  r.  r   r5  r7  r  r9  r?  r2  rA  rD  r3  rH  rK  r   rM  rR  rQ  rT  rX  high_trust_packagesrZ  r_  r]  ra  rd  r  rf  rj  r/  rl  rp  r  rr  ru  rt  rw  r{  rz  r}  r  r  r  r  r0  r  r  r  r  r  r(  r[   r\   r   r   r  r3  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   ra   r  r9  r=  r$   r+   r8   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 
\\(I#'  )	P)	P 
\\(I#&  (E(E 
\\(I#'  )
M)
M 
\\(I#'  )
L)
L86 ; ;
<	9 
\\:&)(0  2"2", ;'))13!3! * *   & &P  2 ;'))13$3$
 A A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-changedNr8   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)rA   r  s     r'   r   zTransactionQueue.__init__   sU      &!'')
.0I0IJr)   c                 ,    t        | j                        S r  )r  r\  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 changedrX  N)r?   r@   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  r\  rp   runrc  )rA   r   r  s      r'   r  zTransactionQueue.put2  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/  r\  popleftr  re  
IndexErrorr?   r@   rc  )rA   r  r  r  _transr&   r  s          r'   r^  z%TransactionQueue._on_transaction_done>  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)r\  r  rc  rA   transactions     r'   r  zTransactionQueue.removeW  s     ;'  "r)   c                 z    | j                   D ]  }|j                           | j                   j                          y)z Remove all items from the queue.N)r\  r   clearrm  s     r'   rp  zTransactionQueue.clear\  s1    ;; 	;K88:	;r)   c                 ,    t        | j                        S )z*Return a list containing all queued items.)listr\  r  s    r'   rc   zTransactionQueue.itemsb  s     DKK  r)   )r   r   r   r   r   SignalFlags	RUN_FIRST__gsignals__r   r`  rc  r  r^  r  rp  rX   rc   r8   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 AptKit 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/   )r:   timeout)AptPackageKitWorkerrX  zDaemon was initialized)0r?   r  r   unix_signal_addPRIORITY_HIGHr   SIGTERM_sigquitr   niceoptions
packagekitr[   r   r   APTKIT_DBUS_PATHr\   r   r   r   NameExistsExceptionr'  criticalsysr  warning
get_objectQuitAPTKIT_DBUS_INTERFACEtimesleepr7   r   dummyr   r  disable_pluginsworker.pkworkerr{  chrootr   r   r   r   _on_queue_changedis_reboot_required_reboot_requiredr@   )	rA   r  r   r   bus_pathr   the_other_guyload_pluginsr{  s	            r'   r   zAptKit.__init__q  s    	&' 	T//!]]D	2 	
d?{nn&DH'HC<<//0C03=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>? #/B/?!A""2G+. # 0

1<<//0C03=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   rc   ActiveTransactionsChanged)rA   r   currentr  queueds        r'   r  zAptKit._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   r9   c                 :    t         j                  d|d|       yr  r>   r  s      r'   r  zAptKit.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, %sNr>   )rA   r  r  s      r'   r  z AptKit.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_timeoutr?   r@   r   r   r   _check_for_inactivityr    re  KeyboardInterruptr  r  s    r'   re  z
AptKit.run  sq    <<''50II./$$%?%)%?%?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   )rA   r   r{   r   r   r   r   r   r   r   r  s              r'   _create_transzAptKit._create_trans  s      99&$((KK 	S#wjjltzz3S'6f$((< ',

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

        Requires the ``org.aptkit.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)r?   r  r  r   rP  r  s     r'   FixIncompleteInstallzAptKit.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.aptkit.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)r?   r  r  r   rQ  r  s     r'   FixBrokenDependszAptKit.FixBrokenDepends  s*     	,-!!%"?"?HHr)   c                 x    t         j                  d       ddi}| j                  t        j                  ||      S )aH  Download the latest information about available packages from the
        repositories and rebuild the package cache.

        Requires the ``org.aptkit.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_listNr8  r?   r  r  r   r  )rA   r{   r   s      r'   UpdateCachezAptKit.UpdateCache  s@     	+, $'!!%"9"96)/ " 1 	1r)   c                 x    t         j                  d       d|i}| j                  t        j                  ||      S )aB  Update the cache from the repositories defined in the given
        sources.list only.

        Requires the ``org.aptkit.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-aptkit.list` or the name
            of the snippet in :file:`/etc/apt/sources.list.d/`, e.g.
            :file:`ppa-aptkit.list`.
        :type sources_list: s

        :returns: The D-Bus path of the new transaction object which
            performs this action.
         z!UpdateCachePartially() was calledr  r8  r  )rA   r  r{   r   s       r'   UpdateCachePartiallyzAptKit.UpdateCachePartially(  s@    & 	45 ,/!!%"9"96)/ " 1 	1r)   rF  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.aptkit.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   )r?   r  _check_package_namesr  r   rH  rA   package_namesr{   s      r'   RemovePackageszAptKit.RemovePackagesA  sU    " 	4mD!!-0!!%"<"<f,.M2r2+N " P 	Pr)   rW   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.aptkit.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_moder8  )r?   r  r  r   rK  )rA   r  r{   s      r'   UpgradeSystemzAptKit.UpgradeSystemX  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.aptkit.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   r8   )r  s    r'   check_empty_listz/AptKit.CommitPackages.<locals>.check_empty_list  s    rd{	
r)   r  )r?   r  r  r  r   r  )rA   install	reinstallr  purgeupgrade	downgrader{   r  r  packages_lstr   s               r'   CommitPackageszAptKit.CommitPackagesn  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.aptkit.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  )r?   r  r  r  r   r  r  s      r'   InstallPackageszAptKit.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.aptkit.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  )r?   r  r  r  r   rJ  r  s      r'   UpgradePackageszAptKit.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.aptkit.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	keyserverr8  )r?   r  r  r   r  )rA   r  r  r{   s       r'   AddVendorKeyFromKeyserverz AptKit.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.aptkit.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   r8  )r?   r  r  r   rM  )rA   r   r{   s      r'   AddVendorKeyFromFilezAptKit.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.aptkit.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fingerprintr8  )r?   r  r  r   rO  )rA   r  r{   s      r'   RemoveVendorKeyzAptKit.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.aptkit.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   forcer8  )r?   r  r  r   r  )rA   r   r  r{   s       r'   InstallFilezAptKit.InstallFile  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.aptkit.clean``
        :ref:`PolicyKit privilege <policykit>`.

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

        Requires the ``org.aptkit.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   )r?   r  joinr  r   rR  )rA   r   r  r{   s       r'   ReconfigurezAptKit.ReconfigureI  s[    ( 	/#((82DDE!!%"8"8&,."b"b+I*4h)? " A 	Ar)   sssasssc                     t         j                  d||||||       | j                  t        j                  |||||||d      S )a]  Add given repository to the sources list.

        Requires the ``org.aptkit.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sourcesfiler8  )r?   r  r  r   r  )rA   r  r  r  r  r  r  r{   s           r'   AddRepositoryzAptKit.AddRepositoryc  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.aptkit.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' 	componentr8  )r?   r  r  r   rU  )rA   r  r{   s      r'   EnableDistroComponentzAptKit.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.aptkit.get-trusted-vendor-keys``
        :ref:`PolicyKit privilege <policykit>`.

        :returns: Fingerprints of all installed keys.
        z!GetTrustedVendorKeys() was called)r?   r  _get_trusted_vendor_keysr  s     r'   GetTrustedVendorKeyszAptKit.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   )rA   r{   r  fingerprintss       r'   r  zAptKit._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   )r?   r@   r   rc   r   r  r  )rA   r  r  r  s       r'   GetActiveTransactionszAptKit.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)r?   r  r@   r    quit)rA   r  s     r'   r  zAptKit.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.aptkit.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_namer8  )r?   r  r  r   r  )rA   r  r  r  r{   s        r'   AddLicenseKeyzAptKit.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   r+  N)r   PK_ACTION_CHANGE_CONFIGr  r   r  r  
set_configr[   rk   rh   r   r   )rA   ru   rN   rx   r{   r  s         r'   r   zAptKit._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   r  rematchREGEX_VALID_PACKAGENAMEREGEX_VALID_VERSIONREGEX_VALID_RELEASE)rA   	pkg_namesfullnamerN   versionreleasesep	auto_flags           r'   r  zAptKit._check_package_names  s     " 	5H%5h%?"D'7#'>>##6 D#y,(()@,5*6 7 7883T:(()H,0*1 2 2#!4g>(()C,3*4 5 5#!4g>(()C,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  r[   rh   r  
get_configrk   r  r   s     r'   ra   zAptKit._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  )rA   rs   s     r'   r  zAptKit._sigquit0  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)zgShutdown the daemon if it has been inactive for time specified
        in APTKIT_IDLE_TIMEOUT.
        zChecking for inactivityzQuitting due to inactivityNFT)r?   r@   r   r  last_action_timestampr  r   main_context_defaultpendingr  r	   r  r  )rA   	timestamps     r'   r  zAptKit._check_for_inactivity4  s     			+,JJ%%;;	

!!''--/779		i'*==JJHH12IIdOr)   )TN)NN),r   r   r   r   r   r  r[   r\   r   r  r  r  re  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  ra   r  r  r8   r)   r'   r   r   h  s   <,|8 
\\(=#'  )	J)	J 
\\(=#(  *#*#
 	  	  /'))13M3M /'))13
I3
I /'))13131  /'*#)13131, /'+3)13P3P( /'*#)13C3C& /'5S)1319319h /'+3)13P3P. /'+3)13P3P. /'+3)13K3K0 /'*#)13A3A$ /'*#)13O3O$ /'+3)13C3C0 /'))13
<3
< /',C)13A3A. /'0)13 G3 GF /'*#)13C3C, /'))13
53
5 # # 
\\.&(  ?
?
 
\\.&((5  77 /',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)r[   rf   UnicodeDecodeErrordecode)ri  rZ   s     r'   r   r   D  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--debugr@   z$Show internal processing informationz-rz	--replacer'  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  rR   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_argsr@   r?   setLevelloggingDEBUGINFO_console_handlerr$  r[   
SessionBusr   r'  Profileruncallre  
dump_statsprint_stats)parserr  argsr   daemonr'  profilers          r'   mainr8  L  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G%F??$$GOO,

r)   )rY   )ar   
__author____all__rZ  	xml.etreer   r$   hashlibr   r   r+  logging.handlersoptparser   r   r  r   r  r  r   gi.repositoryr   r   dbus.exceptionsr[   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  r@  rB  r  r  r   r   r   r	   r
   r   r
  r  r  glibDBusGMainLoopputenv	getLoggerr?   handlersSysLogHandler
LOG_DAEMON_syslog_handlerr*  r-  	Formatter_syslog_formattersetFormatter
addHandlerStreamHandlerr.  _console_formatterr   	setlocaleLC_ALLr(  r  r\   r]   r7   r   r   r   r   r8  r8   r)   r'   <module>rY     s  	4 5
B  !      ! 	 	  
   '        : : ,  2 O  $ 0;;#O! O"$   " $< !       B  3 ,           5 
		&
HJ g!$&&44!!//:: 5 <O W\\*))) +8 9  !23 NN?#(7((* % '4&*,    0 1   Gn-	KFV]]B'
s$$ slSO* SOl M!w M!`YZ Yx<;i>	 || KKKIJKs    A9I( 9I/ (I,/ JJ