コード例 #1
0
ファイル: __init__.py プロジェクト: rtnpro/faf
    def rhbz_bugs(self, count=100):
        comps = self.ses.query(OpSysComponent).all()
        releases = self.ses.query(OpSysRelease).all()
        rhbz_users = self.ses.query(RhbzUser).all()

        self.begin('Rhbz bugs')
        for i in range(count):
            comp = random.choice(comps)
            bug = RhbzBug()
            bug.id = 900000 + i*1337 # over 9000
            bug.summary = '[faf] Crash in component {0}'.format(comp)


            bug.status = random.choice(pyfaf.storage.rhbz.BUG_STATES)
            if bug.status == 'CLOSED':
                bug.resolution = random.choice(
                    pyfaf.storage.rhbz.BUG_RESOLUTIONS)

            when = datetime.now().date() + fuzzy_timedelta(
                months=random.randrange(-6, 0))

            bug.creation_time = when
            bug.last_change_time = when
            bug.opsysrelease = random.choice(releases)
            bug.component = comp
            bug.creator = random.choice(rhbz_users)
            bug.whiteboard = 'empty'
            self.add(bug)

        self.commit()
コード例 #2
0
ファイル: bugzilla.py プロジェクト: rtnpro/faf
    def save_bug(self, bug_dict):
        """
        Save bug represented by `bug_dict` to the database.

        If bug is marked as duplicate, the duplicate bug is downloaded
        as well.
        """

        logging.info("Saving bug #{0}: {1}".format(bug_dict["bug_id"],
                     bug_dict["summary"]))

        bug_id = bug_dict["bug_id"]

        # check if we already have this bug up-to-date
        old_bug = (
            self.db.session.query(RhbzBug)
            .filter(RhbzBug.id == bug_id)
            .filter(RhbzBug.last_change_time == bug_dict["last_change_time"])
            .first())

        if old_bug:
            logging.info("Bug already up-to-date")
            return old_bug

        opsysrelease = self.get_opsysrelease(bug_dict["product"],
                                             bug_dict["version"])

        if not opsysrelease:
            logging.error("Unable to save this bug due to unknown release")
            return

        component = self.get_component(opsysrelease, bug_dict["component"])

        if not component:
            logging.error("Unable to save this bug due to unknown component")
            return

        reporter = self.get_user(bug_dict["reporter"])
        if not reporter:
            logging.debug("Creator {0} not found".format(
                bug_dict["reporter"]))

            downloaded = self.download_user(bug_dict["reporter"])
            if not downloaded:
                logging.error("Unable to download user, skipping.")
                return

            reporter = self.save_user(downloaded)

        new_bug = RhbzBug()
        new_bug.id = bug_dict["bug_id"]
        new_bug.summary = bug_dict["summary"]
        new_bug.status = bug_dict["status"]
        new_bug.creation_time = bug_dict["creation_time"]
        new_bug.last_change_time = bug_dict["last_change_time"]

        if bug_dict["status"] == "CLOSED":
            new_bug.resolution = bug_dict["resolution"]
            if bug_dict["resolution"] == "DUPLICATE":
                if not self.get_bug(bug_dict["dupe_id"]):
                    logging.debug("Duplicate #{0} not found".format(
                        bug_dict["dupe_id"]))

                    downloaded = self.download_bug(bug_dict["dupe_id"])
                    if downloaded:
                        dup = self.save_bug(downloaded)
                        if dup:
                            new_bug.duplicate = dup.id

        new_bug.component_id = component.id
        new_bug.opsysrelease_id = opsysrelease.id
        new_bug.creator_id = reporter.id
        new_bug.whiteboard = bug_dict["status_whiteboard"]

        # the bug itself might be downloaded during duplicate processing
        # exit in this case - it would cause duplicate database entry
        if self.get_bug(bug_dict["bug_id"]):
            logging.debug("Bug #{0} already exists in storage,"
                          " updating".format(bug_dict["bug_id"]))

            bugdict = {}
            for col in new_bug.__table__._columns:
                bugdict[col.name] = getattr(new_bug, col.name)

            (self.db.session.query(RhbzBug)
                .filter(RhbzBug.id == bug_id).update(bugdict))

            new_bug = self.get_bug(bug_dict["bug_id"])
        else:
            self.db.session.add(new_bug)

        self.db.session.flush()

        self.save_ccs(bug_dict["cc"], new_bug.id)
        self.save_history(bug_dict["history"], new_bug.id)
        self.save_attachments(bug_dict["attachments"], new_bug.id)
        self.save_comments(bug_dict["comments"], new_bug.id)

        return new_bug