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,
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 '</tr>' 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
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)')
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()