ó
½-'Nc           @   sF   d  d l  Z  d  d l m Z d  d l m Z d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   APT_PREFERENCES_SIZE_LIMIT(   t   DataWatchert   AptPreferencesc           B   sJ   e  Z d  Z d Z d Z d Z d Z e Z d d „ Z	 d „  Z
 d „  Z RS(   s:   
    Report the system APT preferences configuration.
    s   apt-preferencest   datai„  s   /etc/aptc         C   s   | |  _  d  S(   N(   t   _etc_apt_directory(   t   selft   etc_apt_directory(    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/aptpreferences.pyt   __init__   s    c   
      C   s[  i  } d „  } t  j j |  j d ƒ } t  j j | ƒ rL | | ƒ | | <n  t  j j |  j d ƒ } t  j j | ƒ rÍ xT t  j | ƒ D]@ } t  j j | | ƒ } t  j j | ƒ r† | | ƒ | | <q† q† Wn  | i  k rÝ d S|  j	 t
 | j ƒ  ƒ } x^ | j ƒ  D]P \ } } t
 | ƒ t
 | ƒ | k r| t
 | ƒ }	 | | d |	 !| | <qqW| S(   s·   Return a C{dict} mapping APT preferences files to their contents.

        If no APT preferences configuration is set at all on the system, then
        simply return C{None}
        c         S   s/   t  |  d ƒ } | j ƒ  } | j ƒ  t | ƒ S(   Nt   r(   t   opent   readt   closet   unicode(   t   filenamet   fdt   content(    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/aptpreferences.pyt	   read_file   s    
u   preferencesu   preferences.di    N(   t   ost   patht   joinR   t   existst   isdirt   listdirt   isfilet   Nonet
   size_limitt   lent   keyst	   iteritems(
   R   R   R   t   preferences_filenamet   preferences_directoryt   entryR   t   item_size_limitt   contentst   truncated_contents_size(    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/aptpreferences.pyt   get_data   s*    			c         C   s   |  j  d t ƒ S(   Nt   urgent(   t   exchanget   True(   R   (    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/aptpreferences.pyt   run<   s    (   t   __name__t
   __module__t   __doc__t   persist_namet   message_typet   message_keyt   run_intervalR    R   R   R#   R'   (    (    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/aptpreferences.pyR      s   	&(   R   t   landscape.constantsR    t   landscape.monitor.pluginR   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/aptpreferences.pyt   <module>   s   