ó
ÍÿŠTc           @   sl  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 m	 Z	 d  d l
 m Z d  d l m Z m 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 m Z d
 Z d Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ  d e f d „  ƒ  YZ! d „  Z" d „  Z# d S(   iÿÿÿÿN(   t   Deferredt   succeed(   t   sequence_to_ranges(   t   gather_resultst   spawn_process(   t   fetch_async(   t
   touch_file(   t   bpickle(   t   PackageTaskHandlerConfigurationt   PackageTaskHandlert   run_task_handler(   t   UnknownHashIDRequestt   FakePackageStorei   iô  t   PackageReporterConfigurationc           B   s   e  Z d  Z d „  Z RS(   s=   Specialized configuration for the Landscape package-reporter.c         C   s8   t  t |  ƒ j ƒ  } | j d d t d d d d ƒ| S(   sl   
        Specialize L{Configuration.make_parser}, adding options
        reporter-specific options.
        s   --force-apt-updatet   defaultt   actiont
   store_truet   helps   Force running apt-update.(   t   superR   t   make_parsert
   add_optiont   False(   t   selft   parser(    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR      s
    (   t   __name__t
   __module__t   __doc__R   (    (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR      s   t   PackageReporterc           B   sÝ   e  Z d  Z e Z d Z d Z d Z d Z e	 Z
 d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   st   Report information about the system packages.

    @cvar queue_name: Name of the task queue to pick tasks from.
    t   reporters   /usr/lib/landscape/apt-updates   /etc/apt/sources.lists   /etc/apt/sources.list.dc            sÓ   t  ˆ  _ t ƒ  } | j ‡  f d †  ƒ | j ‡  f d †  ƒ | j ‡  f d †  ƒ | j ‡  f d †  ƒ | j ‡  f d †  ƒ | j ‡  f d †  ƒ | j ‡  f d †  ƒ | j ‡  f d †  ƒ | j d  ƒ | S(	   Nc            s
   ˆ  j  ƒ  S(   N(   t   get_session_id(   t   x(   R   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   <lambda><   s    c            s
   ˆ  j  ƒ  S(   N(   t   run_apt_update(   R   (   R   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR   >   s    c            s
   ˆ  j  ƒ  S(   N(   t   fetch_hash_id_db(   R   (   R   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR   A   s    c            s
   ˆ  j  ƒ  S(   N(   t   use_hash_id_db(   R   (   R   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR   D   s    c            s
   ˆ  j  ƒ  S(   N(   t   handle_tasks(   R   (   R   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR   G   s    c            s
   ˆ  j  ƒ  S(   N(   t   remove_expired_hash_id_requests(   R   (   R   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR   J   s    c            s
   ˆ  j  ƒ  S(   N(   t   request_unknown_hashes(   R   (   R   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR   M   s    c            s
   ˆ  j  ƒ  S(   N(   t   detect_changes(   R   (   R   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR   P   s    (   R   t	   _got_taskR    t   addCallbackt   callbackt   None(   R   t   result(    (   R   s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   run7   s    		c         C   s   |  j  j | |  j t ƒ S(   N(   t   _brokert   send_messaget   _session_idt   True(   R   t   message(    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR.   U   s    	c            s,   ‡  f d †  } ˆ  j  ƒ  } | j | ƒ | S(   sî  
        Fetch the appropriate pre-canned database of hash=>id mappings
        from the server. If the database is already present, it won't
        be downloaded twice.

        The format of the database filename is <uuid>_<codename>_<arch>,
        and it will be downloaded from the HTTP directory set in
        config.package_hash_id_url, or config.url/hash-id-databases if
        the former is not set.

        Fetch failures are handled gracefully and logged as appropriate.
        c            s¼   ˆ d  k r d  St j j ˆ ƒ r& d  Sˆ j ƒ  } | sI t j d ƒ d  St | t j j ˆ ƒ ƒ ‰  ‡  ‡ f d †  } d „  } t	 ˆ  d ˆ j
 j d ƒ ƒ} | j | ƒ | j | ƒ | S(   Ns)   Can't determine the hash=>id database urlc            s;   t  ˆ d ƒ } | j |  ƒ | j ƒ  t j d ˆ  ƒ d  S(   Nt   ws$   Downloaded hash=>id database from %s(   t   opent   writet   closet   loggingt   info(   t   datat   hash_id_db_fd(   t   urlt   hash_id_db_filename(    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   fetch_okz   s    
c         S   s$   |  j  } t j d t | ƒ ƒ d  S(   Ns'   Couldn't download hash=>id database: %s(   t   valueR6   t   warningt   str(   t   failuret	   exception(    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   fetch_error€   s    		t   cainfot   ssl_public_key(   R*   t   ost   patht   existst   _get_hash_id_db_base_urlR6   R>   R?   t   basenameR   t   _configt   getR(   t
   addErrback(   R;   t   base_urlR<   RB   R+   (   R   (   R:   R;   s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   fetch_itg   s     		(   t   _determine_hash_id_db_filenameR(   (   R   RN   R+   (    (   R   s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR!   Y   s    %c         C   sc   |  j  j d ƒ } | sR |  j  j d ƒ s. d  St j |  j  j j d ƒ d ƒ } n  | j d ƒ d S(   Nt   package_hash_id_urlR:   t   /s   hash-id-databases(   RJ   RK   R*   t   urlparset   urljoinR:   t   rstrip(   R   RM   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRH      s    c         C   sØ   d d l  m } g  } t j j |  j ƒ r> | j |  j ƒ n  t j j |  j ƒ r” | j g  t j	 |  j ƒ D] } t j j
 |  j | ƒ ^ ql ƒ n  x= | D]5 } t j ƒ  t j j | ƒ } | | j k  r› t Sq› Wt S(   s=   Return a boolean indicating if the APT sources were modified.iÿÿÿÿ(   t   PackageMonitor(   t    landscape.monitor.packagemonitorRU   RE   RF   RG   t   sources_list_filenamet   appendt   sources_list_directoryt   extendt   listdirt   joint   timet   getmtimet   run_intervalR0   R   (   R   RU   t	   filenamest   filenamet   seconds_since_last_change(    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   _apt_sources_have_changed¡   s    8c         C   sr   t  j j |  j ƒ r! |  j } n+ t  j j |  j j ƒ rH |  j j } n t St  j | ƒ j } | | t	 j	 ƒ  k  S(   s+   Check if the apt-update timeout has passed.(
   RE   RF   RG   t   update_notifier_stampRJ   t   update_stamp_filenameR0   t   statt   st_mtimeR]   (   R   t   intervalt   stampt   last_update(    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   _apt_update_timeout_expired·   s    c            sz   ˆ  j  j s- ˆ  j ƒ  s- ˆ  j ˆ  j  j ƒ rX t ˆ  j ƒ } ‡  f d †  } | j | ƒ St j	 d ˆ  j ƒ t
 d ƒ Sd S(   s€   Run apt-update and log a warning in case of non-zero exit code.

        @return: a deferred returning (out, err, code)
        c            s  |  \ ‰ ‰ ‰  d } t  ˆ j j ƒ t j d ˆ j ˆ  ˆ ˆ f ƒ ˆ  d k r¡ t j d ˆ j ˆ  ˆ f ƒ x^ | D]% } | ˆ k ru d \ ‰ ‰ ‰  Pqu qu Wn. ˆ j j ƒ  sÏ d ‰  d ˆ j	 ˆ j
 f ‰ n  ˆ j j d	 ˆ j ˆ  ˆ ƒ } | j ‡  ‡ ‡ f d
 †  ƒ | S(   Ns8   Problem renaming the file /var/cache/apt/srcpkgcache.bins5   Problem renaming the file /var/cache/apt/pkgcache.bins/   '%s' exited with status %d (out='%s', err='%s')i    s   '%s' exited with status %d (%s)t    i   s0   There are no APT sources configured in %s or %s.s   package-reporter-resultc            s   ˆ ˆ ˆ  f S(   N(    (   t   ignore(   t   codet   errt   out(    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR   í   s    (   s8   Problem renaming the file /var/cache/apt/srcpkgcache.bins5   Problem renaming the file /var/cache/apt/pkgcache.bin(   Rl   Rl   i    (   R   RJ   Re   R6   t   debugt   apt_update_filenameR>   t   _facadet   get_channelsRW   RY   R-   t   call_if_acceptedt   send_resultR(   (   t   .0Rp   Ro   Rn   t   accepted_apt_errorsR1   t   deferred(   R   (   Rn   Ro   Rp   s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR)   Î   s.     		s/   '%s' didn't run, update interval has not passedRl   i    N(   Rl   Rl   i    (   RJ   t   force_apt_updateRc   Rk   t   apt_update_intervalR   Rr   R(   R6   Rq   R   (   R   R+   R)   (    (   R   s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR    Ã   s    "	c         C   s(   i d d 6| d 6| d 6} |  j  | ƒ S(   sP   
        Report the package reporter result to the server in a message.
        s   package-reporter-resultt   typeRn   Ro   (   R.   (   R   Rn   Ro   R1   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRv   ÷   s
    
c         C   sV   | j  } | d d k r/ t |  _ |  j | ƒ S| d d k rR t |  _ |  j ƒ  Sd  S(   NR|   s   package-idst   resynchronize(   R8   R0   R'   t   _handle_package_idst   _handle_resynchronize(   R   t   taskR1   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   handle_task  s    			c            sÿ   g  } y |  j  j | d ƒ ‰  Wn t k
 r: t d  ƒ SXi  } xJ t ˆ  j | d ƒ D]2 \ } } | d  k r€ | j | ƒ qX | | | <qX W|  j  j | ƒ t	 j
 d t | ƒ t | ƒ f ƒ | rÙ |  j | ƒ } n t d  ƒ } | j ‡  f d †  ƒ | S(   Ns
   request-idt   idssC   Received %d package hash => id translations, %d hashes are unknown.c            s
   ˆ  j  ƒ  S(   N(   t   remove(   R   (   t   request(    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR   &  s    (   t   _storet   get_hash_id_requestR   R   R*   t   zipt   hashesRX   t   set_hash_idsR6   R7   t   lent   _handle_unknown_packagesR(   (   R   R1   t   unknown_hashest   hash_idst   hasht   idR+   (    (   R„   s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR~   
  s$    #	c         C   sK   |  j  j ƒ  |  j  j ƒ  |  j  j ƒ  |  j  j ƒ  |  j  j ƒ  t d  ƒ S(   N(   R…   t   clear_availablet   clear_available_upgradest   clear_installedt   clear_lockedt   clear_hash_id_requestsR   R*   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR   *  s    c   	      C   s<  |  j  j ƒ  t | ƒ } g  } g  } x¾ |  j  j ƒ  D]­ } |  j  j | ƒ } | | k r5 | j | ƒ |  j  j | ƒ } | j i	 | j d 6| j d 6| j	 d 6| j
 d 6| j d 6| j d 6| j d 6| j d 6| j d	 6ƒ q5 q5 W| r,t j d
 t | ƒ ƒ i d d 6| d 6} |  j | | ƒ } n t d  ƒ } | S(   NR|   t   namet   versiont   sectiont   summaryt   descriptiont   sizes   installed-sizet	   relationss@   Queuing messages with data for %d packages to exchange urgently.s   add-packagest   packages(   Rs   t   ensure_channels_reloadedt   sett   get_packagest   get_package_hashRX   t   get_package_skeletonR|   R•   R–   R—   R˜   R™   Rš   t   installed_sizeR›   R6   R7   RŠ   t"   _send_message_with_hash_id_requestR   R*   (	   R   Rˆ   t   added_hashesRœ   t   packageRŽ   t   skeletonR1   R+   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR‹   3  s4    






		c            s    t  j  ƒ  ‰ ˆ t ‰  ‡ ‡  f d †  } g  } xe |  j j ƒ  D]T } | j d  k r` | j ƒ  q> |  j j | j ƒ } | j	 | | ƒ | j
 | ƒ q> Wt | ƒ S(   Nc            s2   |  r ˆ  | _  n | j  ˆ k  r. | j ƒ  n  d  S(   N(   t	   timestampRƒ   (   t
   is_pendingR„   (   t   nowt   timeout(    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   update_or_removeZ  s    (   R]   t   HASH_ID_REQUEST_TIMEOUTR…   t   iter_hash_id_requestst
   message_idR*   Rƒ   R-   t   is_message_pendingR(   RX   R   (   R   R«   t   resultsR„   R+   (    (   Rª   R©   s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR$   V  s    
c         C   s  |  j  j ƒ  t ƒ  } x] |  j  j ƒ  D]L } |  j  j | ƒ } |  j j | ƒ d k r& | j |  j  j | ƒ ƒ q& q& Wx* |  j j	 ƒ  D] } | t | j
 ƒ 8} q† W| s¸ t d ƒ } nS t | ƒ } | t  } t j d t | ƒ ƒ i d d 6| d 6} |  j | | ƒ } | S(   s¸  Detect available packages for which we have no hash=>id mappings.

        This method will verify if there are packages that APT knows
        about but for which we don't have an id yet (no hash => id
        translation), and deliver a message (unknown-package-hashes)
        to request them.

        Hashes previously requested won't be requested again, unless they
        have already expired and removed from the database.
        sB   Queuing request for package hash => id translation on %d hash(es).s   unknown-package-hashesR|   Rˆ   N(   Rs   R   Rž   RŸ   R    R…   t   get_hash_idR*   t   addR­   Rˆ   R   t   sortedt   MAX_UNKNOWN_HASHES_PER_REQUESTR6   R7   RŠ   R£   (   R   RŒ   R¥   RŽ   R„   R+   R1   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR%   p  s&    	 
	

		c            s\   |  j  j | ƒ ‰  ˆ  j | d <|  j | ƒ } ‡  f d †  } ‡  f d †  } | j | | ƒ S(   s<   Create a hash_id_request and send message with "request-id".s
   request-idc            s   |  ˆ  _  d  S(   N(   R®   (   R®   (   R„   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   set_message_idŸ  s    c            s   ˆ  j  ƒ  |  S(   N(   Rƒ   (   R@   (   R„   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   send_message_failed¢  s    
(   R…   t   add_hash_id_requestR   R.   t   addCallbacks(   R   R1   RŒ   R+   Rµ   R¶   (    (   R„   s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR£   ™  s    c            s(   ‡  f d †  } ˆ  j  ƒ  } | j | ƒ S(   s×   Detect all changes concerning packages.

        If some changes were detected with respect to our last run, then an
        event of type 'package-data-changed' will be fired in the broker
        reactor.
        c            s   |  r ˆ  j  j d ƒ Sd  S(   Ns   package-data-changed(   R-   t
   fire_event(   R+   (   R   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   changes_detected°  s    (   t   detect_packages_changesR(   (   R   Rº   Ry   (    (   R   s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR&   ¨  s    c         C   s-   |  j  s |  j ƒ  r |  j ƒ  St d ƒ Sd S(   s„   
        Check if any information regarding packages have changed, and if so
        compute the changes and send a signal.
        N(   R'   t   _package_state_has_changedt   _compute_packages_changesR   R*   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR»   ¸  s    
c         C   sµ   |  j  j } t j j | ƒ s" t St j j d ƒ } t j j	 d ƒ } | | g } | j
 t j d | ƒ ƒ t j | ƒ j } x0 | D]( } t j | ƒ j } | | k r… t Sq… Wt S(   sE  
        Detect changes in the universe of known packages.

        This uses the state of packages in /var/lib/dpkg/state and other files
        and simply checks whether they have changed using their "last changed"
        timestamp on the filesystem.

        @return True if the status changed, False otherwise.
        s   dir::state::statuss   dir::state::listss   %s/*Packages(   RJ   t   detect_package_changes_stampRE   RF   RG   R0   t   apt_pkgt   configt	   find_filet   find_dirRZ   t   globRf   Rg   R   (   R   t
   stamp_filet   status_filet	   lists_dirt   filest   last_checkedt   ft   last_changed(    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR¼   Â  s    
c            s×  ˆ j  j ƒ  t ˆ j j ƒ  ƒ } t ˆ j j ƒ  ƒ } t ˆ j j ƒ  ƒ } t ˆ j j ƒ  ƒ } t ƒ  } t ƒ  } t ƒ  } t ƒ  } x½ ˆ j  j ƒ  D]¬ }	 ˆ j  j	 |	 ƒ }
 ˆ j j
 |
 ƒ } | d k	 r• ˆ j  j |	 ƒ r| j | ƒ ˆ j  j |	 ƒ r| j | ƒ qn | j | ƒ ˆ j  j |	 ƒ rA| j | ƒ qAq• q• WxW ˆ j  j ƒ  D]F }	 ˆ j  j	 |	 ƒ }
 ˆ j j
 |
 ƒ } | d k	 rU| j | ƒ qUqUW| | ‰ | | ‰ | | ‰ | | ‰ | | ‰ | | ‰ | | ‰ | | ‰  i  } ˆ rt t t ˆ ƒ ƒ ƒ | d <n  ˆ r?t t t ˆ ƒ ƒ ƒ | d <n  ˆ rdt t t ˆ ƒ ƒ ƒ | d <n  ˆ r‰t t t ˆ ƒ ƒ ƒ | d <n  ˆ r®t t t ˆ ƒ ƒ ƒ | d <n  ˆ rÓt t t ˆ ƒ ƒ ƒ | d <n  ˆ røt t t ˆ ƒ ƒ ƒ | d <n  ˆ  rt t t ˆ  ƒ ƒ ƒ | d <n  | s-t t ƒ Sd	 | d
 <ˆ j | ƒ } t j d t ˆ ƒ t ˆ ƒ t ˆ ƒ t ˆ ƒ t ˆ ƒ t ˆ ƒ t ˆ ƒ t ˆ  ƒ f ƒ ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ f	 d †  } | j | ƒ | S(   s/  Analyse changes in the universe of known packages.

        This method will verify if there are packages that:

        - are now installed, and were not;
        - are now available, and were not;
        - are now locked, and were not;
        - were previously available but are not anymore;
        - were previously installed but are not anymore;
        - were previously locked but are not anymore;

        Additionally it will report package locks that:

        - are now set, and were not;
        - were previously set but are not anymore;

        In all cases, the server is notified of the new situation
        with a "packages" message.

        @return: A deferred resulting in C{True} if package changes were
            detected with respect to the previous run, or C{False} otherwise.
        t	   installedt	   availables   available-upgradest   lockeds   not-installeds   not-availables   not-available-upgradess
   not-lockedRœ   R|   s»   Queuing message with changes in known packages: %d installed, %d available, %d available upgrades, %d locked, %d not installed, %d not available, %d not available upgrades, %d not locked.c            sâ   ˆ r ˆ j  j ˆ ƒ n  ˆ r2 ˆ j  j ˆ ƒ n  ˆ rK ˆ j  j ˆ ƒ n  ˆ rd ˆ j  j ˆ ƒ n  ˆ r} ˆ j  j ˆ ƒ n  ˆ r– ˆ j  j ˆ ƒ n  ˆ r¯ ˆ j  j ˆ ƒ n  ˆ  rÈ ˆ j  j ˆ  ƒ n  ˆ j	 j
 } t | ƒ t S(   N(   R…   t   add_installedt   remove_installedt   add_availablet
   add_lockedt   remove_availablet   add_available_upgradest   remove_available_upgradest   remove_lockedRJ   R¾   R   R0   (   R+   RÄ   (	   t
   not_lockedt   new_availablet
   new_lockedt   new_upgradesR   t   not_upgradest   not_availablet   new_installedt   not_installed(    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   update_currently_knownH  s&    
N(   Rs   R   Rž   R…   t   get_installedt   get_availablet   get_available_upgradest
   get_lockedRŸ   R    R±   R*   t   is_package_installedR²   t   is_package_availablet   is_package_upgradet   get_locked_packagest   listR   R³   R   R   R.   R6   R7   RŠ   R(   (   R   t   old_installedt   old_availablet   old_upgradest
   old_lockedt   current_installedt   current_availablet   current_upgradest   current_lockedR¥   RŽ   R   R1   R+   RÞ   (    (	   RÖ   R×   RØ   R   RÚ   RÛ   RÜ   RÙ   RÝ   s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR½   Ü  s|    				









	'(   R   R   R   R   t   config_factoryt
   queue_nameRr   RW   RY   R   R'   R,   R.   R!   RH   Rc   Rk   R    Rv   R   R~   R   R‹   R$   R%   R£   R&   R»   R¼   R½   (    (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR   )   s4   			7				4	
			 			#		)			
	t   FakeGlobalReporterc           B   s   e  Z d  Z e Z d „  Z RS(   sb   
    A standard reporter, which additionally stores messages sent into its
    package store.
    c         C   s&   |  j  j | ƒ t t |  ƒ j | ƒ S(   N(   R…   t   save_messageR   Rò   R.   (   R   R1   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR.   l  s    (   R   R   R   R   t   package_store_classR.   (    (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRò   d  s   t   FakeReporterc           B   s,   e  Z d  Z e Z d Z d „  Z d „  Z RS(   se   
    A fake reporter which only sends messages previously stored by a
    L{FakeGlobalReporter}.
    c            sh   t  d  ƒ } | j ‡  f d †  ƒ | j ‡  f d †  ƒ | j ‡  f d †  ƒ | j ‡  f d †  ƒ | S(   Nc            s
   ˆ  j  ƒ  S(   N(   R   (   R   (   R   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR   }  s    c            s
   ˆ  j  ƒ  S(   N(   R!   (   R   (   R   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR   €  s    c            s   ˆ  j  j ƒ  S(   N(   R…   t   clear_tasks(   R   (   R   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR   ‚  s    c            s
   ˆ  j  ƒ  S(   N(   t   send_pending_messages(   R   (   R   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR   …  s    (   R   R*   R(   (   R   R+   (    (   R   s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR,   z  s    c            s>  ˆ  j  d k r" t j d ˆ  _  n  t j j ˆ  j  ƒ sA t d ƒ St ˆ  j j	 ƒ  ƒ } t
 ˆ  j  ƒ } t | j	 ƒ  ƒ } | | } t d ƒ } t ƒ  } | r:| j | ƒ } g  } xs | D]k \ }	 }
 t j t |
 ƒ ƒ }
 |
 d | k r¸ | j |
 d ƒ | j |	 ƒ | j |
 ‡  f d † ƒ q¸ q¸ Wˆ  j j | ƒ n  | S(   sT   
        As the last callback of L{PackageReporter}, sends messages stored.
        t   FAKE_PACKAGE_STORER|   c            s   ˆ  j  | ƒ S(   N(   R.   (   R   R1   (   R   (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR      s    N(   t   global_store_filenameR*   RE   t   environRF   RG   R   Rž   R…   t   get_message_idsR   t   get_messages_by_idsR   t   loadsR?   R²   RX   R(   t   save_message_ids(   R   t   message_sentt   global_storet   all_message_idst   not_sentRy   t   got_typet   messagest   sentR®   R1   (    (   R   s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyR÷   ‰  s,    

	N(	   R   R   R   R   Rô   R*   Rù   R,   R÷   (    (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyRõ   q  s
   	c         C   sI   d t  j k r t t |  ƒ Sd t  j k r8 t t |  ƒ St t |  ƒ Sd  S(   Nt   FAKE_GLOBAL_PACKAGE_STORERø   (   RE   Rú   R
   Rò   Rõ   R   (   t   args(    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   main¥  s
    c          C   s8   t  j j t  j j t j d ƒ ƒ }  t  j j |  d ƒ S(   Ni    s   landscape-package-reporter(   RE   RF   t   dirnamet   abspatht   syst   argvR\   (   R	  (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   find_reporter_command®  s    %($   RR   R6   R]   R  RE   RÃ   R¿   t   twisted.internet.deferR    R   t   landscape.lib.sequencerangesR   t   landscape.lib.twisted_utilR   R   t   landscape.lib.fetchR   t   landscape.lib.fsR   t   landscape.libR   t   landscape.package.taskhandlerR   R	   R
   t   landscape.package.storeR   R   R¬   R´   R   R   Rò   Rõ   R  R  (    (    (    s>   /usr/lib/python2.7/dist-packages/landscape/package/reporter.pyt   <module>   s0   ÿ ÿ =4		