public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Paweł Hajdan" <phajdan.jr@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/arch-tools:master commit in: /
Date: Sun, 22 May 2011 15:16:17 +0000 (UTC)	[thread overview]
Message-ID: <c113ff742b3910ef257dd3b4479020d6a8865919.phajdan.jr@gentoo> (raw)

commit:     c113ff742b3910ef257dd3b4479020d6a8865919
Author:     Pawel Hajdan, Jr <phajdan.jr <AT> gentoo <DOT> org>
AuthorDate: Sun May 22 15:16:03 2011 +0000
Commit:     Paweł Hajdan <phajdan.jr <AT> gentoo <DOT> org>
CommitDate: Sun May 22 15:16:03 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/arch-tools.git;a=commit;h=c113ff74

Cleanup: use a Bug class instead of raw XML processing all over the place.

---
 bugzilla-viewer.py |   76 ++++++++++++++++++++++++++++++++-------------------
 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)



             reply	other threads:[~2011-05-22 15:16 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-22 15:16 Paweł Hajdan [this message]
  -- strict thread matches above, loose matches on Subject: below --
2017-07-10 20:29 [gentoo-commits] proj/arch-tools:master commit in: / Paweł Hajdan
2017-07-09 14:42 Paweł Hajdan
2015-01-05 14:41 Paweł Hajdan
2015-01-05 14:41 Paweł Hajdan
2015-01-05 14:41 Paweł Hajdan
2014-06-14  9:47 Paweł Hajdan
2014-04-07 12:40 Samuli Suominen
2014-02-12  7:06 Paweł Hajdan
2013-06-22 15:05 Paweł Hajdan
2013-06-22 14:57 Paweł Hajdan
2013-05-19 23:35 Paweł Hajdan
2013-03-11 21:56 Paweł Hajdan
2013-02-28  4:50 Paweł Hajdan
2013-02-28  4:50 Paweł Hajdan
2012-10-16 16:54 Paweł Hajdan
2012-10-16 16:54 Paweł Hajdan
2012-10-08 16:03 Paweł Hajdan
2012-10-08 16:03 Paweł Hajdan
2012-10-08 16:03 Paweł Hajdan
2012-10-08 16:03 Paweł Hajdan
2012-10-08 16:03 Paweł Hajdan
2012-10-08 16:03 Paweł Hajdan
2012-10-08 16:03 Paweł Hajdan
2012-10-08 16:02 [gentoo-commits] proj/arch-tools:new-pybugz " Paweł Hajdan
2012-10-08 16:03 ` [gentoo-commits] proj/arch-tools:master " Paweł Hajdan
2012-08-01 11:08 [gentoo-commits] proj/arch-tools:new-pybugz " Paweł Hajdan
2012-10-08 16:03 ` [gentoo-commits] proj/arch-tools:master " Paweł Hajdan
2012-08-01  7:28 [gentoo-commits] proj/arch-tools:new-pybugz " Paweł Hajdan
2012-10-08 16:03 ` [gentoo-commits] proj/arch-tools:master " Paweł Hajdan
2012-06-04  9:18 [gentoo-commits] proj/arch-tools:new-pybugz " Paweł Hajdan
2012-10-08 16:03 ` [gentoo-commits] proj/arch-tools:master " Paweł Hajdan
2012-03-27 15:26 Paweł Hajdan
2012-03-09 11:49 Paweł Hajdan
2012-03-09 11:49 Paweł Hajdan
2012-02-02 16:48 Paweł Hajdan
2012-01-27 14:55 Paweł Hajdan
2012-01-21 17:05 Paweł Hajdan
2011-12-14  7:23 Paweł Hajdan
2011-12-06 11:14 Paweł Hajdan
2011-12-01 18:56 Paweł Hajdan
2011-12-01 18:47 Paweł Hajdan
2011-12-01 18:47 Paweł Hajdan
2011-11-30 17:38 Paweł Hajdan
2011-11-23  8:59 Paweł Hajdan
2011-11-23  8:59 Paweł Hajdan
2011-11-21  8:34 Paweł Hajdan
2011-11-03 11:00 Paweł Hajdan
2011-10-22  8:18 Paweł Hajdan
2011-10-21 15:15 Paweł Hajdan
2011-10-18 14:05 Paweł Hajdan
2011-10-16  3:51 Paweł Hajdan
2011-10-13 21:59 Paweł Hajdan
2011-10-04 21:46 Paweł Hajdan
2011-09-19  3:09 Paweł Hajdan
2011-08-07  3:26 Paweł Hajdan
2011-06-05 16:16 Paweł Hajdan
2011-06-02 15:41 Paweł Hajdan
2011-06-02 15:38 Paweł Hajdan
2011-05-25 19:51 Paweł Hajdan
2011-05-25 10:32 Paweł Hajdan
2011-05-22 15:31 Paweł Hajdan
2011-05-22 13:36 Paweł Hajdan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c113ff742b3910ef257dd3b4479020d6a8865919.phajdan.jr@gentoo \
    --to=phajdan.jr@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox