From be505d4009838fcf3bcd0c260562169057e8d458 Mon Sep 17 00:00:00 2001 From: "martin@piware.de" <> Date: Tue, 24 Nov 2009 15:24:19 +0100 Subject: [PATCH] workitems: add tracking of assignee (DB schema change) --- workitems.py | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/workitems.py b/workitems.py index 5cad66d..db89f51 100755 --- a/workitems.py +++ b/workitems.py @@ -20,8 +20,9 @@ def get_db(dbpath): cur = db.cursor() cur.execute('''CREATE TABLE work_items ( blueprint VARCHAR(255) NOT NULL, - workitem VARCHAR(255) NOT NULL, + workitem VARCHAR(1000) NOT NULL, status VARCHAR(20) NOT NULL, + assignee VARCHAR(200) NOT NULL, date TIMESTAMP NOT NULL)''') cur.execute('''CREATE TABLE status ( blueprint VARCHAR(255) NOT NULL, @@ -88,14 +89,28 @@ def get_blueprints(url, name_pattern): def get_blueprint_workitems(blueprint_url): '''Collect work items from a particular blueprint URL. - This will return a list of ('item', 'status') pairs. + This will return a list of ('item', 'status', 'assignee') tuples. ''' work_items_re = re.compile('(

|^)work items:\s*
', re.I) + assignee_re = re.compile('') found_workitems = False + found_assignee = False result = [] + default_assignee = 'nobody' for l in urllib.urlopen(blueprint_url): end = False + + if '

Assignee:' in l: + found_assignee = True + continue + + if found_assignee and not found_workitems: + m = assignee_re.search(l) + if m: + default_assignee = m.group(1) + found_assignee = False + if not found_workitems: if work_items_re.search(l): found_workitems = True @@ -127,7 +142,18 @@ def get_blueprint_workitems(blueprint_url): print >> sys.stderr, 'ERROR: invalid state "%s" for work item "%s"' % ( state, desc) continue - result.append((desc, state)) + + if desc.startswith('['): + try: + off = desc.index(']') + assignee = desc[1:off] + desc = desc[off+1:].strip() + except ValueError: + print >> sys.stderr, 'ERROR: missing closing "]" for assignee for work item "%s"' % desc + else: + assignee = default_assignee + + result.append((desc, state, assignee)) if end: break @@ -195,8 +221,8 @@ def dump(db): cur = db.cursor() cur.execute('SELECT * FROM work_items') print '== Work items: ==' - for (blueprint, workitem, item_status, date) in cur: - print '%s [%s]\t%s: %s' % (date, blueprint, workitem, item_status) + for (blueprint, workitem, item_status, assignee, date) in cur: + print '%s [%s, %s]\t%s: %s' % (date, blueprint, assignee, workitem, item_status) print '\n== Status ==' cur = db.cursor() @@ -204,12 +230,12 @@ def dump(db): for (blueprint, status, date) in cur: print '%s: %s [%s]' % (blueprint, status, date) -def add_work_item(db, blueprint, item, status): +def add_work_item(db, blueprint, item, status, assignee): '''Add work item to database.''' cur = db.cursor() - cur.execute('INSERT INTO work_items VALUES (?, ?, ?, date(CURRENT_TIMESTAMP))', - (blueprint, item, status)) + cur.execute('INSERT INTO work_items VALUES (?, ?, ?, ?, date(CURRENT_TIMESTAMP))', + (blueprint, item, status, assignee)) def add_status(db, blueprint, status): '''Add blueprint status to database.''' @@ -238,8 +264,8 @@ def import_lp(db, name_pattern, release): status = get_blueprint_status(bp) if not work_items: print >> sys.stderr, 'WARNING: %s has no work items' % bpname - for (item, state) in work_items: - add_work_item(db, bpname, item, state) + for (item, state, assignee) in work_items: + add_work_item(db, bpname, item, state, assignee) add_status(db, bpname, status) def workitems_over_time(db): @@ -387,7 +413,7 @@ def import_moin(db, urls): for url in urls: for (d, s) in get_moin_workitems(url): - add_work_item(db, url, d, s) + add_work_item(db, url, d, s, 'nobody') # # main -- 2.39.2