コード例 #1
0
ファイル: mark_probably_fixed.py プロジェクト: mjtrangoni/faf
    def _get_tasks(self, cmdline, db):
        result = set()

        # no arguments - pull everything for non-EOL releases
        if not cmdline.opsys:
            for osplugin in systems.values():
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    raise FafError("Operating system '{0}' is not defined in "
                                   "storage".format(osplugin.nice_name))

                for db_release in db_opsys.releases:
                    if db_release.status != "EOL":
                        result.add((osplugin, db_release))

        # a single opsys - respect opsysrelease
        elif len(cmdline.opsys) == 1:
            if cmdline.opsys[0] not in systems:
                raise FafError("Operating system '{0}' is not supported"
                               .format(cmdline.opsys[0]))

            osplugin = systems[cmdline.opsys[0]]
            db_opsys = get_opsys_by_name(db, osplugin.nice_name)
            if db_opsys is None:
                raise FafError("Operating system '{0}' is not defined in "
                               "storage".format(osplugin.nice_name))

            if not cmdline.opsys_release:
                for db_release in db_opsys.releases:
                    result.add((osplugin, db_release))
            else:
                for release in cmdline.opsys_release:
                    db_release = get_osrelease(db, osplugin.nice_name, release)
                    if db_release is None:
                        self.log_warn("Operating system '{0} {1}' is not "
                                      "supported".format(osplugin.nice_name,
                                                         release))
                        continue

                    result.add((osplugin, db_release))

        # multiple opsys - pull all of their releases
        else:
            for opsys_name in cmdline.opsys:
                if not opsys_name in systems:
                    self.log_warn("Operating system '{0}' is not supported"
                                  .format(opsys_name))
                    continue

                osplugin = systems[opsys_name]
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    self.log_warn("Operating system '{0}' is not defined in "
                                  "storage".format(osplugin.nice_name))
                    continue

                for db_release in db_opsys.releases:
                    result.add((osplugin, db_release))

        return sorted(result, key=lambda p_r: (p_r[1].opsys.name, p_r[1].version))
コード例 #2
0
    def run(self, cmdline, db):
        if cmdline.opsys is None:
            self.log_error("You must specify an operating system")
            return 1

        if not cmdline.opsys in systems:
            self.log_error("Operating system '{0}' does not exist"
                           .format(cmdline.opsys))
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '{0}' is not installed"
                           .format(opsys.nice_name))
            return 1

        db_release = get_osrelease(db, opsys.nice_name, cmdline.opsys_release)
        if db_release is None:
            self.log_info("Release '{0} {1}' is not defined"
                          .format(opsys.nice_name, cmdline.opsys_release))
            return 1

        if cmdline.status is not None and cmdline.status != db_release.status:
            if not cmdline.status in OpSysReleaseStatus.enums:
                self.log_error("Status '{0}' is invalid".format(cmdline.status))
                return 1

            self.log_info("Updating status of '{0} {1}': {2} ~> {3}"
                          .format(opsys.nice_name, db_release.version,
                                  db_release.status, cmdline.status))

            db_release.status = cmdline.status

        db.session.flush()
コード例 #3
0
    def _get_tasks(self, cmdline, db):
        result = set()

        # no arguments - pull everything for non-EOL releases
        if not cmdline.opsys:
            for osplugin in systems.values():
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    raise FafError("Operating system '{0}' is not defined in "
                                   "storage".format(osplugin.nice_name))

                for db_release in db_opsys.releases:
                    if db_release.status != "EOL":
                        result.add((osplugin, db_release))

        # a single opsys - respect opsysrelease
        elif len(cmdline.opsys) == 1:
            if cmdline.opsys[0] not in systems:
                raise FafError("Operating system '{0}' is not supported"
                               .format(cmdline.opsys[0]))

            osplugin = systems[cmdline.opsys[0]]
            db_opsys = get_opsys_by_name(db, osplugin.nice_name)
            if db_opsys is None:
                raise FafError("Operating system '{0}' is not defined in "
                               "storage".format(osplugin.nice_name))

            if len(cmdline.opsys_release) < 1:
                for db_release in db_opsys.releases:
                    result.add((osplugin, db_release))
            else:
                for release in cmdline.opsys_release:
                    db_release = get_osrelease(db, osplugin.nice_name, release)
                    if db_release is None:
                        self.log_warn("Operating system '{0} {1}' is not "
                                      "supported".format(osplugin.nice_name,
                                                         release))
                        continue

                    result.add((osplugin, db_release))

        # multiple opsys - pull all of their releases
        else:
            for opsys_name in cmdline.opsys:
                if not opsys_name in systems:
                    self.log_warn("Operating system '{0}' is not supported"
                                  .format(opsys_name))
                    continue

                osplugin = systems[opsys_name]
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    self.log_warn("Operating system '{0}' is not defined in "
                                  "storage".format(osplugin.nice_name))
                    continue

                for db_release in db_opsys.releases:
                    result.add((osplugin, db_release))

        return sorted(result, key=lambda p_r: (p_r[1].opsys.name, p_r[1].version))
コード例 #4
0
ファイル: releasemod.py プロジェクト: mjtrangoni/faf
    def run(self, cmdline, db):
        if cmdline.opsys is None:
            self.log_error("You must specify an operating system")
            return 1

        if not cmdline.opsys in systems:
            self.log_error("Operating system '{0}' does not exist"
                           .format(cmdline.opsys))
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '{0}' is not installed"
                           .format(opsys.nice_name))
            return 1

        db_release = get_osrelease(db, opsys.nice_name, cmdline.opsys_release)
        if db_release is None:
            self.log_info("Release '{0} {1}' is not defined"
                          .format(opsys.nice_name, cmdline.opsys_release))
            return 1

        if cmdline.status is not None and cmdline.status != db_release.status:
            if not cmdline.status in OpSysReleaseStatus.enums:
                self.log_error("Status '{0}' is invalid".format(cmdline.status))
                return 1

            self.log_info("Updating status of '{0} {1}': {2} ~> {3}"
                          .format(opsys.nice_name, db_release.version,
                                  db_release.status, cmdline.status))

            db_release.status = cmdline.status

        db.session.flush()
