From a133fc8d32cd892bd5ef58eb42af7d86f18eeddc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lo=C3=AFc=20Minier?= Date: Tue, 11 Aug 2009 21:16:13 +0200 Subject: [PATCH] Implement blueprint status tracking by parsing Status: in the whiteboard --- workitems.py | 96 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 73 insertions(+), 23 deletions(-) diff --git a/workitems.py b/workitems.py index d562106..928c941 100755 --- a/workitems.py +++ b/workitems.py @@ -23,6 +23,10 @@ def get_db(dbpath): workitem VARCHAR(255) NOT NULL, status VARCHAR(20) NOT NULL, date TIMESTAMP NOT NULL)''') + cur.execute('''CREATE TABLE statuses ( + blueprint VARCHAR(255) NOT NULL, + status VARCHAR(20) NOT NULL, + date TIMESTAMP NOT NULL)''') db.commit() return db @@ -84,7 +88,7 @@ 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', 'state') pairs. ''' work_items_re = re.compile('(

|^)work items:\s*
', re.I) @@ -130,12 +134,42 @@ def get_blueprint_workitems(blueprint_url): return result +def get_blueprint_status(blueprint_url): + '''Collect status from a particular blueprint URL. + + This will return a list of lines. + ''' + status_re = re.compile('(

|^)status:\s*
', re.I) + + found_status = False + result = [] + for l in urllib.urlopen(blueprint_url): + end = False + if not found_status: + if status_re.search(l): + found_status = True + continue + + if '

' in l: + end = True + l = l.replace('
', '').replace('', '').replace('

', '').strip() + + if not l: + break + + result.append(l.strip()) + + if end: + break + + return "\n".join(result) + def get_moin_workitems(url): '''Collect work items from a moin wiki URL. Every line starting with "|| " is treated as a work item. - Return a list of ('item', 'status') pairs. + Return a list of ('item', 'state') pairs. ''' result = [] for line in urllib.urlopen(url): @@ -159,34 +193,46 @@ def dump(db): '''Dump database contents.''' cur = db.cursor() - cur.execute('SELECT * FROM work_items') + cur.execute('SELECT w.*, s.status FROM work_items w LEFT JOIN statuses s on w.blueprint = s.blueprint') for (blueprint, workitem, status, date) in cur: print '%s [%s]\t%s: %s' % (date, blueprint, workitem, status) -def add_work_item(db, blueprint, item, status): +def add_work_item(db, blueprint, item, state): '''Add work item to database.''' cur = db.cursor() cur.execute('INSERT INTO work_items VALUES (?, ?, ?, date(CURRENT_TIMESTAMP))', - (blueprint, item, status)) + (blueprint, item, state)) + +def add_status(db, blueprint, status): + '''Add blueprint status to database.''' + + cur = db.cursor() + cur.execute('INSERT INTO statuses VALUES (?, ?, date(CURRENT_TIMESTAMP))', + (blueprint, status)) def import_lp(db, name_pattern, release): - '''Collect blueprint work items from Launchpad into DB.''' + '''Collect blueprint work items and status from Launchpad into DB.''' blueprints = get_blueprints('%s//ubuntu/%s/+specs?batch=300' % (blueprints_base_url, opts.release), name_pattern) cur = db.cursor() cur.execute('DELETE FROM work_items WHERE date = date(CURRENT_TIMESTAMP)') + cur.execute('DELETE FROM statuses WHERE date = date(CURRENT_TIMESTAMP)') for bp in blueprints: #print 'Checking', bp bpname = bp.split('/')[-1] work_items = get_blueprint_workitems(bp) + status = get_blueprint_status(bp) if not work_items: print >> sys.stderr, 'WARNING: %s has no work items' % bpname - for (item, status) in work_items: - add_work_item(db, bpname, item, status) + if not status: + print >> sys.stderr, 'WARNING: %s has no status' % bpname + for (item, state) in work_items: + add_work_item(db, bpname, item, state) + add_status(db, bpname, status) def workitems_over_time(db): '''Calculate work item development over time. @@ -202,8 +248,8 @@ def workitems_over_time(db): data.setdefault(date, {})[s] = num return data -def blueprint_status(db): - '''Determine current blueprint status. +def blueprint_stats(db): + '''Determine current blueprint stats. Return blueprint -> [todo, done, postponed] mapping. ''' @@ -217,17 +263,19 @@ def blueprint_status(db): index = 0 for s in valid_states: cur = db.cursor() - cur.execute('SELECT blueprint, count(workitem) FROM work_items ' - 'WHERE status = ? AND date = ? GROUP BY blueprint', + cur.execute('SELECT w.blueprint, count(w.workitem), s.status FROM work_items w ' + 'LEFT JOIN statuses s ON w.blueprint = s.blueprint ' + 'WHERE w.status = ? AND w.date = ? GROUP BY w.blueprint', (s, last_date)) - for (bp, num) in cur: - data.setdefault(bp, [0, 0, 0])[index] = num + for (bp, num, status) in cur: + data.setdefault(bp, [0, 0, 0, ""])[index] = num + data[bp][-1] = status index += 1 return data def text(db): - '''Print work item status as text.''' + '''Print work item stats as text.''' data = workitems_over_time(db) @@ -235,9 +283,10 @@ def text(db): for d in sorted(data.keys()): print d, data[d] - print '\nBlueprint status:' - data = blueprint_status(db) - for (bp, (todo, done, postponed)) in data.iteritems(): + print '\nBlueprint stats:' + data = blueprint_stats(db) + for (bp, (todo, done, postponed, status)) in data.iteritems(): + # TODO print status print '%s: %i/%i (%i%%)' % (bp, postponed+done, todo+done+postponed, int(float(postponed+done)/(todo+done+postponed)*100 + 0.5)) @@ -297,22 +346,23 @@ def html(db):

Status by blueprint

- + ''' - data = blueprint_status(db) + data = blueprint_stats(db) completion = [] - for (bp, (todo, done, postponed)) in data.iteritems(): + for (bp, (todo, done, postponed, status)) in data.iteritems(): completion.append((bp, int(float(postponed+done)/(todo+done+postponed)*100 + 0.5))) completion.sort(key=lambda k: k[1], reverse=True) for (bp, percent) in completion: - print ' ' % ( + print ' ' % ( blueprints_base_url, bp, bp, data[bp][0], data[bp][2], - data[bp][1], percent) + data[bp][1], percent, + data[bp][-1]) print '
Blueprint todo/postponed/done Completion
Blueprint todo/postponed/done Completion Status
%s %i/%i/%i %i%%
%s %i/%i/%i %i%% %s
' -- 2.39.5