]> piware.de Git - bin.git/commitdiff
workitems: add support for milestone filtering
authormartin@piware.de <>
Tue, 24 Nov 2009 17:17:02 +0000 (18:17 +0100)
committermartin@piware.de <>
Tue, 24 Nov 2009 17:17:02 +0000 (18:17 +0100)
workitems.py

index 7b22e60111fdf07fa49d9382c6feb3534418b4ca..dea7768d32facd932503b2cac1c59a6ad1aa5fc5 100755 (executable)
@@ -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 '</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
 
@@ -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()