from __init__ import *
import rfc822
-class LaunchpadData:
+
+class LaunchpadTask:
+ def __init__(self, msg):
+ self.product = msg["task"]
+ self.status = msg["status"]
+
+
+class LaunchpadBug:
+ def __init__(self, text):
+ bug = rfc822.Message(text)
+ self.duplicate_of = bug.get("duplicate-of", None)
+ if self.duplicate_of == "":
+ self.duplicate_of = None
+ self.id = int(bug["bug"])
+ self.tasks = {}
+
+ # Find the task related to the product we're dealing
+ # with at the moment
+ task = rfc822.Message(text)
+ while "task" in task:
+ self.tasks[task["task"]] = LaunchpadTask(task)
+ task = rfc822.Message(text)
+
+
+class RemoteLaunchpadData:
def __init__(self, uri, id):
text = urllib.urlopen(urlparse.urljoin(uri+"/", "+text"))
else:
# https://bugs.launchpad.net/bugs/XXXXXX
product = None
+ self.resolution = None
- bug = rfc822.Message(text)
- if bug.get("duplicate-of", "") != "":
+ lp_bug = LaunchpadBug(text)
+ self.id = lp_bug.id
+
+ if lp_bug.duplicate_of is not None:
raise DupeExn(uri)
- self.id = int(bug["bug"])
- self.resolution = None
+ if product is None:
+ if len(lp_bug.tasks) != 1:
+ raise ParseExn(uri,
+ "No product specified but bug affects multiple products")
+ else:
+ self.status = lp_bug.tasks[lp_bugs.keys()[0]].status
- # Find the task related to the product we're dealing
- # with at the moment
- task = rfc822.Message(text)
- while "task" in task:
- if product is None or task["task"] == product:
- self.status = task["status"]
- return
- task = rfc822.Message(text)
- failwith(uri, "Not a bug in %s" % product)
+ if product not in lp_bug.tasks:
+ raise ParseExn(uri, "No task affecting product %s" % product)
+
+ self.status = lp_bug.tasks[product].status
class RemoteLaunchpad(RemoteBts):
def __init__(self, cnf):
bugre = r"^%(uri)s/(?:.*/)?\+bug/([0-9]+)$"
urifmt = "%(uri)s/\+bug/%(id)s"
- RemoteBts.__init__(self, cnf, bugre, urifmt, LaunchpadData)
+ RemoteBts.__init__(self, cnf, bugre, urifmt, RemoteLaunchpadData)
def isClosing(self, status, resolution):
return status == "Fix-Released" or status == "Fix-Committed"