X-Git-Url: https://piware.de/gitweb/?a=blobdiff_plain;f=workitems.py;h=e90b09d8b1764262b6472f11e6d86f9f792605a8;hb=e9406697c46545b1d9fd2b27921cacad18711487;hp=5cad66dea718fc9f82ac776b318de6a7ed2209eb;hpb=ecdaf208f8578f97c434b1f59f72d03f9a5d7599;p=bin.git diff --git a/workitems.py b/workitems.py index 5cad66d..e90b09d 100755 --- a/workitems.py +++ b/workitems.py @@ -2,6 +2,7 @@ import urllib, re, sys, optparse, os.path, datetime import sqlite3 as dbapi2 +from xml.sax.saxutils import escape blueprints_base_url = 'https://blueprints.launchpad.net' @@ -20,8 +21,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, @@ -41,6 +43,8 @@ def parse_argv(): help='Path to database', dest='database', metavar='PATH') optparser.add_option('-r', '--release', help='Release name', dest='release') + optparser.add_option('--milestone', + help='Milestone name', dest='milestone') optparser.add_option('-p', '--pattern', metavar='REGEX', help='Regex pattern for blueprint name', dest='pattern') optparser.add_option('-D', '--dump', action='store_true', default=False, @@ -71,31 +75,60 @@ def parse_argv(): return (opts, args) -def get_blueprints(url, name_pattern): +def get_blueprints(url, name_pattern, milestone): '''Return a list of blueprint URLs for the current release.''' blueprint_name_filter = re.compile('href="(/ubuntu/\+spec/%s[^"]+)"' % name_pattern) result = [] + scan_tr_end = False + found_ms = False + bp = None for l in urllib.urlopen(url): - m = blueprint_name_filter.search(l) - if m: - result.append(blueprints_base_url + m.group(1)) + if scan_tr_end: + if milestone: + if ('/+milestone/%s"' % milestone) in l: + found_ms = True + if '' in l: + scan_tr_end = False + if bp and (not milestone or found_ms): + result.append(bp) + bp = None + found_ms = False + else: + m = blueprint_name_filter.search(l) + if m: + bp = blueprints_base_url + m.group(1) + scan_tr_end = True return result 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 @@ -103,7 +136,7 @@ def get_blueprint_workitems(blueprint_url): if '

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

', '').strip() + l = l.replace('
', '').replace('', '').replace('

', '').replace('', '').strip() if not l: break @@ -127,7 +160,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 +239,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 +248,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.''' @@ -221,11 +265,11 @@ def add_status(db, blueprint, status): cur.execute('INSERT INTO status VALUES (?, ?, date(CURRENT_TIMESTAMP))', (blueprint, status)) -def import_lp(db, name_pattern, release): +def import_lp(db, name_pattern, release, milestone): '''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) + release), name_pattern, milestone) cur = db.cursor() cur.execute('DELETE FROM work_items WHERE date = date(CURRENT_TIMESTAMP)') @@ -238,8 +282,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): @@ -282,6 +326,30 @@ def blueprint_completion(db): return data +def assignee_completion(db): + '''Determine current by-assignee completion. + + Return assignee -> [todo, done, postponed] mapping. + ''' + data = {} + + # last date + cur = db.cursor() + cur.execute('SELECT max(date) FROM work_items') + (last_date,) = cur.fetchone() + + index = 0 + for s in valid_states: + cur = db.cursor() + cur.execute('SELECT assignee, count(workitem) FROM work_items ' + 'WHERE date=? and status=? GROUP BY assignee', + (last_date, s)) + for (a, num) in cur: + data.setdefault(a, [0, 0, 0])[index] = num + index += 1 + + return data + def text(db): '''Print work item completion as text.''' @@ -369,15 +437,36 @@ def html(db): completion.sort(key=lambda k: k[1], reverse=True) for (bp, percent) in completion: - if bp.startswith('http:'): + if bp.startswith('http:') or bp.startswith('https:'): url = bp else: - url = '%s/ubuntu/+spec/%s' % (blueprints_base_url, bp) + url = '%s/ubuntu/+spec/%s' % (blueprints_base_url, escape(bp)) print '
%s %i/%i/%i %i%% %s' % ( - url, bp, data[bp][0], data[bp][2], + url, escape(bp), data[bp][0], data[bp][2], data[bp][1], percent, - data[bp][-1]) + escape(data[bp][-1])) + + print '' + + print ''' +

Status by assignee

+ + +''' + data = assignee_completion(db) + + completion = [] + for (a, (todo, done, postponed)) in data.iteritems(): + completion.append((a, + int(float(postponed+done)/(todo+done+postponed)*100 + 0.5))) + + completion.sort(key=lambda k: k[0], reverse=False) + for (a, percent) in completion: + url = '%s/~%s/+specs?role=assignee' % (blueprints_base_url, a) + print ' ' % ( + url, escape(a), data[a][0], data[a][2], + data[a][1], percent) print '
Assignee todo/postponed/done Completion
%s %i/%i/%i %i%%
' print '' @@ -387,7 +476,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 @@ -406,7 +495,7 @@ elif opts.html: elif opts.csv: csv(db, opts.from_date, opts.to_date) else: - import_lp(db, opts.pattern, opts.release) + import_lp(db, opts.pattern, opts.release, opts.milestone) import_moin(db, opts.moin) db.commit()