
    |f@                         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m	Z	 d dl
mZ d dlmZ dZdZdZ ed	       d
 Z G d dej$                        Z G d dej(                  j*                  e      Zy)    )GLibN)SourceEntry)DBusGMainLoop)SoftwarePropertieszcom.ubuntu.SoftwareProperties/T)set_as_defaultc                 N    t         j                  dk  r| j                  d      S | S )N3zutf-8)sysversionencode)strings    P/usr/lib/python3/dist-packages/softwareproperties/dbus/SoftwarePropertiesDBus.py_to_unicoder   (   s"    [[3==!!M    c                       e Zd ZdZy)PermissionDeniedByPolicyz6com.ubuntu.SoftwareProperties.PermissionDeniedByPolicyN)__name__
__module____qualname___dbus_error_name r   r   r   r   .   s    Or   r   c                   T    e Zd Zd+dZ fdZ fdZej                  j                  e	d      d        Z
ej                  j                  e	d      d        Zej                  j                  e	d      d        Zej                  j                  e	d      d	        Zej                  j                  e	d      d
        Zej                  j                  e	dddd      d,d       Zej                  j                  e	dddd      d,d       Zej                  j                  e	dddd      d,d       Zej                  j                  e	dddd      d,d       Zej                  j                  e	dddd      d,d       Zej                  j                  e	dddd      d,d       Zej                  j                  e	dddd      d,d       Zej                  j                  e	dddd      d,d       Zej                  j                  e	dddd      d,d       Zej                  j                  e	dddd      d,d       Zej                  j                  e	dddd      d,d       Zej                  j                  e	dddd      d,d       Zd Zd Zej                  j                  e	dddd      d,d       Zej                  j                  e	ddd d      d,d!       Zej                  j                  e	ddd d      d,d"       Z ej                  j                  e	ddd d      d,d#       Z!ej                  j                  e	dddd      d,d$       Z"ej                  j                  e	dddd      d,d%       Z#ej                  j                  e	dddd      d,d&       Z$ej                  j                  e	dddd      d,d'       Z%ej                  j                  e	dddd      d,d(       Z&ej                  j                  e	dddd      d,d)       Z'd* Z( xZ)S )-SoftwarePropertiesDBusc                 4   t        j                  | |||d       d | _        d | _        t        j
                  j                  t        |      }t        j
                  j                  j                  | |t               d| _
        t        j                  d       y )NT)optionsdatadirrootdirdeb822)buszwaiting for connections)r   __init__	dbus_infopolkitdbusserviceBusNameDBUS_INTERFACE_NAMEObject	DBUS_PATHenforce_polkitloggingdebug)selfr    r   r   r   bus_names         r   r!   zSoftwarePropertiesDBus.__init__3   sw    ##D'7,3D	B <<''(;'E$$T8Y?"/0r   c                 J    t         t        |           | j                          y N)superr   save_sourceslistSourcesListModifiedr-   	__class__s    r   r2   z'SoftwarePropertiesDBus.save_sourceslistB   s    $d<>  "r   c                 J    t         t        |           | j                          y r0   )r1   r   write_configConfigModifiedr4   s    r   r7   z#SoftwarePropertiesDBus.write_configE   s    $d8:r    )dbus_interface	signaturec                 .    t        j                  d       y)0 emit signal when the sources.list got modified zSourcesListModified signalNr+   r,   r-   s    r   r3   z*SoftwarePropertiesDBus.SourcesListModifiedJ   s     	23r   c                 .    t        j                  d       y)r=   zConfigModified signalNr>   r?   s    r   r8   z%SoftwarePropertiesDBus.ConfigModifiedO   s     	-.r   c                 .    t        j                  d       y)z, emit signal when the apt keys got modified zKeysModified signalNr>   r?   s    r   KeysModifiedz#SoftwarePropertiesDBus.KeysModifiedT   s     	+,r   c                 .    t        j                  d       y)z6 emit signal when the policykit authentication failed zAuth signalNr>   r?   s    r   