コード例 #5
0
ファイル: fedora.py プロジェクト: xsuchy/faf
    def save_ureport(self,
                     db,
                     db_report,
                     ureport,
                     packages,
                     flush=False,
                     count=1):
        if "desktop" in ureport:
            db_release = get_osrelease(db, Fedora.nice_name,
                                       ureport["version"])
            if db_release is None:
                self.log_warn("Release '{0} {1}' not found".format(
                    Fedora.nice_name, ureport["version"]))
            else:
                db_reldesktop = get_report_release_desktop(
                    db, db_report, db_release, ureport["desktop"])
                if db_reldesktop is None:
                    db_reldesktop = ReportReleaseDesktop()
                    db_reldesktop.report = db_report
                    db_reldesktop.release = db_release
                    db_reldesktop.desktop = ureport["desktop"]
                    db_reldesktop.count = 0
                    db.session.add(db_reldesktop)

                db_reldesktop.count += count

        self._save_packages(db, db_report, packages, count=count)

        if flush:
            db.session.flush()
コード例 #6
0
ファイル: cleanup_packages.py プロジェクト: mjtrangoni/faf
    def run(self, cmdline, db):
        # nobody will write the full name
        if cmdline.OPSYS == "rhel":
            cmdline.OPSYS = "Red Hat Enterprise Linux"

        # check if operating system is known
        if not get_opsys_by_name(db, cmdline.OPSYS):
            self.log_error("Selected operating system '{0}' is not supported."
                           .format(cmdline.OPSYS))
            return 1

        self.log_info("Selected operating system: '{0}'"
                      .format(cmdline.OPSYS))

        # check if release is known
        opsysrelease = get_osrelease(db, cmdline.OPSYS, cmdline.RELEASE)
        if not opsysrelease:
            self.log_error("Selected release '{0}' is not supported."
                           .format(cmdline.RELEASE))
            return 1

        self.log_info("Selected release: '{0}'".format(cmdline.RELEASE))

        # find all builds, that are assigned to this opsysrelease but none other
        # architecture is missed out intentionally
        bosra1 = aliased(BuildOpSysReleaseArch)
        bosra2 = aliased(BuildOpSysReleaseArch)
        all_builds = (db.session.query(bosra1)
                      .filter(bosra1.opsysrelease_id == opsysrelease.id)
                      .filter(~bosra1.build_id.in_(
                          db.session.query(bosra2.build_id)
                          .filter(bosra1.build_id == bosra2.build_id)
                          .filter(bosra2.opsysrelease_id != opsysrelease.id)
                      ))
                      .all())

        #delete all records, where the opsysrelease.id is present
        query = (db.session.query(BuildOpSysReleaseArch)
                 .filter(BuildOpSysReleaseArch.opsysrelease_id == opsysrelease.id))

        self.log_info("{0} links will be removed".format(query.count()))
        if cmdline.dry_run:
            self.log_info("Dry run active, removal will be skipped")
        else:
            query.delete()

        #delete all builds and packages from them
        for build in all_builds:
            for pkg in (db.session.query(Package)
                        .filter(Package.build_id == build.build_id)
                        .all()):
                self.delete_package(pkg, db, cmdline.dry_run)
コード例 #7
0
ファイル: cleanup_packages.py プロジェクト: sanjana098/faf
    def run(self, cmdline, db):
        # nobody will write the full name
        if cmdline.OPSYS == "rhel":
            cmdline.OPSYS = "Red Hat Enterprise Linux"

        # check if operating system is known
        if not get_opsys_by_name(db, cmdline.OPSYS):
            self.log_error(
                "Selected operating system '{0}' is not supported.".format(
                    cmdline.OPSYS))
            return 1

        self.log_info("Selected operating system: '{0}'".format(cmdline.OPSYS))

        # check if release is known
        opsysrelease = get_osrelease(db, cmdline.OPSYS, cmdline.RELEASE)
        if not opsysrelease:
            self.log_error("Selected release '{0}' is not supported.".format(
                cmdline.RELEASE))
            return 1

        self.log_info("Selected release: '{0}'".format(cmdline.RELEASE))

        # find all builds, that are assigned to this opsysrelease but none other
        # architecture is missed out intentionally
        bosra1 = aliased(BuildOpSysReleaseArch)
        bosra2 = aliased(BuildOpSysReleaseArch)
        all_builds = (db.session.query(bosra1).filter(
            bosra1.opsysrelease_id == opsysrelease.id).filter(
                ~bosra1.build_id.in_(
                    db.session.query(bosra2.build_id).filter(
                        bosra1.build_id == bosra2.build_id).filter(
                            bosra2.opsysrelease_id != opsysrelease.id))).all())

        #delete all records, where the opsysrelease.id is present
        query = (db.session.query(BuildOpSysReleaseArch).filter(
            BuildOpSysReleaseArch.opsysrelease_id == opsysrelease.id))

        self.log_info("{0} links will be removed".format(query.count()))
        if cmdline.dry_run:
            self.log_info("Dry run active, removal will be skipped")
        else:
            query.delete()

        #delete all builds and packages from them
        for build in all_builds:
            for pkg in (db.session.query(Package).filter(
                    Package.build_id == build.build_id).all()):
                self.delete_package(pkg, cmdline.dry_run)
        return 0
コード例 #8
0
    def run(self, cmdline, db):
        if cmdline.opsys is None:
            self.log_error("You must specify an operating system")
            return 1

        if not cmdline.opsys in systems:
            self.log_error("Operating system '{0}' does not exist".format(
                cmdline.opsys))
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '{0}' is not installed".format(
                opsys.nice_name))
            return 1

        db_component = get_component_by_name(db, cmdline.COMPONENT,
                                             opsys.nice_name)
        if db_component is None:
            self.log_info(
                "Adding component '{0}' to operating system '{1}'".format(
                    cmdline.COMPONENT, opsys.nice_name))

            db_component = OpSysComponent()
            db_component.opsys = db_opsys
            db_component.name = cmdline.COMPONENT
            db.session.add(db_component)

        for release in cmdline.opsys_release:
            db_release = get_osrelease(db, opsys.nice_name, release)
            if db_release is None:
                self.log_warn("Release '{0} {1}' is not defined".format(
                    opsys.nice_name, release))
                continue

            db_relcomponent = get_component_by_name_release(
                db, db_release, cmdline.COMPONENT)
            if db_relcomponent is None:
                self.log_info("Adding component '{0}' to '{1} {2}'".format(
                    cmdline.COMPONENT, opsys.nice_name, release))

                db_relcomponent = OpSysReleaseComponent()
                db_relcomponent.component = db_component
                db_relcomponent.release = db_release
                db.session.add(db_relcomponent)

        db.session.flush()
        return 0
