
    S$                         d Z dZdZddlZddlZddlZ ej                  d      Z G d de      Z	 G d d	e      Z
d
 Zedk(  r e        yy)zHandling configuration files.z%Sebastian Heinlein <devel@glatzor.de>)ConfigWriter    NzAptDaemon.ConfigWriterc                   "    e Zd ZdZd Zd Zd Zy)Valuea  Represents a value with position information.

    .. attribute:: string
        The value string.

    .. attribute:: line
        The line number of the configuration file in which the value is set.

    .. attribute:: start
        The position in the line at which the value starts.

    .. attribute:: end
        The position in the line at which the value ends.

    .. attribute:: quotes
        The outer qoutes of the value: ' or "
    c                 J    d| _         || _        d | _        || _        || _        y )N )stringstartendlinequotes)selfr   r	   r   s       2/usr/lib/python3/dist-packages/aptdaemon/config.py__init__zValue.__init__4   s%    
	    c                      | j                   |k(  S )N)r   )r   others     r   __cmp__zValue.__cmp__;   s    {{e##r   c           	      p    d| j                   d| j                  d| j                  d| j                  d	S )NzValue: 'z' (line z: z to ))r   r   r	   r
   )r   s    r   __repr__zValue.__repr__>   s(    48KK48JJJ 	Jr   N)__name__
__module____qualname____doc__r   r   r    r   r   r   r       s    $$Jr   r   c                       e Zd ZdZd Zd Zy)r   z!Modifies apt configuration files.c           	         i }d}d}d}g }d}d}g }	d}
d}t        |      D ]I  \  }}t        |      D ]4  \  }}|s|dk(  r
|dk(  rd}d}|r|dk(  r|dk(  r
d}d}|dd }.|rn|s|dk(  r|dk(  s|d	k(  r	d}|dd } ^|d
v rH|r|j                  |k(  r||_        | }n|st        |||      }| }n|xj                  |z  c_        n|r|xj                  |z  c_        n|r"|dk(  r|dk(  r|j                  |dd        d}n^|j                         s|dv r||j                         z  }n5|dk(  r|
r|	j                  |       d}|	r=t        j                  ddj                  |      |	       |	|dj                  |      <   g }	nb|r;t        j                  ddj                  |      |       ||dj                  |      <   n%t        j                  ddj                  |             d}|dkD  r|j                          n`g }n]|dk(  r|dz  }d}
nP|dk(  r|dz  }|r|j                  |       d}d}
n.|dv r|r(|j                  |       d}d}
nt        d|d|d      |}7 L |S )zParse an ISC based apt configuration.

        :param lines: The list of lines of a configuration file.

        :returns: Dictionary of key, values found in the parsed configuration.
        FNr   Tr   */#z'":z/-:._+;zFound %s "%s"z::zSkipping empty key %s}   {z	
 zUnknown char 'z' in line: '')	enumerater   r
   r   r   appendisalphalowerlogdebugjoinpop
ValueError)r   linesoptions
in_commentin_value	prev_charoptionvalueoption_name
value_listin_bracketslevelline_nor   char_nochars                   r   parsezConfigWriter.parseG   s    
	
&u- K	!MGT!*4 J!!dcki36F!%J "IDCKI4D!&J "I"-cr"2K!	S8H'+s{ !#I"-cr"2KU]ELLD$8$+	'/<" %gw ='/<,LLD(L TS[Y#5EMM+cr"23"$K\\^tx'74::</KS[""))%0 $ !		"3TYYv5F",.5?		& 12%'
		"3TYYv5FN5:		& 12		"9499V;LM Eqy

!#S[QJE"'KS[QJE"k2&("&KW_"k2&(&+$&*D&2 3 3 	UJ!K	!X r   c                 ,   |du rd}n|du rd}nt        |      }t        j                  j                  t        j
                  j                  d      t        j
                  j                  d            }t        j                  |      D ]  }||k  r
t        t        j                  j                  ||            5 }|j                         }ddd       | j                        }	 ||j                            }	|dk(  r|	j                  j                         dv s9|dk(  r|	j                  j                         d	v st        |      |	j                  k(  r||k(  rH||	j                     }
|
d|	j                  d
z    }||z  }||
|	j                  d z  }|||	j                  <   n d||	j                     z  ||	j                  <   	 t        t        j                  j                  ||      d      5 }t$        j'                  d|       |j)                  |       ddd        t        j                  j+                  t        j                  j                  ||            sct        t        j                  j                  ||      d      5 }t$        j'                  d       |d|d}
|j-                  |
       ddd       yy# 1 sw Y   xY w# t         $ r$ ||k(  r|j#                  |d|d       nY mY 7w xY w# 1 sw Y   ~xY w# 1 sw Y   yxY w)a  Change the value of an option in the configuration.

        :param option: The name of the option, e.g.
            'apt::periodic::AutoCleanInterval'.
        :param value: The value of the option. Will be converted to string.
        :param defaultfile: The filename of the ``/etc/apt/apt.conf.d``
            configuration snippet in which the option should be set.
            If the value is overriden by a later configuration file snippet
            it will be disabled in the corresponding configuration file.
        TtrueFfalsezDir::EtczDir::Etc::PartsN)yeswithonenable)nowithoutoffdisabler%   z// %sz 'z';
wzWritting %s)strospathr.   apt_pkgconfigfind_dirlistdiropen	readlinesr?   r+   r   r   r	   r
   KeyErrorr)   r,   r-   
writelinesexistswrite)r   r6   r7   defaultfile	etc_partsfilenamefdr1   rP   valr   new_lines               r   	set_valuezConfigWriter.set_value   s    D=Ee^EJEGGLL!8!8!D!(!8!89J!KM	

9- $	%H+%bggll9h78 'B'ZZ&F@V\\^, f_

((* /9 9')))+ 0; ;Uszz1{* ?D#NSYY]3H%HSWWX.H&.E#((O
 '.chh&?E#((Obggll9h7= %		-2e$% %E$	%J ww~~bggll9kBCbggll9k:C@ B		-2'-u5  DE' '
  {*LL!?@ A4% % s6   <K 'K,(K=0L
 K
	&K:9K:=L	
LN)r   r   r   r   r?   r_   r   r   r   r   r   C   s    +]~?r   r   c                     t        j                          t               } t        t	        j
                  d            D ]/  }t        d|z        j                         }| j                  |       1 t        | j                  ddd             y )Nz/etc/apt/apt.conf.d/z/etc/apt/apt.conf.d/%sz	huhu::abclumpi	10glatzor)rO   init_configr   sortedrM   rR   rS   rT   r?   printr_   )cwr[   r1   s      r   mainrg      sn    	B2::&<=> -89CCE
 
2<<Wk:<r   __main__)r   
__author____all__loggingrM   rO   	getLoggerr,   objectr   r   rg   r   r   r   r   <module>rn      sg    #& 5

  	 g01 JF  JFb6 bJ= zF r   