From 1db9933d4649c567932a7bb18785b4a365574254 Mon Sep 17 00:00:00 2001 From: "martin@piware.de" <> Date: Tue, 24 Nov 2009 18:17:02 +0100 Subject: [PATCH] workitems: add support for milestone filtering --- workitems.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/workitems.py b/workitems.py index 7b22e60..dea7768 100755 --- a/workitems.py +++ b/workitems.py @@ -42,6 +42,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, @@ -72,17 +74,32 @@ 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 @@ -247,11 +264,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)') @@ -477,7 +494,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() -- 2.39.5