コード例 #9
0
ファイル: componentadd.py プロジェクト: abrt/faf
    def run(self, cmdline, db):
        if cmdline.opsys is None:
            self.log_error("You must specify an operating system")
            return 1

        if not cmdline.opsys in systems:
            self.log_error("Operating system '{0}' does not exist"
                           .format(cmdline.opsys))
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '{0}' is not installed"
                           .format(opsys.nice_name))
            return 1

        db_component = get_component_by_name(db, cmdline.COMPONENT,
                                             opsys.nice_name)
        if db_component is None:
            self.log_info("Adding component '{0}' to operating system '{1}'"
                          .format(cmdline.COMPONENT, opsys.nice_name))

            db_component = OpSysComponent()
            db_component.opsys = db_opsys
            db_component.name = cmdline.COMPONENT
            db.session.add(db_component)

        for release in cmdline.opsys_release:
            db_release = get_osrelease(db, opsys.nice_name, release)
            if db_release is None:
                self.log_warn("Release '{0} {1}' is not defined"
                              .format(opsys.nice_name, release))
                continue

            db_relcomponent = get_component_by_name_release(db, db_release,
                                                            cmdline.COMPONENT)
            if db_relcomponent is None:
                self.log_info("Adding component '{0}' to '{1} {2}'"
                              .format(cmdline.COMPONENT,
                                      opsys.nice_name, release))

                db_relcomponent = OpSysReleaseComponent()
                db_relcomponent.component = db_component
                db_relcomponent.release = db_release
                db.session.add(db_relcomponent)

        db.session.flush()
        return 0
コード例 #10
0
    def run(self, cmdline, db):
        if cmdline.opsys is None:
            self.log_error("You must specify the operating system.")
            return 1

        if cmdline.opsys_release is None:
            self.log_error("You must specify the operating system release.")
            return 1

        if cmdline.opsys not in systems:
            self.log_error("Operating system '%s' does not exist",
                           cmdline.opsys)
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '%s' is not installed",
                           opsys.nice_name)
            return 1

        db_release = get_osrelease(db, opsys.nice_name, cmdline.opsys_release)
        if db_release is None:
            self.log_info("Release '%s %s' is not defined", opsys.nice_name,
                          cmdline.opsys_release)
            return 1

        self.log_info("Deleting release '{0} {1}'".format(
            opsys.nice_name, cmdline.opsys_release))

        db_release_id = db_release.id

        self._delete_mantis_bugs(db, db_release_id)
        self._delete_bugzilla_bugs(db, db_release_id)
        self._delete_release_builds(db, db_release_id)
        self._delete_release_repos(db, db_release_id)
        self._delete_release_reports(db, db_release_id)
        self._delete_release_problems(db, db_release_id)

        (db.session.query(st.OpSysReleaseComponent).filter(
            st.OpSysReleaseComponent.opsysreleases_id == db_release_id).delete(
                False))

        db.session.delete(db_release)
        db.session.flush()

        self.log_info("Done")
        return 0
コード例 #11
0
ファイル: releasedel.py プロジェクト: abrt/faf
    def run(self, cmdline, db):
        if cmdline.opsys is None:
            self.log_error("You must specify the operating system.")
            return 1

        if cmdline.opsys_release is None:
            self.log_error("You must specify the operating system release.")
            return 1

        if cmdline.opsys not in systems:
            self.log_error("Operating system '%s' does not exist", cmdline.opsys)
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '%s' is not installed", opsys.nice_name)
            return 1

        db_release = get_osrelease(db, opsys.nice_name, cmdline.opsys_release)
        if db_release is None:
            self.log_info("Release '%s %s' is not defined", opsys.nice_name, cmdline.opsys_release)
            return 1

        self.log_info("Deleting release '{0} {1}'"
                      .format(opsys.nice_name, cmdline.opsys_release))

        db_release_id = db_release.id

        self._delete_mantis_bugs(db, db_release_id)
        self._delete_bugzilla_bugs(db, db_release_id)
        self._delete_release_builds(db, db_release_id)
        self._delete_release_repos(db, db_release_id)
        self._delete_release_reports(db, db_release_id)
        self._delete_release_problems(db, db_release_id)

        (db.session.query(st.OpSysReleaseComponent)
         .filter(st.OpSysReleaseComponent.opsysreleases_id == db_release_id)
         .delete(False))

        db.session.delete(db_release)
        db.session.flush()

        self.log_info("Done")
        return 0
コード例 #12
0
ファイル: releaseadd.py プロジェクト: mkutlak/faf
    def run(self, cmdline, db) -> int:
        if cmdline.opsys is None:
            self.log_error("You must specify an operating system")
            return 1

        if not cmdline.opsys in systems:
            self.log_error("Operating system '{0}' does not exist".format(
                cmdline.opsys))
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '{0}' is not installed".format(
                opsys.nice_name))
            return 1

        db_release = get_osrelease(db, opsys.nice_name, cmdline.opsys_release)
        if db_release is not None:
            self.log_info("Release '{0} {1}' is already defined".format(
                opsys.nice_name, cmdline.opsys_release))
            return 0

        if not cmdline.status in OpSysReleaseStatus.enums:
            self.log_error("Status '{0}' is invalid".format(cmdline.status))
            return 1

        self.log_info("Adding release '{0} {1}'".format(
            opsys.nice_name, cmdline.opsys_release))
        db_release = OpSysRelease()
        db_release.opsys = db_opsys
        db_release.version = cmdline.opsys_release
        db_release.status = cmdline.status
        db.session.add(db_release)

        db.session.flush()

        return 0
コード例 #13
0
ファイル: fedora.py プロジェクト: mjtrangoni/faf
    def save_ureport(self, db, db_report, ureport, packages, flush=False, count=1):
        if "desktop" in ureport:
            db_release = get_osrelease(db, Fedora.nice_name, ureport["version"])
            if db_release is None:
                self.log_warn("Release '{0} {1}' not found"
                              .format(Fedora.nice_name, ureport["version"]))
            else:
                db_reldesktop = get_report_release_desktop(db, db_report,
                                                           db_release,
                                                           ureport["desktop"])
                if db_reldesktop is None:
                    db_reldesktop = ReportReleaseDesktop()
                    db_reldesktop.report = db_report
                    db_reldesktop.release = db_release
                    db_reldesktop.desktop = ureport["desktop"]
                    db_reldesktop.count = 0
                    db.session.add(db_reldesktop)

                db_reldesktop.count += count

        self._save_packages(db, db_report, packages, count=count)

        if flush:
            db.session.flush()
コード例 #14
0
ファイル: assign_release_to_builds.py プロジェクト: abrt/faf
    def run(self, cmdline, db):
        # nobody will write the full name
        if cmdline.OPSYS == "rhel":
            cmdline.OPSYS = "Red Hat Enterprise Linux"

        # check if operating system is known
        if not get_opsys_by_name(db, cmdline.OPSYS):
            self.log_error("Selected operating system '{0}' is not supported."
                           .format(cmdline.OPSYS))
            return 1

        self.log_info("Selected operating system: '{0}'"
                      .format(cmdline.OPSYS))

        # check if release is known
        opsysrelease = get_osrelease(db, cmdline.OPSYS, cmdline.RELEASE)
        if not opsysrelease:
            self.log_error("Selected release '{0}' is not supported."
                           .format(cmdline.RELEASE))
            return 1

        self.log_info("Selected release: '{0}'".format(cmdline.RELEASE))

        # check if architecture is known
        arch = get_arch_by_name(db, cmdline.ARCH)
        if not arch:
            self.log_error("Selected architecture '{0}' is not supported."
                           .format(cmdline.ARCH))
            return 1

        self.log_info("Selected architecture: '{0}'".format(cmdline.ARCH))

        # when release-builds argument specified
        if cmdline.released_builds:
            self.log_info("Assigning released builds for '{0} {1}'"
                          .format(cmdline.OPSYS, cmdline.RELEASE))
            opsys = self._edit_opsys(cmdline.OPSYS)
            if opsys not in systems.keys():
                self.log_error("There are no known released builds for '{0}'"
                               .format(cmdline.OPSYS))
                return 1

            for build in systems[opsys].get_released_builds(cmdline.RELEASE):
                found_build = (db.session.query(Build)
                               .filter(Build.base_package_name == build["name"])
                               .filter(Build.version == build["version"])
                               .filter(Build.release == build["release"])
                               .filter(Build.epoch == build["epoch"])
                               .first())

                if found_build:
                    self._add_into_build_opsysrelease_arch(db, found_build,
                                                           opsysrelease, arch)

        # when expression argument was passed
        if cmdline.expression:
            self.log_info("Selecting builds by expression: '{0}'"
                          .format(cmdline.expression))
            found_builds = (db.session.query(Build)
                            .filter(Build.release.like("%{0}"
                                                       .format(cmdline.expression)))
                            .all())
            for build in found_builds:
                self._add_into_build_opsysrelease_arch(db, build,
                                                       opsysrelease, arch)

        db.session.flush()
        return 0
コード例 #15
0
    def run(self, cmdline, db) -> int:
        if not cmdline.OPSYS and not cmdline.RELEASE and not cmdline.arch:
            self.log_error("None of the arguments were specified.")
            return 1

        if (cmdline.OPSYS or cmdline.RELEASE) and cmdline.arch:
            self.log_error(
                "Argument --arch not allowed with OPSYS and RELEASE.")
            return 1

        if cmdline.OPSYS and not cmdline.RELEASE:
            self.log_error("Missing RELEASE argument.")
            return 1

        # in case we're using the web UI:
        if not hasattr(cmdline, "dry_run"):
            cmdline.dry_run = False

        if cmdline.OPSYS:
            # nobody will write the full name
            if cmdline.OPSYS == "rhel":
                cmdline.OPSYS = "Red Hat Enterprise Linux"

            # check if operating system is known
            if not get_opsys_by_name(db, cmdline.OPSYS):
                self.log_error(
                    "Selected operating system '%s' is not supported.",
                    cmdline.OPSYS)
                return 1

            self.log_info("Selected operating system: '%s'", cmdline.OPSYS)

            # check if release is known
            opsysrelease = get_osrelease(db, cmdline.OPSYS, cmdline.RELEASE)
            if not opsysrelease:
                self.log_error("Selected release '%s' is not supported.",
                               cmdline.RELEASE)
                return 1

            self.log_info("Selected release: '%s'", cmdline.RELEASE)

            # find all builds, that are assigned to this opsysrelease but none other
            # architecture is missed out intentionally
            all_builds = get_builds_by_opsysrelease_id(db, opsysrelease.id)

            #delete all records, where the opsysrelease.id is present
            query = (db.session.query(BuildOpSysReleaseArch).filter(
                BuildOpSysReleaseArch.opsysrelease_id == opsysrelease.id))

        elif cmdline.arch:
            # check if operating system is known
            architecture = get_arch_by_name(db, cmdline.arch)
            if not architecture:
                self.log_error("Selected architecture '%s' is not supported.",
                               cmdline.arch)
                return 1

            self.log_info("Selected architecture: '%s'", cmdline.arch)

            # find all builds, that are assigned to this arch_id but none other
            all_builds = get_builds_by_arch_id(db, architecture.id)

            #delete all records, where the arch.id is present
            query = (db.session.query(BuildOpSysReleaseArch).filter(
                BuildOpSysReleaseArch.arch_id == architecture.id))

        else:
            self.log_error(
                "Architecture or operating system was not selected.")
            return 1

        self.log_info("%d links will be removed", query.count())
        if cmdline.dry_run:
            self.log_info("Dry run active, removal will be skipped")
        else:
            for build in all_builds:
                for pkg in (db.session.query(Package).filter(
                        Package.build_id == build.build_id).all()):
                    self.delete_package(pkg, cmdline.dry_run)

            query.delete()

        return 0
コード例 #16
0
def save_ureport2(db,
                  ureport,
                  create_component=False,
                  timestamp=None,
                  count=1):
    """
    Save uReport2
    """
    if timestamp is None:
        timestamp = datetime.datetime.utcnow()

    osplugin = systems[ureport["os"]["name"]]
    problemplugin = problemtypes[ureport["problem"]["type"]]

    db_osrelease = get_osrelease(db, osplugin.nice_name,
                                 ureport["os"]["version"])
    if db_osrelease is None:
        raise FafError(
            "Operating system '{0} {1}' not found in storage".format(
                osplugin.nice_name, ureport["os"]["version"]))

    report_hash = problemplugin.hash_ureport(ureport["problem"])
    db_report = get_report(db, report_hash)
    if db_report is None:
        component_name = problemplugin.get_component_name(ureport["problem"])
        db_component = get_component_by_name(db, component_name,
                                             osplugin.nice_name)
        if db_component is None:
            if create_component:
                log.info("Creating an unsupported component '{0}' in "
                         "operating system '{1}'".format(
                             component_name, osplugin.nice_name))
                db_component = OpSysComponent()
                db_component.name = component_name
                db_component.opsys = db_osrelease.opsys
                db.session.add(db_component)
            else:
                raise FafError("Unknown component '{0}' in operating system "
                               "{1}".format(component_name,
                                            osplugin.nice_name))

        db_report = Report()
        db_report.type = problemplugin.name
        db_report.first_occurrence = timestamp
        db_report.last_occurrence = timestamp
        db_report.count = 0
        db_report.component = db_component
        db.session.add(db_report)

        db_report_hash = ReportHash()
        db_report_hash.report = db_report
        db_report_hash.hash = report_hash
        db.session.add(db_report_hash)

    if db_report.first_occurrence > timestamp:
        db_report.first_occurrence = timestamp

    if db_report.last_occurrence < timestamp:
        db_report.last_occurrence = timestamp

    db_reportosrelease = get_reportosrelease(db, db_report, db_osrelease)
    if db_reportosrelease is None:
        db_reportosrelease = ReportOpSysRelease()
        db_reportosrelease.report = db_report
        db_reportosrelease.opsysrelease = db_osrelease
        db_reportosrelease.count = 0
        db.session.add(db_reportosrelease)

    db_reportosrelease.count += count

    db_arch = get_arch_by_name(db, ureport["os"]["architecture"])
    if db_arch is None:
        raise FafError("Architecture '{0}' is not supported".format(
            ureport["os"]["architecture"]))

    db_reportarch = get_reportarch(db, db_report, db_arch)
    if db_reportarch is None:
        db_reportarch = ReportArch()
        db_reportarch.report = db_report
        db_reportarch.arch = db_arch
        db_reportarch.count = 0
        db.session.add(db_reportarch)

    db_reportarch.count += count

    reason = ureport["reason"].encode("utf-8")
    db_reportreason = get_reportreason(db, db_report, reason)
    if db_reportreason is None:
        db_reportreason = ReportReason()
        db_reportreason.report = db_report
        db_reportreason.reason = reason
        db_reportreason.count = 0
        db.session.add(db_reportreason)

    db_reportreason.count += count

    day = timestamp.date()
    db_daily = get_history_day(db, db_report, db_osrelease, day)
    if db_daily is None:
        db_daily = ReportHistoryDaily()
        db_daily.report = db_report
        db_daily.opsysrelease = db_osrelease
        db_daily.day = day
        db_daily.count = 0
        db_daily.unique = 0
        db.session.add(db_daily)

    if "serial" in ureport["problem"] and ureport["problem"]["serial"] == 1:
        db_daily.unique += 1
    db_daily.count += count

    week = day - datetime.timedelta(days=day.weekday())
    db_weekly = get_history_week(db, db_report, db_osrelease, week)
    if db_weekly is None:
        db_weekly = ReportHistoryWeekly()
        db_weekly.report = db_report
        db_weekly.opsysrelease = db_osrelease
        db_weekly.week = week
        db_weekly.count = 0
        db_weekly.unique = 0
        db.session.add(db_weekly)

    if "serial" in ureport["problem"] and ureport["problem"]["serial"] == 1:
        db_weekly.unique += 1
    db_weekly.count += count

    month = day.replace(day=1)
    db_monthly = get_history_month(db, db_report, db_osrelease, month)
    if db_monthly is None:
        db_monthly = ReportHistoryMonthly()
        db_monthly.report = db_report
        db_monthly.opsysrelease = db_osrelease
        db_monthly.month = month
        db_monthly.count = 0
        db_monthly.unique = 0
        db.session.add(db_monthly)

    if "serial" in ureport["problem"] and ureport["problem"]["serial"] == 1:
        db_monthly.unique += 1
    db_monthly.count += count

    osplugin.save_ureport(db,
                          db_report,
                          ureport["os"],
                          ureport["packages"],
                          count=count)
    problemplugin.save_ureport(db, db_report, ureport["problem"], count=count)

    # Update count as last, so that handlers listening to its "set" event have
    # as much information as possible
    db_report.count += count

    db.session.flush()

    problemplugin.save_ureport_post_flush()
コード例 #17
0
    def run(self, cmdline, db):
        # nobody will write the full name
        if cmdline.OPSYS == "rhel":
            cmdline.OPSYS = "Red Hat Enterprise Linux"

        # check if operating system is known
        if not get_opsys_by_name(db, cmdline.OPSYS):
            self.log_error(
                "Selected operating system '{0}' is not supported.".format(
                    cmdline.OPSYS))
            return 1
        else:
            self.log_info("Selected operating system: '{0}'".format(
                cmdline.OPSYS))

        # check if release is known
        opsysrelease = get_osrelease(db, cmdline.OPSYS, cmdline.RELEASE)
        if not opsysrelease:
            self.log_error("Selected release '{0}' is not supported.".format(
                cmdline.RELEASE))
            return 1
        else:
            self.log_info("Selected release: '{0}'".format(cmdline.RELEASE))

        # check if architecture is known
        arch = get_arch_by_name(db, cmdline.ARCH)
        if not arch:
            self.log_error(
                "Selected architecture '{0}' is not supported.".format(
                    cmdline.ARCH))
            return 1
        else:
            self.log_info("Selected architecture: '{0}'".format(cmdline.ARCH))

        # when release-builds argument specified
        if cmdline.released_builds:
            self.log_info("Assigning released builds for '{0} {1}'".format(
                cmdline.OPSYS, cmdline.RELEASE))
            opsys = self._edit_opsys(cmdline.OPSYS)
            if not opsys in systems.keys():
                self.log_error(
                    "There are no known released builds for '{0}'".format(
                        cmdline.OPSYS))
                return 1

            for build in systems[opsys].get_released_builds(cmdline.RELEASE):
                found_build = (db.session.query(Build).filter(
                    Build.base_package_name == build["name"]).filter(
                        Build.version == build["version"]).filter(
                            Build.release == build["release"]).filter(
                                Build.epoch == build["epoch"]).first())

                if found_build:
                    self._add_into_build_opsysrelease_arch(
                        db, found_build, opsysrelease, arch)

        # when expression argument was passed
        if cmdline.expression:
            self.log_info("Selecting builds by expression: '{0}'".format(
                cmdline.expression))
            found_builds = (db.session.query(Build).filter(
                Build.release.like("%{0}".format(cmdline.expression))).all())
            for build in found_builds:
                self._add_into_build_opsysrelease_arch(db, build, opsysrelease,
                                                       arch)

        db.session.flush()