AuthFailedz!SoftwarePropertiesDBus.AuthFailedY   s     	m$r   c                 .    t        j                  d       y)z( emit signal when adding a cdrom failed zCdrom scan failed signalNr>   r?   s    r   CdromScanFailedz&SoftwarePropertiesDBus.CdromScanFailed^   s     	01r   senderconn)sender_keywordconnection_keywordin_signatureout_signaturec                 J    | j                  ||d       | j                          y Nz*com.ubuntu.softwareproperties.applychanges)_check_policykit_privilegerevertr-   rG   rH   s      r   RevertzSoftwarePropertiesDBus.Reverte   s$     	''DF	Hr   c                 $    | j                          y r0   )reload_sourceslistrQ   s      r   ReloadzSoftwarePropertiesDBus.Reloadm   s     	!r   sc                 ^    | j                  ||d       | j                  t        |             y rN   )rO   enable_child_sourcer   r-   templaterG   rH   s       r   EnableChildSourcez(SoftwarePropertiesDBus.EnableChildSourcet   s.     	''DF	H  X!67r   c                 ^    | j                  ||d       | j                  t        |             y rN   )rO   disable_child_sourcer   rY   s       r   DisableChildSourcez)SoftwarePropertiesDBus.DisableChildSource|   s.     	''DF	H!!+h"78r   c                 ^    | j                  ||d       | j                  t        |             y rN   )rO   enable_componentr   r-   	componentrG   rH   s       r   EnableComponentz&SoftwarePropertiesDBus.EnableComponent   s.     	''DF	Hk)45r   c                 ^    | j                  ||d       | j                  t        |             y rN   )rO   disable_componentr   ra   s       r   DisableComponentz'SoftwarePropertiesDBus.DisableComponent   s.     	''DF	H{956r   c                 J    | j                  ||d       | j                          y rN   )rO   enable_source_code_sourcesrQ   s      r   EnableSourceCodeSourcesz.SoftwarePropertiesDBus.EnableSourceCodeSources   s'     	''DF	H'')r   c                 j    | j                  ||d       | j                          | j                          y rN   )rO   disable_source_code_sourcesr2   rQ   s      r   DisableSourceCodeSourcesz/SoftwarePropertiesDBus.DisableSourceCodeSources   s3     	''DF	H((*r   c                 ^    | j                  ||d       | j                  t        |             y rN   )rO   toggle_source_user   r-   sourcerG   rH   s       r   ToggleSourceUsez&SoftwarePropertiesDBus.ToggleSourceUse   s.     	''DF	H{623r   ssbc                 p    | j                  ||d       | j                  t        |      t        |            S rN   )rO   replace_source_entryr   )r-   oldnewrG   rH   s        r   ReplaceSourceEntryz)SoftwarePropertiesDBus.ReplaceSourceEntry   s=     	''DF	H((k#.0 	0r   c                 ^    | j                  ||d       | j                  t        |             y rN   )rO   change_main_download_serverr   )r-   serverrG   rH   s       r   ChangeMainDownloadServerz/SoftwarePropertiesDBus.ChangeMainDownloadServer   s.     	''DF	H((V)<=r   c                 J    | j                  ||d       | j                          y rN   )rO   _add_cdrom_sourcerQ   s      r   AddCdromSourcez%SoftwarePropertiesDBus.AddCdromSource   s'     	''DF	H r   c                     t        j                         }dddddddddddd|j                  z  g}t        j                  |      }t        j                  d	| j                  ||       y
)z  add a (already inserted) cdrom z	apt-cdromaddz-ozDebug::aptcdrom=1zDebug::identcdrom=1zacquire::cdrom::AutoDetect=1zacquire::cdrom::NoMount=1zDir::Etc::sourcelist=%si  N)tempfileNamedTemporaryFilename
subprocessPopenr   timeout_add_wait_for_cdrom_scan_finish)r-   tmpcmdps       r   r~   z(SoftwarePropertiesDBus._add_cdrom_source   sq    ))+ E(*30.9 S!d>>3Gr   c                 6   |j                         y|j                         }|dk7  r| j                          yd}t        |j                        D ]  }|} |dk7  r?| j                  j
                  j                  dt        |             | j                          y)z= glib timeout helper to wait for the cdrom scanner to finish Tr   Fr9   )	pollrF   openr   sourceslistlistinsertr   set_modified_sourceslist)r-   r   r   reslinexs         r   r   z2SoftwarePropertiesDBus._wait_for_cdrom_scan_finish   s     668ffh!8  "chh 	AD	2:!!((K,=>))+r   c                 L    | j                  ||d       | j                  |       y rN   )rO   set_popcon_pariticipation)r-   participatesrG   rH   s       r   SetPopconPariticipationz.SoftwarePropertiesDBus.SetPopconPariticipation   s)     	''DF	H&&|4r   ic                 L    | j                  ||d       | j                  |       y rN   )rO   set_update_automation_levelr-   staterG   rH   s       r   SetUpdateAutomationLevelz/SoftwarePropertiesDBus.SetUpdateAutomationLevel   )     	''DF	H((/r   c                 L    | j                  ||d       | j                  |       y rN   )rO   set_release_upgrades_policyr   s       r   SetReleaseUpgradesPolicyz/SoftwarePropertiesDBus.SetReleaseUpgradesPolicy   r   r   c                 ^    | j                  ||d       | j                  t        |             y rN   )rO   set_update_intervalint)r-   daysrG   rH   s       r   SetUpdateIntervalz(SoftwarePropertiesDBus.SetUpdateInterval  s-     	''DF	H  T+r   c                 ~    | j                  ||d       | j                  t        |             | j                          y rN   )rO   add_source_from_liner   rB   )r-   
