Permalink
Browse files

batch mode refinements

- store results in files called facet/tag-value (eg, suite/gnome)
- allow queries to be piped through stdin
- set dust value to n/a when applicable, instead of empty space
  • Loading branch information...
1 parent 15fa809 commit 04379a9e25f8e986c8b867ecd813a8343f61c6f1 Serafeim Zanikolas committed Jun 22, 2009
Showing with 23 additions and 9 deletions.
  1. +3 −0 batch_queries_test.txt
  2. +3 −3 lib/bugs.py
  3. +3 −3 test_wnpp_by_tags.py
  4. +14 −3 wnpp_by_tags.py
View
@@ -0,0 +1,3 @@
+implemented-in
+suite
+culture
View
@@ -47,12 +47,12 @@ def abbreviation_of(t):
class Bug(object):
- def __init__(self, bug_no, title=None, type=None, dust=None):
+ def __init__(self, bug_no, title=None, type=None, dust="n/a"):
# add bug title
self.bug_no = bug_no
self.title = title
self.type = type
- self.dust = dust if dust else ""
+ self.dust = dust
def get_bug_title(self):
if self.title is None:
pass # TODO: get it from bts
@@ -150,7 +150,7 @@ def extract_bugs(html_page_handle, pkgs_by_name, bug_type):
# change?
days_part = str(link.parent).split(",")[-1]
match = days_pat.search(days_part)
- dust = int(match.group(1)) if match else None
+ dust = int(match.group(1)) if match else "n/a"
pkg_obj = pkgs_by_name.get(pkgname)
if pkg_obj is None:
View
@@ -47,18 +47,18 @@ class QueryTest(unittest.TestCase):
prog = None
prog = "./wnpp_by_tags.py --cache-dir %s" % cache_dir
def testTagMatching1(self):
- expected_result = "RFA 447393 bins 29 \nO 503554 a2ps-perl-ja 28 "
+ expected_result = "RFA 447393 bins 29 n/a\nO 503554 a2ps-perl-ja 28 n/a"
status, output = run("%s -t o,rfa -m implemented-in::perl" % QueryTest.prog)
self.assertEqual(status, 0)
self.assertEqual(output, expected_result)
def testTagMatching2(self):
"""Same as previous test but for RFA only."""
- expected_result = "RFA 447393 bins 29 "
+ expected_result = "RFA 447393 bins 29 n/a"
status, output = run("%s -t rfa -m implemented-in::perl" % QueryTest.prog)
self.assertEqual(status, 0)
self.assertEqual(output, expected_result)
def testTagMatchingAndExclusion(self):
- expected_result = "RFA 447393 bins 29 "
+ expected_result = "RFA 447393 bins 29 n/a"
status, output = run("%s -t o,rfa -m implemented-in::perl -x use::printing" % \
QueryTest.prog)
self.assertEqual(status, 0)
View
@@ -107,9 +107,13 @@ def __init__(self):
if options.batch_qfile or options.batch_dir:
options.batch_qfile and options.batch_dir or \
parser.error("In batch mode, you have to specify both -b and -d")
- assert os.path.exists(options.batch_qfile)
+ if options.batch_qfile == "-":
+ queries_fd = sys.stdin
+ else:
+ assert os.path.exists(options.batch_qfile)
+ queries_fd = open(options.batch_qfile)
+ self.batch_queries = queries_fd.read().strip().split("\n")
ensure_dir_exists(options.batch_dir)
- self.batch_queries = open(options.batch_qfile).read().strip().split("\n")
self.batch_dir = options.batch_dir
else:
self.batch_queries = None
@@ -211,10 +215,17 @@ def main():
for facet in args.batch_queries:
if args.verbose:
print "processing \"%s\" tags" % facet
+ facet_dir = "%s/%s" % (args.batch_dir, facet)
+ ensure_dir_exists(facet_dir)
for tag in vocabulary.tags_of_facet(facet):
args.match_tags = set([tag])
pkg_objs = gen_matches(tag_db, pkgs_by_name, args)
- filename = "%s/%s.txt" % (args.batch_dir, tag)
+ try:
+ tag_value = tag.split("::")[1]
+ except ValueError:
+ warn("skipping invalid tag \"%s\"" % tag)
+ continue
+ filename = "%s/%s" % (facet_dir, tag_value)
matches = format_matches(pkg_objs, args)
create_file(filename, matches)
tag_db.seek(0)

0 comments on commit 04379a9

Please sign in to comment.