コード例 #18
0
    def _save_bug(self, db, bug):
        """
        Save bug represented by `bug_dict` to the database.

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

        bug_dict = self._preprocess_bug(bug)
        if not bug_dict:
            self.log_error("Bug pre-processing failed")
            return

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

        bug_id = bug_dict["bug_id"]

        tracker = queries.get_bugtracker_by_name(db, self.name)
        if not tracker:
            self.log_error("Tracker with name '{0}' is not installed"
                           .format(self.name))
            return

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

        if old_bug:
            self.log_info("Bug already up-to-date")
            return old_bug

        opsysrelease = queries.get_osrelease(db, bug_dict["product"],
                                             bug_dict["version"])

        if not opsysrelease:
            self.log_error("Unable to save this bug due to unknown "
                           "release '{0} {1}'".format(bug_dict["product"],
                                                      bug_dict["version"]))
            return

        relcomponent = queries.get_component_by_name_release(
            db, opsysrelease, bug_dict["component"])

        if not relcomponent:
            self.log_error("Unable to save this bug due to unknown "
                           "component '{0}'".format(bug_dict["component"]))
            return

        component = relcomponent.component

        new_bug = MantisBug()
        new_bug.external_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 queries.get_mantis_bug(db, bug_dict["dupe_id"], tracker.id):
                    self.log_debug("Duplicate #{0} not found".format(
                        bug_dict["dupe_id"]))

                    dup = self.download_bug_to_storage(db, bug_dict["dupe_id"])
                    if dup:
                        new_bug.duplicate_id = dup.id

        new_bug.tracker_id = tracker.id
        new_bug.component_id = component.id
        new_bug.opsysrelease_id = opsysrelease.id

        # the bug itself might be downloaded during duplicate processing
        # exit in this case - it would cause duplicate database entry
        if queries.get_mantis_bug(db, bug_dict["bug_id"], tracker.id):
            self.log_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)

            (db.session.query(MantisBug)
                .filter(MantisBug.external_id == bug_id)
                .filter(MantisBug.tracker_id == tracker.id)
                .update(bugdict))

            new_bug = queries.get_mantis_bug(db, bug_dict["bug_id"], tracker.id)
        else:
            db.session.add(new_bug)

        db.session.flush()

        return new_bug
コード例 #19
0
ファイル: repoassign.py プロジェクト: mkutlak/faf
    def run(self, cmdline, db) -> int:
        repo = (db.session.query(Repo).filter(
            Repo.name == cmdline.REPO).first())

        if not repo:
            self.log_error("Repository '{0}' not found".format(cmdline.REPO))
            return 1

        arch_list = []
        opsys_list = []
        opsysrelease_list = []

        for item_name in cmdline.OPSYS + cmdline.ARCH:
            pos_name, pos_release = self._parser_osrelease(item_name)
            opsysrelease = get_osrelease(db, pos_name, pos_release)
            opsys = get_opsys_by_name(db, item_name)
            arch = get_arch_by_name(db, item_name)

            if not (opsys or arch or opsysrelease):
                #If name is rhel we will search Red Hat Enterprise Linux
                if item_name == "rhel":
                    item_name = "Red Hat Enterprise Linux"
                    opsys = get_opsys_by_name(db, item_name)

                    if not opsys:
                        self.log_error(
                            "Item '{0}' not found".format(item_name))
                        return 1

                elif pos_name == "rhel":
                    pos_name = "Red Hat Enterprise Linux"
                    opsysrelease = get_osrelease(db, pos_name, pos_release)

                    if not opsysrelease:
                        self.log_error(
                            "Item '{0}' not found".format(item_name))
                        return 1

                else:
                    self.log_error("Item '{0}' not found".format(item_name))
                    return 1

            if opsys:
                opsys_list.append(opsys)
            elif opsysrelease:
                opsysrelease_list.append(opsysrelease)
            else:
                arch_list.append(arch)

        # test if url type correspond with type of repo
        if any('$' in url.url for url in repo.url_list) and opsysrelease_list:
            self.log_error("Assigning operating system with release to "
                           "parametrized repo. Assign only operating system.")
            return 1

        if any('$' not in url.url for url in repo.url_list) and opsys_list:
            self.log_error("Assigning operating system without release to "
                           "non - parametrized repo. Assign operating system"
                           " with release.")
            return 1

        repo.opsys_list += opsys_list
        repo.opsysrelease_list += opsysrelease_list
        repo.arch_list += arch_list

        db.session.flush()

        self.log_info(
            "Assigned '{0}' to {1} operating system(s)"
            ", {2} operating systems with release(s) and {3} architecture(s)".
            format(repo.name, len(opsys_list), len(opsysrelease_list),
                   (len(arch_list))))

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

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

        bug_dict = self.preprocess_bug(bug)
        if not bug_dict:
            self.log_error("Bug pre-processing failed")
            raise FafError("Bug pre-processing failed")

        self.log_debug("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 = (
            db.session.query(BzBug)
            .filter(BzBug.id == bug_id)
            .filter(BzBug.last_change_time == bug_dict["last_change_time"])
            .first())

        if old_bug:
            self.log_info("Bug already up-to-date")
            return old_bug

        tracker = queries.get_bugtracker_by_name(db, self.name)
        if not tracker:
            self.log_error("Tracker with name '{0}' is not installed"
                           .format(self.name))
            raise FafError("Tracker with name '{0}' is not installed"
                           .format(self.name))

        opsysrelease = queries.get_osrelease(db, bug_dict["product"],
                                             bug_dict["version"])

        if not opsysrelease:
            self.log_error("Unable to save this bug due to unknown "
                           "release '{0} {1}'".format(bug_dict["product"],
                                                      bug_dict["version"]))
            raise FafError("Unable to save this bug due to unknown "
                           "release '{0} {1}'".format(bug_dict["product"],
                                                      bug_dict["version"]))

        relcomponent = queries.get_component_by_name_release(
            db, opsysrelease, bug_dict["component"])

        if not relcomponent:
            self.log_error("Unable to save this bug due to unknown "
                           "component '{0}'".format(bug_dict["component"]))
            raise FafError("Unable to save this bug due to unknown "
                           "component '{0}'".format(bug_dict["component"]))

        component = relcomponent.component

        reporter = queries.get_bz_user(db, bug_dict["reporter"])
        if not reporter:
            self.log_debug("Creator {0} not found".format(
                bug_dict["reporter"]))

            downloaded = self._download_user(bug_dict["reporter"])
            if not downloaded:
                self.log_error("Unable to download user, skipping.")
                raise FafError("Unable to download user, skipping.")

            reporter = self._save_user(db, downloaded)

        new_bug = BzBug()
        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"]
        new_bug.private = bool(bug_dict["groups"])

        if bug_dict["status"] == "CLOSED":
            new_bug.resolution = bug_dict["resolution"]
            if bug_dict["resolution"] == "DUPLICATE":
                if not queries.get_bz_bug(db, bug_dict["dupe_id"]):
                    self.log_debug("Duplicate #{0} not found".format(
                        bug_dict["dupe_id"]))

                    dup = self.download_bug_to_storage(db, bug_dict["dupe_id"])
                    if dup:
                        new_bug.duplicate = dup.id

        new_bug.tracker_id = tracker.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 queries.get_bz_bug(db, bug_dict["bug_id"]):
            self.log_debug("Bug #{0} already exists in storage,"
                           " updating".format(bug_dict["bug_id"]))

            bugdict = {}
            for col in new_bug.__table__._columns: #pylint: disable=protected-access
                bugdict[col.name] = getattr(new_bug, col.name)

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

            new_bug = queries.get_bz_bug(db, bug_dict["bug_id"])
        else:
            db.session.add(new_bug)

        db.session.flush()

        self._save_ccs(db, bug_dict["cc"], new_bug.id)
        self._save_history(db, bug_dict["history"], new_bug.id)
        if self.save_attachments:
            self._save_attachments(db, bug_dict["attachments"], new_bug.id)
        if self.save_comments:
            self._save_comments(db, bug_dict["comments"], new_bug.id)

        return new_bug
コード例 #21
0
ファイル: repoassign.py プロジェクト: mjtrangoni/faf
    def run(self, cmdline, db):
        repo = (db.session.query(Repo)
                .filter(Repo.name == cmdline.NAME)
                .first())

        if not repo:
            self.log_error("Repository '{0}' not found"
                           .format(cmdline.NAME))
            return 1

        arch_list = []
        opsys_list = []
        opsysrelease_list = []

        for item_name in cmdline.OPSYS + cmdline.ARCH:
            pos_name, pos_release = self._parser_osrelease(item_name)
            opsysrelease = get_osrelease(db, pos_name, pos_release)
            opsys = get_opsys_by_name(db, item_name)
            arch = get_arch_by_name(db, item_name)

            if not (opsys or arch or opsysrelease):
                #If name is rhel we will search Red Hat Enterprise Linux
                if item_name == "rhel":
                    item_name = "Red Hat Enterprise Linux"
                    opsys = get_opsys_by_name(db, item_name)

                    if not opsys:
                        self.log_error("Item '{0}' not found"
                                       .format(item_name))
                        return 1

                elif pos_name == "rhel":
                    pos_name = "Red Hat Enterprise Linux"
                    opsysrelease = get_osrelease(db, pos_name, pos_release)

                    if not opsysrelease:
                        self.log_error("Item '{0}' not found"
                                       .format(item_name))
                        return 1

                else:
                    self.log_error("Item '{0}' not found"
                                   .format(item_name))
                    return 1

            if opsys:
                opsys_list.append(opsys)
            elif opsysrelease:
                opsysrelease_list.append(opsysrelease)
            else:
                arch_list.append(arch)

        # test if url type correspond with type of repo
        if any('$' in url.url for url in repo.url_list) and opsysrelease_list:
            self.log_error("Assigning operating system with release to "
                           "parametrized repo. Assign only operating system.")
            return 1

        if any('$' not in url.url for url in repo.url_list) and opsys_list:
            self.log_error("Assigning operating system without release to "
                           "non - parametrized repo. Assign operating system"
                           " with release.")
            return 1

        repo.opsys_list += opsys_list
        repo.opsysrelease_list += opsysrelease_list
        repo.arch_list += arch_list

        db.session.flush()

        self.log_info("Assigned '{0}' to {1} operating system(s)"
                      ", {2} operating systems with release(s) and {3} architecture(s)"
                      .format(repo.name, len(opsys_list), len(opsysrelease_list),
                              (len(arch_list))))
コード例 #22
0
    def _save_bug(self, db, bug):
        """
        Save bug represented by `bug_dict` to the database.

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

        bug_dict = self._preprocess_bug(bug)
        if not bug_dict:
            self.log_error("Bug pre-processing failed")
            raise FafError("Bug pre-processing failed")

        self.log_debug("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 = (
            db.session.query(BzBug)
            .filter(BzBug.id == bug_id)
            .filter(BzBug.last_change_time == bug_dict["last_change_time"])
            .first())

        if old_bug:
            self.log_info("Bug already up-to-date")
            return old_bug

        tracker = queries.get_bugtracker_by_name(db, self.name)
        if not tracker:
            self.log_error("Tracker with name '{0}' is not installed"
                           .format(self.name))
            raise FafError("Tracker with name '{0}' is not installed"
                           .format(self.name))

        opsysrelease = queries.get_osrelease(db, bug_dict["product"],
                                             bug_dict["version"])

        if not opsysrelease:
            self.log_error("Unable to save this bug due to unknown "
                           "release '{0} {1}'".format(bug_dict["product"],
                                                      bug_dict["version"]))
            raise FafError("Unable to save this bug due to unknown "
                           "release '{0} {1}'".format(bug_dict["product"],
                                                      bug_dict["version"]))

        relcomponent = queries.get_component_by_name_release(
            db, opsysrelease, bug_dict["component"])

        if not relcomponent:
            self.log_error("Unable to save this bug due to unknown "
                           "component '{0}'".format(bug_dict["component"]))
            raise FafError("Unable to save this bug due to unknown "
                           "component '{0}'".format(bug_dict["component"]))

        component = relcomponent.component

        reporter = queries.get_bz_user(db, bug_dict["reporter"])
        if not reporter:
            self.log_debug("Creator {0} not found".format(
                bug_dict["reporter"]))

            downloaded = self._download_user(bug_dict["reporter"])
            if not downloaded:
                self.log_error("Unable to download user, skipping.")
                raise FafError("Unable to download user, skipping.")

            reporter = self._save_user(db, downloaded)

        new_bug = BzBug()
        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"]
        new_bug.private = True if bug_dict["groups"] else False

        if bug_dict["status"] == "CLOSED":
            new_bug.resolution = bug_dict["resolution"]
            if bug_dict["resolution"] == "DUPLICATE":
                if not queries.get_bz_bug(db, bug_dict["dupe_id"]):
                    self.log_debug("Duplicate #{0} not found".format(
                        bug_dict["dupe_id"]))

                    dup = self.download_bug_to_storage(db, bug_dict["dupe_id"])
                    if dup:
                        new_bug.duplicate = dup.id

        new_bug.tracker_id = tracker.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 queries.get_bz_bug(db, bug_dict["bug_id"]):
            self.log_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)

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

            new_bug = queries.get_bz_bug(db, bug_dict["bug_id"])
        else:
            db.session.add(new_bug)

        db.session.flush()

        self._save_ccs(db, bug_dict["cc"], new_bug.id)
        self._save_history(db, bug_dict["history"], new_bug.id)
        if self.save_attachments:
            self._save_attachments(db, bug_dict["attachments"], new_bug.id)
        if self.save_comments:
            self._save_comments(db, bug_dict["comments"], new_bug.id)

        return new_bug
