Ë
    ƒìõSö  ã                   ó²   — d Z d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Zddl	Z	ddl
mZ  ej                  d«      Z G d„ de«      Zd„ Zed	k(  r e«        yy)
zÞ
Integration of debconf on the client side

Provides the DebconfProxy class which allows to run the debconf frontend
as normal user by connecting to the root running debconf through the
socket of the passthrough frontend.
)ÚDebconfProxyé    N)ÚGLibzAptClient.DebconfProxyc                   ó<   — e Zd ZdZd
d„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
y)r   z§The DebconfProxy class allows to run the debconf frontend
    as normal user by connecting to the root debconf through the socket of the
    passthrough frontend.
    Nc                 óì  — || _         d| _        |€Jt        j                  d¬«      | _        t        j
                  j                  | j                  d«      | _         t        j                  d| j                   z  «       t        j                  t        j                  t        j                  «      | _	        | j                  j                  | j                   «       || _        d| _        d| _        g | _        y)a  Initialize a new DebconfProxy instance.

        Keyword arguments:
        frontend -- the to be used debconf frontend (defaults to gnome)
        socket_path -- the path to the socket of the passthrough frontend.
            Will be created if not specified
        Nz
aptdaemon-)Úprefixzdebconf.socketzdebconf socket: %s)Úsocket_pathÚtemp_dirÚtempfileÚmkdtempÚosÚpathÚjoinÚlogÚdebugÚsocketÚAF_UNIXÚSOCK_STREAMÚbindÚfrontendÚ_listener_idÚ_active_connÚ
_watch_ids)Úselfr   r   s      ú3/usr/lib/python3/dist-packages/aptdaemon/debconf.pyÚ__init__zDebconfProxy.__init__2   s±   € ð 'ˆÔØˆŒØÐÜ$×,Ñ,°LÔAˆDŒMÜ!Ÿw™wŸ|™|¨D¯M©MÐ;KÓLˆDÔÜ�	‰	Ð&¨×)9Ñ)9Ñ9Ô:Ü—m‘m¤F§N¡N´F×4FÑ4FÓGˆŒØ�‰×Ñ˜×)Ñ)Ô*Ø ˆŒØ ˆÔØ ˆÔØˆ�ó    c                 óÊ   — t        j                   t        j                  «      }d|d<   d|d<   | j                  |d<   t        j
                  t        j                  k(  rd|d<   |S )zcReturns a dictonary of the environment variables required by
        the debconf frontend.
        ÚconfigdbÚDEBCONF_DB_REPLACEzPipe{infd:none outfd:none}ÚDEBCONF_DB_OVERRIDEÚDEBIAN_FRONTENDú.ÚDEBCONF_DEBUG)Úcopyr   Úenvironr   r   ÚlevelÚloggingÚDEBUG)r   Úenvs     r   Ú_get_debconf_envzDebconfProxy._get_debconf_envG   sZ   € ô �i‰iœŸ
™
Ó#ˆØ$.ˆÐ Ñ!Ø%AˆÐ!Ñ"Ø!%§¡ˆÐÑÜ�9‰9œŸ™Ò%Ø#&ˆC�Ñ Øˆ
r   c                 óþ   — t        j                  d«       | j                  j                  d«       t	        j
                  | j                  t        j                  t        j                  | j                  «      | _	        y)zStart listening on the socket.zdebconf.start()é   N)
r'   r   r   Úlistenr   Úio_add_watchÚPRIORITY_DEFAULT_IDLEÚIO_INÚ_accept_connectionr   ©r   s    r   ÚstartzDebconfProxy.startS   sR   € ä�‰Ð'Ô(Ø�‰×Ñ˜1ÔÜ ×-Ñ-Ø�K‰Kœ×3Ñ3Ü�J‰J˜×/Ñ/ó1ˆÕr   c                 ó|  — t        j                  d«       | j                  j                  «        | j                  �&t        j                  | j                  «       d| _        | j                  r@	 t        j                  | j                  «       t        j                  | j                  «       yy# t        $ r Y yw xY w)zStop listening on the socket.zdebconf.stop()N)r'   r   r   Úcloser   r   Úsource_remover	   r   Úremover   ÚrmdirÚOSErrorr2   s    r   ÚstopzDebconfProxy.stop[   sŽ   € ä�‰Ð&Ô'Ø�‰×ÑÔØ×ÑÐ(Ü×Ñ˜t×0Ñ0Ô1Ø $ˆDÔØ�=Š=ðÜ—	‘	˜$×*Ñ*Ô+Ü—‘˜Ÿ™Õ'ð øô ò Ùðús   Á/>B/ Â/	B;Â:B;c                 óª  — | j                   rt        j                  d«       y |j                  «       \  }}|| _         t        j
                  t        j                  z  t        j                  z  t        j                  z  }t        j                  dgt        j                  t        j                  | j                  «       ¬«      | _        t	        j                  |t        j                  || j                   | j                  j"                  «       t	        j                  | j                  j$                  t        j                  || j&                  |«       y)NzDelaying connectionTzdebconf-communicate)ÚstdinÚstdoutr)   )r   r   r   Úacceptr   r0   ÚIO_ERRÚIO_HUPÚIO_NVALÚ
