Mercurial > hg > ltpdarepo
changeset 14:29aa9cbb321c
Simplify upgrade steps registration.
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Mon, 27 Jun 2011 13:43:15 +0200 |
parents | fad020eceac0 |
children | 3d6c57b24e72 |
files | src/ltpdarepo/upgrade.py |
diffstat | 1 files changed, 6 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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()