コード例 #23
0
ファイル: ureport.py プロジェクト: patriczek/faf
def save_ureport2(db, ureport, create_component=False, timestamp=None, count=1):
    """
    Save uReport2
    """

    if timestamp is None:
        timestamp = datetime.datetime.utcnow()

    osplugin = systems[ureport["os"]["name"]]
    problemplugin = problemtypes[ureport["problem"]["type"]]

    db_osrelease = get_osrelease(db, osplugin.nice_name,
                                 ureport["os"]["version"])
    if db_osrelease is None:
        raise FafError("Operating system '{0} {1}' not found in storage"
                       .format(osplugin.nice_name, ureport["os"]["version"]))

    report_hash = problemplugin.hash_ureport(ureport["problem"])
    db_report = get_report(db, report_hash)
    if db_report is None:
        component_name = problemplugin.get_component_name(ureport["problem"])
        db_component = get_component_by_name(db, component_name,
                                             osplugin.nice_name)
        if db_component is None:
            if create_component:
                log.info("Creating an unsupported component '{0}' in "
                         "operating system '{1}'".format(component_name,
                                                         osplugin.nice_name))
                db_component = OpSysComponent()
                db_component.name = component_name
                db_component.opsys = db_osrelease.opsys
                db.session.add(db_component)
            else:
                raise FafError("Unknown component '{0}' in operating system "
                               "{1}".format(component_name, osplugin.nice_name))

        db_report = Report()
        db_report.type = problemplugin.name
        db_report.first_occurrence = timestamp
        db_report.last_occurrence = timestamp
        db_report.count = 0
        db_report.component = db_component
        db.session.add(db_report)

        db_report_hash = ReportHash()
        db_report_hash.report = db_report
        db_report_hash.hash = report_hash
        db.session.add(db_report_hash)

    if db_report.first_occurrence > timestamp:
        db_report.first_occurrence = timestamp

    if db_report.last_occurrence < timestamp:
        db_report.last_occurrence = timestamp

    db_reportosrelease = get_reportosrelease(db, db_report, db_osrelease)
    if db_reportosrelease is None:
        db_reportosrelease = ReportOpSysRelease()
        db_reportosrelease.report = db_report
        db_reportosrelease.opsysrelease = db_osrelease
        db_reportosrelease.count = 0
        db.session.add(db_reportosrelease)

    db_reportosrelease.count += count

    db_arch = get_arch_by_name(db, ureport["os"]["architecture"])
    if db_arch is None:
        raise FafError("Architecture '{0}' is not supported"
                       .format(ureport["os"]["architecture"]))

    db_reportarch = get_reportarch(db, db_report, db_arch)
    if db_reportarch is None:
        db_reportarch = ReportArch()
        db_reportarch.report = db_report
        db_reportarch.arch = db_arch
        db_reportarch.count = 0
        db.session.add(db_reportarch)

    db_reportarch.count += count

    reason = ureport["reason"].encode("utf-8")
    db_reportreason = get_reportreason(db, db_report, reason)
    if db_reportreason is None:
        db_reportreason = ReportReason()
        db_reportreason.report = db_report
        db_reportreason.reason = reason
        db_reportreason.count = 0
        db.session.add(db_reportreason)

    db_reportreason.count += count

    day = timestamp.date()
    db_daily = get_history_day(db, db_report, db_osrelease, day)
    if db_daily is None:
        db_daily = ReportHistoryDaily()
        db_daily.report = db_report
        db_daily.opsysrelease = db_osrelease
        db_daily.day = day
        db_daily.count = 0
        db.session.add(db_daily)

    db_daily.count += count

    week = day - datetime.timedelta(days=day.weekday())
    db_weekly = get_history_week(db, db_report, db_osrelease, week)
    if db_weekly is None:
        db_weekly = ReportHistoryWeekly()
        db_weekly.report = db_report
        db_weekly.opsysrelease = db_osrelease
        db_weekly.week = week
        db_weekly.count = 0
        db.session.add(db_weekly)

    db_weekly.count += count

    month = day.replace(day=1)
    db_monthly = get_history_month(db, db_report, db_osrelease, month)
    if db_monthly is None:
        db_monthly = ReportHistoryMonthly()
        db_monthly.report = db_report
        db_monthly.opsysrelease = db_osrelease
        db_monthly.month = month
        db_monthly.count = 0
        db.session.add(db_monthly)

    db_monthly.count += count

    osplugin.save_ureport(db, db_report, ureport["os"], ureport["packages"],
                          count=count)
    problemplugin.save_ureport(db, db_report, ureport["problem"], count=count)

    # Update count as last, so that handlers listening to its "set" event have
    # as much information as possible
    db_report.count += count

    db.session.flush()

    problemplugin.save_ureport_post_flush()