sourceLinerG   rH   s       r   AddSourceFromLinez(SoftwarePropertiesDBus.AddSourceFromLine  s:     	''DF	H!!+j"9:r   c                 ^    | j                  ||d       | j                  t        |             y rN   )rO   remove_sourcer   ro   s       r   RemoveSourcez#SoftwarePropertiesDBus.RemoveSource  s.     	''DF	H;v./r   c                 r    | j                  ||d       | j                  |      }|r| j                          |S rN   )rO   add_keyrB   )r-   pathrG   rH   r   s        r   AddKeyzSoftwarePropertiesDBus.AddKey!  s=     	''DF	Hll4 
r   c                 r    | j                  ||d       | j                  |      }|r| j                          |S rN   )rO   add_key_from_datarB   )r-   keyDatarG   rH   r   s        r   AddKeyFromDataz%SoftwarePropertiesDBus.AddKeyFromData,  s?     	''DF	H$$W-
r   c                 r    | j                  ||d       | j                  |      }|r| j                          |S rN   )rO   
remove_keyrB   )r-   keyidrG   rH   r   s        r   	RemoveKeyz SoftwarePropertiesDBus.RemoveKey7  s=     	''DF	Hooe$
r   c                 p    | j                  ||d       | j                         }|r| j                          |S rN   )rO   update_keysrB   )r-   rG   rH   r   s       r   
UpdateKeysz!SoftwarePropertiesDBus.UpdateKeysB  s=     	''DF	H 
r   c           
      $   ||y| j                   sy| j                  ,t        j                  |j	                  ddd      d      | _        | j                  j                  |      }| j                  >t        j                  t        j                         j	                  ddd      d      | _        	 | j                  j                  dd	t        j                  |d
      if|ddit        j                  d
      dd      \  }}}|sAt        j                  d||||t!        |      fz         | j#                          t%        |      y# t        j                  $ r4}|j                  dk(  rd| _        | j                  |||      cY d}~S  d}~ww xY w)a  Verify that sender has a given PolicyKit privilege.

        sender is the sender's (private) D-BUS name, such as ":1:42"
        (sender_keyword in @dbus.service.methods). conn is
        the dbus.Connection object (connection_keyword in
        @dbus.service.methods). privilege is the PolicyKit privilege string.

        This method returns if the caller is privileged, and otherwise throws a
        PermissionDeniedByPolicy exception.
        Nzorg.freedesktop.DBusz/org/freedesktop/DBus/BusFzorg.freedesktop.PolicyKit1z%/org/freedesktop/PolicyKit1/Authorityz$org.freedesktop.PolicyKit1.Authorityzsystem-bus-namer      )variant_levelr9   iX  )timeoutz)org.freedesktop.DBus.Error.ServiceUnknownzW_check_polkit_privilege: sender %s on connection %s pid %i is not authorized for %s: %s)r*   r"   r$   	Interface
get_objectGetConnectionUnixProcessIDr#   	SystemBusCheckAuthorizationStringUInt32DBusExceptionr   _check_polkit_privileger+   r,   strrD   r   )	r-   rG   rH   	privilegepidis_auth_detailses	            r   rO   z1SoftwarePropertiesDBus._check_policykit_privilegeN  s    >dl""  >>!!^^DOO<R+U-45KMDNnn77? ;;..)9)D)D,7*@ 78DK	$(KK$B$B&VUV1W(XYBxQS %C %J!Wa MMsT3	3w<@A BOO*955	  !! 	!!%PP"33FD)LL	s%   1AE F(F
F	F

F)NNr   )NN)*r   r   r   r!   r2   r7   r$   r%   signalr'   r3   r8   rB   rD   rF   methodrR   rU   r[   r^   rc   rf   ri   rl   rq   rx   r|   r   r~   r   r   r   r   r   r   r   r   r   r   r   rO   __classcell__)r5   s   @r   r   r   1   s   1#
 
\\(;rJ4 K4 
\\(;rJ/ K/ 
\\(;rJ- K- 
\\(;rJ% K% 
\\(;rJ2 K2 
\\,(0V&(  <<
 
\\,(0V&(  <"<" 
\\,(0V&)  =8=8
 
\\,(0V&)  =9=9
 
\\,(0V&)  =6=6
 
\\,(0V&)  =7=7
 
\\,(0V&(  <*<*
 
\\,(0V&(  < <  
\\,(0V&)  =4=4
 
\\,(0V&*#  ?0?0 
\\,(0V&(  <><> 
\\,(0V&(  <!<!
H * 
\\,(0V&)  =5=5
 
\\,(0V&)  =0=0
 
\\,(0V&)  =0=0
 
\\,(0V&)  =,=, 
\\,(0V&)  == 
\\,(0V&)  =0=0 
\\,(0V&)  >> 
\\,(0V&)  >> 
\\,(0V&)  >> 
\\,(0V&(  ==06r   r   )gi.repositoryr   dbus.servicer$   r+   r   r   r   aptsources.sourceslistr   dbus.mainloop.glibr   %softwareproperties.SoftwarePropertiesr   DBUS_BUS_NAMEr)   r'   r   r   r   r%   r(   r   r   r   r   <module>r      sn   *      
 . , D/	5  T "Pt11 PM6T\\002D M6r   