# HG changeset patch # User Daniele Nicolodi # Date 1309174995 -7200 # Node ID 29aa9cbb321c3ff8e91e74142a63f44334b05cb3 # Parent fad020eceac0032c2ca039d26ff72a77cf14c54e Simplify upgrade steps registration. diff -r fad020eceac0 -r 29aa9cbb321c src/ltpdarepo/upgrade.py --- a/src/ltpdarepo/upgrade.py Mon Jun 27 13:41:52 2011 +0200 +++ b/src/ltpdarepo/upgrade.py Mon Jun 27 13:43:15 2011 +0200 @@ -1,21 +1,18 @@ import MySQLdb as db -import itertools from functools import partial from .config import HOSTNAME, DATABASE, USERNAME, PASSWORD -# counter -counter = itertools.count() - # upgrade steps register steps = [] -def register(r0, r1, func=None, count=None): +def register(r0, r1, func=None): + # register upgrade functions if func == None: return partial(register, r0, r1) - steps.append((r0, r1, count, func)) + steps.append((r0, r1, func)) return func @@ -33,16 +30,15 @@ # filter applicable upgrade steps todo = filter(lambda x: x[0] >= schema, steps) - # iter upgrade steps - for r, to, count, step in sorted(todo): + # iter upgrade steps + for fromr, tor, step in sorted(todo): # run upgrade step - # print 'from %g to %g: %s.%s' % (r, to, step.__module__, step.__name__) step(conn) # update schema version curs.execute("""UPDATE options SET value=%s - WHERE name='version'""", str(to)) + WHERE name='version'""", str(tor)) conn.commit() conn.close()