subprocessÚPopenÚPIPEr*   Úhelperr.   ÚPRIORITY_HIGH_IDLEÚ
_copy_connr<   r=   Ú_copy_stdout)r   r   Ú	conditionÚconnÚaddrÚmasks         r   r1   zDebconfProxy._accept_connectioni   sí   € Ø×ÒÜ�I‰IÐ+Ô,ØØ"�V—]‘]“_‰
ˆˆdØ ˆÔÜ�z‰zœDŸK™KÑ'¬$¯+©+Ñ5¼¿¹ÑDˆÜ ×&Ñ&Ð(=Ð'>Ü-7¯_©_Ü.8¯o©oØ+/×+@Ñ+@Ó+BôDˆŒô 	×Ñ˜$¤× 7Ñ 7Ø §¡°·±×1BÑ1Bô	Dä×Ñ˜$Ÿ+™+×,Ñ,¬d×.EÑ.EØ × 1Ñ 1°4ô	9àr   c                 óÐ  — t        j                  d«       	 |j                  «       }|r(t        j                  d|«       |j	                  |«       y	 t        j                  d«       | j                  j                  j                  «        | j                  j                  «        d| _        y# t
        j                  t        f$ r}t        j                  |«       Y d}~ŒŽd}~ww xY w)zaCallback to copy data from the stdout of debconf-communicate to
        the passthrough frontend.rH   zFrom debconf: %sTNzStop reading from stdoutF)r'   r   Úreadliner   Úsendr   ÚerrorÚIOErrorrE   r=   r5   r   )r   ÚsourcerI   rJ   Údebconf_datarP   s         r   rH   zDebconfProxy._copy_stdoutz   s³   € ô 	�‰�nÔ%ð	Ø!Ÿ?™?Ó,ˆLÙÜ—	‘	Ð,¨lÔ;Ø—	‘	˜,Ô'Øð ô 	�	‰	Ð,Ô-Ø�‰×Ñ× Ñ Ô"Ø×Ñ×ÑÔ!Ø ˆÔØøô —‘œgÐ&ò 	Ü�I‰I�e×Ñûð	ús   —9B- Â-C%ÃC Ã C%c                 ó°  — t        j                  d«       	 |j                  d«      }|r8t        j                  d|«       |j	                  |«       |j                  «        y	 t        j                  d«       | j                  j                  j                  «        y# t        j                  t        f$ r}t        j                  |«       Y d}~Œmd}~ww xY w)z\Callback to copy data from the passthrough frontend to stdin of
        debconf-communicate.rG   i   zFrom socket: %sTNzStop reading from connF)r'   r   Úrecvr   ÚwriteÚflushr   rP   rQ   rE   r<   r5   )r   rR   rI   r<   Úsocket_datarP   s         r   rG   zDebconfProxy._copy_conn�   s¤   € ô 	�‰�lÔ#ð	Ø Ÿ+™+ dÓ+ˆKÙÜ—	‘	Ð+¨[Ô9Ø—‘˜KÔ(Ø—‘”Øð	 ô 	�	‰	Ð*Ô+Ø�‰×Ñ×ÑÔ!Øøô —‘œgÐ&ò 	Ü�I‰I�e×Ñûð	ús   —A
B ÂCÂ6CÃC)ÚgnomeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r*   r3   r:   r1   rH   rG   © r   r   r   r   +   s*   „ ñó
ò*
ò1òòò"ó&r   r   c                  ó8  — t        j                  t         j                  ¬«       d} t        j                  j                  | «      rt        j                  | «       t        d| «      }|j                  «        t        j                  «       }|j                  «        y)a4  Run the DebconfProxy from the command line for testing purposes.

    You have to execute the following commands before in a separate terminal:
    $ echo "fset debconf/frontend seen false" | debconf-communicate
    $ export DEBCONF_PIPE=/tmp/debconf.socket
    $ dpkg-reconfigure debconf -f passthrough
    )r&   z/tmp/debconf.socketrY   N)r'   ÚbasicConfigr(   r   r   Úexistsr7   r   r3   r   ÚMainLoopÚrun)r   ÚproxyÚloops      r   Ú_testrf       s`   € ô ×ÑœgŸm™mÕ,Ø'€KÜ	‡w�w‡~�~�kÔ"Ü
�	‰	�+ÔÜ˜ +Ó.€EØ	‡K�K„MÜ�=‰=‹?€DØ‡H�H…Jr   Ú__main__)r]   Ú__all__r$   r'   r   Úos.pathr   rB   r
   ÚsysÚgi.repositoryr   Ú	getLoggerr   Úobjectr   rf   rZ   r^   r   r   ú<module>rn      sg   ðñð0 €ã Û Û 	Û Û Û Û Û 
å à€g×ÑÐ0Ó1€ôr�6ô ròjð" ˆzÒÙ	…Gð r   