~divmod-dev/divmod.org/dangling-1091

« back to all changes in this revision

Viewing changes to Axiom/axiom/upgrade.py

  • Committer: glyph
  • Date: 2005-07-28 22:09:16 UTC
  • Revision ID: svn-v4:866e43f7-fbfc-0310-8f2a-ec88d1da2979:trunk:2
move this repository to a more official-looking URL

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- axiom.test.test_upgrading -*-
 
2
_upgradeRegistry = {}
 
3
 
 
4
def registerUpgrader(upgrader, typeName, oldVersion, newVersion):
 
5
    """
 
6
    Register a callable which can perform a schema upgrade between two
 
7
    particular versions.
 
8
 
 
9
    @param upgrader: A one-argument callable which will upgrade an object.  It
 
10
    is invoked with an instance of the old version of the object.
 
11
    @param typeName: The database typename for which this is an upgrader.
 
12
    @param oldVersion: The version from which this will upgrade.
 
13
    @param newVersion: The version tow hich this will upgrade.  This must be
 
14
    exactly one greater than C{oldVersion}.
 
15
    """
 
16
    # assert (typeName, oldVersion, newVersion) not in _upgradeRegistry, "duplicate upgrader"
 
17
 
 
18
    # ^ this makes the tests blow up so it's just disabled for now; perhaps we
 
19
    # should have a specific test mode
 
20
    assert newVersion - oldVersion == 1, "read the doc string"
 
21
    _upgradeRegistry[typeName, oldVersion, newVersion] = upgrader
 
22
 
 
23
def upgradeAllTheWay(o, typeName, version):
 
24
    while True:
 
25
        try:
 
26
            upgrader = _upgradeRegistry[typeName, version, version + 1]
 
27
        except KeyError:
 
28
            break
 
29
        else:
 
30
            o = upgrader(o)
 
31
            version += 1
 
32
    return o