summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Hajdan, Jr <phajdan.jr@gentoo.org>2011-05-22 17:16:03 +0200
committerPawel Hajdan, Jr <phajdan.jr@gentoo.org>2011-05-22 17:16:03 +0200
commitc113ff742b3910ef257dd3b4479020d6a8865919 (patch)
treea2345c63bc3fd71eaf36472305cd150b26a4de95
parentCleanup: convert all indentation to tabs. (diff)
downloadarch-tools-c113ff742b3910ef257dd3b4479020d6a8865919.tar.gz
arch-tools-c113ff742b3910ef257dd3b4479020d6a8865919.tar.bz2
arch-tools-c113ff742b3910ef257dd3b4479020d6a8865919.zip
Cleanup: use a Bug class instead of raw XML processing all over the place.
-rwxr-xr-xbugzilla-viewer.py76
1 files changed, 48 insertions, 28 deletions
diff --git a/bugzilla-viewer.py b/bugzilla-viewer.py
index d1de3c0..e160a96 100755
--- a/bugzilla-viewer.py
+++ b/bugzilla-viewer.py
@@ -20,6 +20,29 @@ CPV_REGEX = re.compile("[A-Za-z0-9+_.-]+/[A-Za-z0-9+_-]+-[0-9]+(?:\.[0-9]+)*[a-z
class TermTooSmall(Exception):
pass
+class Bug:
+ def __init__(self, xml):
+ self.__id = int(xml.find("bug_id").text)
+ self.__summary = xml.find("short_desc").text
+ self.__status = xml.find("bug_status").text
+ self.__depends_on = [int(dep.text) for dep in xml.findall("dependson")]
+ self.__comments = [c.find("who").text + "\n" + c.find("thetext").text for c in xml.findall("long_desc")]
+
+ def id_number(self):
+ return self.__id
+
+ def summary(self):
+ return self.__summary
+
+ def status(self):
+ return self.__status
+
+ def depends_on(self):
+ return self.__depends_on
+
+ def comments(self):
+ return self.__comments
+
# Main class (called with curses.wrapper later).
class MainWindow:
def __init__(self, screen, bugs, bugs_dict, packages_dict, related_bugs, repoman_dict):
@@ -74,7 +97,7 @@ class MainWindow:
for i in range(len(self.bugs)):
self.bugs_pad.addstr(i, 0,
- " " + self.bugs[i].find('bug_id').text + " " + self.bugs[i].find('short_desc').text)
+ " %d %s" % (self.bugs[i].id_number(), self.bugs[i].summary()))
def scroll_bugs_pad(self, amount):
height = len(self.bugs)
@@ -106,46 +129,43 @@ class MainWindow:
bug = self.bugs[self.bugs_pad_pos]
output = []
- output += textwrap.wrap(bug.find("short_desc").text, width=width-2)
+ output += textwrap.wrap(bug.summary(), width=width-2)
output.append("-" * (width - 2))
- cpvs = self.packages_dict[bug.find("bug_id").text]
+ cpvs = self.packages_dict[bug.id_number()]
if cpvs:
output += textwrap.wrap("Found package cpvs:", width=width-2)
for cpv in cpvs:
output += textwrap.wrap(cpv, width=width-2)
output.append("-" * (width - 2))
- deps = bug.findall("dependson")
+ deps = [self.bugs_dict[dep_id] for dep_id in bug.depends_on()]
if deps:
output += textwrap.wrap("Depends on:", width=width-2)
for dep in deps:
- dep_bug = self.bugs_dict[dep.text]
- desc = dep.text + " " + dep_bug.find("bug_status").text + " " + dep_bug.find("short_desc").text
+ desc = "%d %s %s" % (dep.id_number(), dep.status(), dep.summary())
output += textwrap.wrap(desc, width=width-2)
output.append("-" * (width - 2))
- related = self.related_bugs[bug.find("bug_id").text]
+ related = self.related_bugs[bug.id_number()]
if related:
output += textwrap.wrap("Related bugs:", width=width-2)
for related_bug in related:
- if related_bug['bugid'] == bug.find("bug_id").text:
+ if str(related_bug['bugid']) == str(bug.id_number()):
continue
desc = related_bug['bugid'] + " " + related_bug['desc']
output += textwrap.wrap(desc, width=width-2)
output.append("-" * (width - 2))
- if bug.find("bug_id").text in repoman_dict and repoman_dict[bug.find("bug_id").text]:
+ if bug.id_number() in repoman_dict and repoman_dict[bug.id_number()]:
output += textwrap.wrap("Repoman output:", width=width-2)
- lines = repoman_dict[bug.find("bug_id").text].split("\n")
+ lines = repoman_dict[bug.id_number()].split("\n")
for line in lines:
output += textwrap.wrap(line, width=width-2)
output.append("-" * (width - 2))
- for elem in bug.findall("long_desc"):
- output += textwrap.wrap("%s:" % elem.find("who").text, width=width-2)
- lines = elem.find("thetext").text.split("\n")
- for line in lines:
+ for comment in bug.comments():
+ for line in comment.split("\n"):
output += textwrap.wrap(line, width=width-2)
output.append("-" * (width - 2))
@@ -196,7 +216,7 @@ if __name__ == "__main__":
print "Searching for arch bugs..."
raw_bugs = bugzilla.search("", cc="%s@gentoo.org" % options.arch, keywords="STABLEREQ")
- bugs = bugzilla.get([bug['bugid'] for bug in raw_bugs]).findall("bug")
+ bugs = [Bug(xml) for xml in bugzilla.get([bug['bugid'] for bug in raw_bugs]).findall("bug")]
dep_bug_ids = []
@@ -205,17 +225,17 @@ if __name__ == "__main__":
related_bugs = {}
repoman_dict = {}
for bug in bugs:
- print "Processing bug %s: %s" % (bug.find("bug_id").text, bug.find("short_desc").text)
- bugs_dict[bug.find("bug_id").text] = bug
- packages_dict[bug.find("bug_id").text] = []
- related_bugs[bug.find("bug_id").text] = []
- repoman_dict[bug.find("bug_id").text] = ""
- for cpv_candidate in CPV_REGEX.findall(bug.find("short_desc").text):
+ print "Processing bug %d: %s" % (bug.id_number(), bug.summary())
+ bugs_dict[bug.id_number()] = bug
+ packages_dict[bug.id_number()] = []
+ related_bugs[bug.id_number()] = []
+ repoman_dict[bug.id_number()] = ""
+ for cpv_candidate in CPV_REGEX.findall(bug.summary()):
if portage.db["/"]["porttree"].dbapi.cpv_exists(cpv_candidate):
- packages_dict[bug.find("bug_id").text].append(cpv_candidate)
+ packages_dict[bug.id_number()].append(cpv_candidate)
pv = portage.versions.cpv_getkey(cpv_candidate)
if options.verbose:
- related_bugs[bug.find("bug_id").text] += bugzilla.search(pv)
+ related_bugs[bug.id_number()] += bugzilla.search(pv)
if options.repo:
cvs_path = os.path.join(options.repo, pv)
@@ -226,11 +246,11 @@ if __name__ == "__main__":
original_contents = open(ebuild_path).read()
manifest_contents = open(manifest_path).read()
try:
- output = repoman_dict[bug.find("bug_id").text]
+ output = repoman_dict[bug.id_number()]
output += subprocess.Popen(["ekeyword", options.arch, ebuild_name], cwd=cvs_path, stdout=subprocess.PIPE).communicate()[0]
subprocess.check_call(["repoman", "manifest"], cwd=cvs_path)
output += subprocess.Popen(["repoman", "full"], cwd=cvs_path, stdout=subprocess.PIPE).communicate()[0]
- repoman_dict[bug.find("bug_id").text] = output
+ repoman_dict[bug.id_number()] = output
finally:
f = open(ebuild_path, "w")
f.write(original_contents)
@@ -238,12 +258,12 @@ if __name__ == "__main__":
f = open(manifest_path, "w")
f.write(manifest_contents)
f.close()
- dep_bug_ids += [dep.text for dep in bug.findall("dependson")]
+ dep_bug_ids += bug.depends_on()
dep_bug_ids = list(set(dep_bug_ids))
- dep_bugs = bugzilla.get(dep_bug_ids).findall("bug")
+ dep_bugs = [Bug(xml) for xml in bugzilla.get(dep_bug_ids).findall("bug")]
for bug in dep_bugs:
- bugs_dict[bug.find("bug_id").text] = bug
+ bugs_dict[bug.id_number()] = bug
try:
curses.wrapper(MainWindow, bugs=bugs, bugs_dict=bugs_dict, packages_dict=packages_dict, related_bugs=related_bugs, repoman_dict=repoman_dict)