ó
½-'Nc           @   sh   d  d l  Z  d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d S(
   iÿÿÿÿNt   UpgraderConflictc           B   s   e  Z d  Z RS(   s9   Two upgraders with the same version have been registered.(   t   __name__t
   __module__t   __doc__(    (    (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyR       s   t   UpgradeManagerBasec           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s   A simple upgrade system.c         C   s   i  |  _  d  S(   N(   t
   _upgraders(   t   self(    (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyt   __init__   s    c         C   sC   | |  j  k r2 t d | |  j  | | f ƒ ‚ n  | |  j  | <d S(   sN  
        @param version: The version number that this upgrader is
            upgrading the database to. This defines the order that
            upgraders are run.
        @param function: The function to call when applying
            upgraders. It must take a single object, the database that is
            being upgraded.
        s-   %s is already registered as %s; not adding %sN(   R   R    (   R   t   versiont   function(    (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyt   register_upgrader   s    	c         C   s#   |  j  j ƒ  } | r t | ƒ Sd S(   sp   
        Get the 'current' version of any database that this
        UpgradeManager will be applied to.
        i    (   R   t   keyst   max(   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyt   get_version   s    
c            s   ‡  ‡ f d †  } | S(   sÍ   
        A decorator for specifying that a function is an upgrader for
        this upgrade manager.

        @param version: The version number that the function will be
            upgrading to.
        c            s   ˆ  j  ˆ |  ƒ |  S(   N(   R
   (   R	   (   R   R   (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyt   inner/   s    (    (   R   R   R   (    (   R   R   s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyt   upgrader'   s    (   R   R   R   R   R
   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyR      s
   			
t   UpgradeManagerc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | j  d ƒ s" | j d d ƒ n  xf t |  j j ƒ  ƒ D]O \ } } | | j d ƒ k r8 | j d | ƒ | | ƒ t j d | ƒ q8 q8 Wd S(   s‘   Bring the database up-to-date.

        @param persist: The database to upgrade. It will be passed to
            all upgrade functions.
        s   system-versioni    s   Successfully applied patch %sN(   t   hast   sett   sortedR   t   itemst   gett   loggingt   info(   R   t   persistR   R   (    (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyt   apply7   s    "
c         C   s   | j  d |  j ƒ  ƒ d S(   sk   
        Mark the database as being up-to-date; use this when
        initializing a new database.
        s   system-versionN(   R   R   (   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyt
   initializeE   s    (   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyR   5   s   	t   SQLiteUpgradeManagerc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s$   An upgrade manager backed by sqlite.c         C   s:   | j  d ƒ | j ƒ  } t g  | D] } | d ^ q# ƒ S(   Ns   SELECT version FROM patchi    (   t   executet   fetchallR   (   R   t   cursort   resultt   row(    (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyt   get_database_versionsP   s    c         C   s+   | j  d ƒ | j ƒ  d } | r' | Sd S(   Ns   SELECT MAX(version) FROM patchi    (   R   t   fetchone(   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyt   get_database_versionU   s
    c         C   sX   |  j  | ƒ } xB t |  j j ƒ  ƒ D]+ \ } } | | k r% |  j | | ƒ q% q% Wd S(   s   Bring the database up-to-date.N(   R!   R   R   R   t	   apply_one(   R   R   t   versionsR   R   (    (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyR   \   s    "c         C   s.   |  j  | } | | ƒ | j d | f ƒ d  S(   Ns   INSERT INTO patch VALUES (?)(   R   R   (   R   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyR$   c   s    
c         C   sJ   | j  d ƒ x6 t |  j j ƒ  ƒ D] \ } } | j  d | f ƒ q# Wd S(   sr   
        Mark the database as being up-to-date; use this when
        initializing a new SQLite database.
        s$   CREATE TABLE patch (version INTEGER)s   INSERT INTO patch VALUES (?)N(   R   R   R   R   (   R   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyR   h   s    "(   R   R   R   R!   R#   R   R$   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyR   M   s   				(   R   t	   ExceptionR    t   objectR   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/landscape/patch.pyt   <module>   s   -