Changeset 416

Show
Ignore:
Timestamp:
Fri Feb 9 10:19:30 2007
Author:
djfroofy
Message:

- made lxml an extras requirement
- added downgrade function to upgrade module

Files:

Legend:

Unmodified
Added
Removed
Modified
  • trunk/tests/doctests/txt/xix-utils-upgrade.txt

    r405 r416  
    24 24                 upgrading from 1023.2  
    25 25  
    26           A module of dictionary namespace can be passed to the function upgrade:  
      26         A module can be passed to the function upgrade instead of a  
      27     namespace dictionary:  
    27 28  
    28 29                 >>> from xix.utils.upgrade import upgrade  
     
    31 32                 upgrading from 1.0.2  
    32 33                 upgrading from 1023.2  
    33                    
      34  
      35         Downgrade functions can be applied as well:  
      36  
      37                 >>> from xix.utils.upgrade import downgrade  
      38                 >>> downgrade('0.0.1', upgrade_example) # downgrade back to version 0.0.1  
      39                 downgrading to 1023.2  
      40                 downgrading to 1.0.2  
      41                 downgrading to 0.0.1  
      42  
      43         Custom function prefixes can be given if you really so desire:  
      44  
      45                 >>> upgrade('0.0.2', upgrade_example, func_pfx='foo')  
      46                 foo 1.0.2  
      47                 foo 1023.2  
      48  
      49         Ditto for downgrading  
      50  
      51                 >>> downgrade('0.0.2', upgrade_example, func_pfx='foo')  
      52                 foo 1023.2  
      53                 foo 1.0.2  
    34 54  
  • trunk/tests/doctests/upgrade_example.py

    r404 r416  
    13 13     print 'upgrading from 1023.2'  
    14 14  
      15 def downgrade0_0_0():  
      16     print 'downgrading to 0.0.0'  
      17  
      18 def downgrade0_0_1():  
      19     print 'downgrading to 0.0.1'  
      20  
      21 def downgrade1_0_2():  
      22     print 'downgrading to 1.0.2'  
      23  
      24 def downgrade1023_2():  
      25     print 'downgrading to 1023.2'  
      26  
      27 def foo0_0_0():  
      28     print 'foo 0.0.0'  
      29  
      30 def foo0_0_1():  
      31     print 'foo 0.0.1'  
      32  
      33 def foo1_0_2():  
      34     print 'foo 1.0.2'  
      35  
      36 def foo1023_2():  
      37     print 'foo 1023.2'  
      38  
    15 39 def do_upgrade(vers):  
    16 40     upgrade(vers, globals())  
  • trunk/setup.py

    r415 r416  
    15 15     author_email='drew dot smathers at gmail dot com',  
    16 16     name='xix-utils',  
    17       version='0.2.2',  
      17     version='0.2.3',  
    17 17     install_requires=['zope.interface>=3.2.0'],  
    18       extras_require = {'coverage' : ['lxml>=1.1.2']},  
      18     extras_require = {  
      19         'xml' : ['lxml>=1.1.2'],  
      20         'sa'  : ['SQLAlchemy>=0.3.3']},  
    19 21     scripts=['scripts/xix-coverage.py'],  
    20 22     description="""Xix Utils is a drillbit library independent (mostly) of  
  • trunk/xix/utils/upgrade.py

    r404 r416  
    5 5 __version__ = '$Revision$'  
    6 6  
    7   def upgrade(vers, namespace, func_pfx='upgrade'):  
    8       """Call upgrade functions found in namepace to perform upgrade functions  
    9       from last version >= current and up to the newest version.  
    10    
    11       Migration function names should obey the following pattern:  
    12    
    13       <pre>migrate[major]_[minor](_[patch])</pre>  
    14    
    15       The version in the function name is the version we are migrating from.  
    16       """  
      7 def _upgrade(vers, namespace, func_pfx='upgrade', sort_func=None, select_func=None):  
    17 8     p = re.compile(r'%s(?P<current_vers>\d+_\d+(_\d+)?)' % func_pfx)  
    18 9     curr_vers_n = _vers_no(vers)  
     
    20 11     ns = namespace  
    21 12     if not isinstance(ns, dict):  
    22           ns = namespace.__dict__  
      13         ns = ns.__dict__  
    22 13     names = ns.keys()  
    23 14     for func in (f for f in names if p.match(f)):  
    24 15          vers_n = _vers_no(p.match(func).groupdict()['current_vers'], '_')  
    25 16          funcs.append((vers_n, func))  
    26       funcs.sort()  
      17     #funcs.sort()  
      18     sort_func(funcs)  
    27 19     # Call migration functions in order  
    28       for func in (f for (v,f) in funcs if v >= curr_vers_n):  
      20     for func in (f for (v,f) in funcs if select_func(curr_vers_n, v)):  
    28 20         ns[func]()  
    29 21  
      22 def upgrade(vers, namespace, func_pfx='upgrade'):  
      23     """Call upgrade functions found in namepace to perform upgrade functions  
      24     from last version >= current and up to the newest version.  
      25  
      26     Upgrade function names must obey the following pattern:  
      27  
      28     <pre>upgrade[major]_[minor](_[patch])</pre>  
      29  
      30     The version in the function name is the version we are upgrading from.  
      31     So if you are upgrading from a version 0.1.3 to 0.2.1 for example, all functions  
      32     >= 0.1.3 will be executed and in order.  
      33     """  
      34     _upgrade(vers, namespace, func_pfx=func_pfx,  
      35             sort_func=(lambda l: l.sort()),  
      36             select_func=(lambda cv, v: v >= cv))  
      37  
      38 def downgrade(vers, namespace, func_pfx='downgrade'):  
      39     """Like upgrade except we apply "downgrade" functions in reverse order  
      40     down to and including the version we want to downgrade to.  
      41     """  
      42     def sorter(l):  
      43         l.sort()  
      44         l.reverse()  
      45     _upgrade(vers, namespace, func_pfx=func_pfx,  
      46             sort_func=sorter,  
      47             select_func=(lambda cv, v: v >= cv))  
      48  
    30 49 # backwards comp  
    31 50 def migrate(vers, namespace):