prog = "./wnpp_by_tags.py --cache-dir %s" % cache_dir def testTagMatching1(self): expected_result = "RFA 447393 bins 151 n/a\nO 503554 a2ps-perl-ja 99 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 151 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 151 n/a" status, output = run("%s -t o,rfa -m implemented-in::perl -x use::printing" % \ QueryTest.prog) self.assertEqual(status, 0) self.assertEqual(output, expected_result) if __name__ == "__main__": try: unittest.main() except Exception, e: print e finally: # wipe cache directory try: rmtree(cache_dir) except Exception, e: warn("error while trying to remove '%s':\n\t%s" % (cache_dir, e))
def run(cmd): status, output = getstatusoutput(cmd) if status != 0: warn("the command '%s' failed" % cmd) return status, output
def main(): # parse user-supplied arguments args = Arguments() # sanity checks if not os.path.exists(args.debtags_file): giveup("The debtags file %s doesn't exist" % args.debtags_file) if not os.path.exists(args.tags_file): giveup("The tag vocabulary file %s doesn't exist" % args.tags_file) if args.match_tags or args.list_tags or args.batch_queries: vocabulary = TagVocabulary(args.tags_file) if args.list_tags: print vocabulary exit(0) invalid_tags = vocabulary.invalid_tags(args.match_tags.union(args.excl_tags)) if invalid_tags: giveup("The following tags are not listed in %s:\n%s" % \ (args.tags_file, "\n".join(list(invalid_tags)))) # misc initialisations bugs_dir = "%s/wnpp" % args.cache_dir popcon_dir = "%s/popcon" % args.cache_dir ensure_dir_exists(bugs_dir) ensure_dir_exists(popcon_dir) update_bug_data(args.force_update, bugs_dir, args.full_name_bug_types, args.conf.bugs_update_period_in_days, args.verbose) update_popcon_data(args.force_update, popcon_dir, args.conf.popcon_update_period_in_days, args.verbose) debtags = Debtags(open(args.debtags_file)) popcon_file = "%s/%s" % (popcon_dir, POPCON_FNAME) assert os.path.isfile(popcon_file) popcon = Popcon(open(popcon_file, "r")) Package.init_sources(debtags.tags_of_pkg, popcon.inst_of_pkg) # build dict of package objects, indexed by package name, using the HTML # BTS pages pkgs_by_name = {} for bug_page in glob("%s/*.html" % bugs_dir): bug_type = BugType.abbreviation_of(os.path.basename(bug_page)[:-5]) if bug_type in args.bug_types: pkgs_by_name = extract_bugs(open(bug_page, "r"), pkgs_by_name, bug_type) if args.show_untagged: # select only packages without tags pkg_objs = [p for p in pkgs_by_name.itervalues() if not p.tags] print format_matches(pkg_objs, args) exit(0) if args.verbose: nbugs = sum([len(p.bugs) for p in pkgs_by_name.itervalues()]) print "loaded %d bugs in %s packages" % (nbugs, len(pkgs_by_name)) # filter packages using user-supplied tags tag_db = StringIO("\n".join([str(p) for p in pkgs_by_name.itervalues()])) if not args.batch_queries: pkg_objs = gen_matches(tag_db, pkgs_by_name, args) print format_matches(pkg_objs, args) exit(0) # else we're in batch mode 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) 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)