Пример #1
0
    def parse_csv(self, file):
        """Parses a bugzilla-generated csv file

        This function gets a bugzilla-generated csv file and returns a list
        of bug objects."""

        data = csv.reader(file)
        data.next() # skips the header

        bugs = []

        for report in data: 
            bug = Bug(report[0], self)
            bug.set_severity(report[1])
            bug.set_priority(report[2])
            bug.set_assignee(report[3])
            bug.set_reporter(report[4])
            bug.set_status(report[5])
            bug.set_resolution(report[6])
            bug.set_product(report[7])
            bug.set_component(report[8])
            bug.set_version(report[9])
            bug.set_summary(report[10])
            bug.set_url("%s/show_bug.cgi?id=%s" % (self.baseurl, bug.get_id()))
            bugs.append(bug)

        return bugs
Пример #2
0
    def parse_html(self, handle):
        """Parses a bugzila-generated html file

        This functions gets a bugzilla-generated html file and returns
        a list of bug objects"""

        soup = BeautifulSoup(handle.read())
        bugs = []

        rows = soup.find("table", attrs = { "class" : "bz_buglist" })
        if not rows:
            # no bugs?
            if soup.find(text = lambda(str): str.find("Zarro") == 0):
                return bugs
            else:
                raise BugListParseError, "Couldn't find the bugs table"
        rows = rows.findAll("tr")[1:]

        for row in rows:
            cells = row.findAll("td")
            
            bug = Bug(cells[0].a.string, self)

            # Bug severity 
            if cells[1].string != None:
                severity = cells[1].string.strip()
            elif cells[1].nobr.string != None: # KDE's bugzilla
                severity = cells[1].nobr.string.strip()
            else:
                raise BugListParseError, "Couldn't get bug severity"

            if severity == "blo":
                bug.set_severity("blocker")
            elif severity == "cri":
                bug.set_severity("critical")
            elif severity == "maj":
                bug.set_severity("major")
            elif severity == "nor":
                bug.set_severity("normal")
            elif severity == "min":
                bug.set_severity("minor")
            elif severity == "tri":
                bug.set_severity("trivial")
            elif severity == "enh":
                bug.set_severity("enhancement")
            elif severity == "gra":  # KDE's bugzilla
                bug.set_severity("grave")
            elif severity == "cra":  # KDE's bugzilla
                bug.set_severity("crash")
            elif severity == "wis":
                bug.set_severity("wishlist")
            else:
                bug.set_severity(severity) 
            
            # Bug priority
            if cells[2].string:
                bug.set_priority(cells[2].string.strip())
            elif cells[2].nobr.string: # KDE's bugzilla
                bug.set_priority(cells[2].nobr.string.strip())
            else:
                raise BugListParseError, "Couldn't get bug priority"

            # Bug owner
            if cells[3].string:
                bug.set_assignee(cells[3].string.strip())
            elif cells[3].nobr.string: # KDE's bugzilla
                bug.set_assignee(cells[3].nobr.string.strip())
            else:
                raise BugListParseError, "Couldn't get bug owner"

            # Bug reporter
            if cells[4].string:
                bug.set_reporter(cells[4].string.strip())
            elif cells[4].nobr.string: # KDE's bugzilla
                bug.set_reporter(cells[4].nobr.string.strip())
            else:
                raise BugListParseError, "Couldn't get bug reporter"

            # Bug status
            if cells[5].string:
                status = cells[5].string.strip()
            elif cells[5].nobr.string: # KDE's bugzilla
                status = cells[5].nobr.string.strip()
            else:
                raise BugListParseError, "Couldn't get bug status"

            if status == "UNCO":
                bug.set_status("UNCONFIRMED")
            elif status == "ASSI":
                bug.set_status = ("ASSIGNED")
            elif status == "REOP":
                bug.set_status = ("REOPENED")
            elif status == "RESO":
                bug.set_status("RESOLVED")
            elif status == "VERI":
                bug.set_status("VERIFIED")
            elif status == "CLOS":
                bug.set_status("CLOSED")
            elif status == "NEED": # Gnome's Bugzilla
                bug.set_status("NEEDINFO")
            else:
                bug.set_status(status)
    
            # Bug resolution
            if cells[6].string:
                resolution = cells[6].string.strip()
            elif cells[6].nobr.string: # KDE's bugzilla
                resolution = cells[6].nobr.string.strip()
            else:
                if bug.get_status() in ["RESOLVED", "VERIFIED", "CLOSED"]:
                    raise BugListParseError, "Couldn't get bug resolution"
                else:
                    resolution = ""

            if resolution == "FIXE":
                bug.set_resolution("FIXED")
            elif resolution == "INVA":
                bug.set_resolution("INVALID")
            elif resolution == "WONT":
                bug.set_resolution("WONTFIX")
            elif resolution == "LATE":
                bug.set_resolution("LATER")
            elif resolution == "REMI":
                bug.set_resolution("REMIND")
            elif resolution == "DUPL":
                bug.set_resolution("DUPLICATE")
            elif resolution == "WORK":
                bug.set_resolution("WORKSFORME")
            elif resolution == "MOVE":
                bug.set_resolution("MOVED")
            elif resolution == "NOTA":  # Gnome's Bugzilla
                bug.set_resolution("NOTABUG")
            elif resolution == "NOTG":  # Gnome's Bugzilla
                bug.set_resolution("NOTGNOME")
            elif resolution == "INCO":  # Gnome's Bugzilla
                bug.set_resolution("INCOMPLETE")
            elif resolution == "GNOM":  # Gnome's Bugzilla
                bug.set_resolution("GNOME1.X")
            elif resolution == "OBSO":  # Gnome's Bugzilla
                bug.set_resolution("OBSOLETE")
            elif resolution == "NOTX":  # Gnome's Bugzilla
                bug.set_resolution("NOTXIMIAN")
            else:
                bug.set_resolution(resolution)

            # Bug product
            if cells[7].string:
                bug.set_product(cells[7].string.strip())
            elif cells[7].nobr.string: # KDE's bugzilla
                bug.set_product(cells[7].nobr.string.strip())
            else:
                raise BugListParseError, "Couldn't get bug product"

            # Bug component
            if cells[8].string:
                bug.set_component(cells[8].string.strip())
            elif cells[8].nobr.string: # KDE's bugzilla
                bug.set_component(cells[8].nobr.string.strip())
            else:
                raise BugListParseError, "Couldn't get bug component"

            # Bug version
            if cells[9].string:
                bug.set_version(cells[9].string.strip())
            elif cells[9].nobr.string: # KDE's bugzilla
                bug.set_version(cells[9].nobr.string.strip())
            else:
                raise BugListParseError, "Couldn't get bug version"

            # Bug summary
            if cells[10].string:
                bug.set_summary(cells[10].string.strip())
            elif cells[10].nobr.string: # KDE's bugzilla
                bug.set_summary(cells[10].nobr.string.strip())
            else:
                raise BugListParseError, "Couldn't get bug summary"

            # Bug URL
            bug.set_url("%s/show_bug.cgi?id=%s" % (self.baseurl, bug.get_id()))

            bugs.append(bug)

        return bugs