示例#1
0
    def run(self, cmdline, db):
        for instance_id in cmdline.INSTANCE_ID:
            db_instance = get_external_faf_by_id(db, instance_id)
            if db_instance is None:
                self.log_warn("The instance with ID {0} is not defined "
                              "in storage".format(instance_id))
                continue

            self.log_debug("Processing instance '%s'", db_instance.name)

            if db_instance.reports:
                if not cmdline.cascade:
                    self.log_warn(
                        "The instance '{0}' with ID {1} has reports "
                        "but --cascade has not been specified".format(
                            db_instance.name, instance_id))
                    continue

                for db_external_report in db_instance.reports:
                    self.log_debug("Deleting assigned report #%d",
                                   db_external_report.external_id)
                    db.session.delete(db_external_report)

            db.session.delete(db_instance)
            self.log_info("Deleted the instance '{0}' with ID {1}".format(
                db_instance.name, instance_id))

        db.session.flush()
示例#2
0
文件: extfafmodify.py 项目: abrt/faf
    def run(self, cmdline, db):
        db_instance = get_external_faf_by_id(db, cmdline.INSTANCE_ID)
        if db_instance is None:
            self.log_error("Instance with ID {0} is not defined in storage"
                           .format(cmdline.INSTANCE_ID))
            return 1

        if cmdline.name is not None:
            db_instance2 = get_external_faf_by_name(db, cmdline.name)
            if db_instance2 is not None:
                self.log_warn("Instance with name '{0}' is already defined with"
                              " ID {1}".format(cmdline.name, db_instance2.id))
            else:
                self.log_info("Updated name")
                db_instance.name = cmdline.name

        if cmdline.baseurl is not None:
            baseurl = cmdline.baseurl.rstrip("/")
            db_instance2 = get_external_faf_by_baseurl(db, baseurl)
            if db_instance2 is not None:
                self.log_warn("Instance with base URL '{0}' is already defined"
                              " with ID {1}".format(baseurl, db_instance2.id))
            else:
                self.log_info("Updated base URL")
                db_instance.baseurl = baseurl

        db.session.flush()
        return 0
示例#3
0
文件: extfaflink.py 项目: coyang/faf
    def run(self, cmdline, db):
        db_external_faf = get_external_faf_by_id(db, cmdline.INSTANCE_ID)
        if db_external_faf is None:
            self.log_error("An external FAF instance with ID #{0} does not "
                           "exist".format(cmdline.INSTANCE_ID))
            return 1

        parser = re.compile(r"{0}/reports/([0-9]+)/".format(
            db_external_faf.baseurl))

        db_reports = self._get_reports_query(db)
        cnt = db_reports.count()

        i = 0
        for db_report in db_reports:
            i += 1

            hashes = set()
            self.log_info("[{0} / {1}] Processing report #{2}".format(
                i, cnt, db_report.id))

            for db_reporthash in db_report.hashes:
                self.log_debug("Adding report hash '{0}'".format(
                    db_reporthash.hash))
                hashes.add(db_reporthash.hash)

            for db_backtrace in db_report.backtraces:
                for db_bthash in db_backtrace.hashes:
                    self.log_debug("Adding backtrace hash '{0}'".format(
                        db_bthash.hash))
                    hashes.add(db_bthash.hash)

            j = 0
            for hashvalue in hashes:
                j += 1

                self.log_debug("[{0} / {1}] Processing hash '{2}'".format(
                    j, len(hashes), hashvalue))
                external_id = self._find_hash(hashvalue,
                                              db_external_faf.baseurl, parser)
                if external_id is None:
                    continue

                if self._has_external_report(db_report, external_id):
                    self.log_debug(
                        "Skipping existing external report #{0}".format(
                            external_id))
                    continue

                self.log_info(
                    "Adding external report #{0}".format(external_id))

                db_externalfaf = ReportExternalFaf()
                db_externalfaf.report = db_report
                db_externalfaf.faf_instance = db_external_faf
                db_externalfaf.external_id = external_id
                db.session.add(db_externalfaf)

        db.session.flush()
        return 0
示例#4
0
    def run(self, cmdline, db):
        db_instance = get_external_faf_by_id(db, cmdline.INSTANCE_ID)
        if db_instance is None:
            self.log_error("Instance with ID {0} is not defined in storage"
                           .format(cmdline.INSTANCE_ID))
            return 1

        if cmdline.name is not None:
            db_instance2 = get_external_faf_by_name(db, cmdline.name)
            if db_instance2 is not None:
                self.log_warn("Instance with name '{0}' is already defined with"
                              " ID {1}".format(cmdline.name, db_instance2.id))
            else:
                self.log_info("Updated name")
                db_instance.name = cmdline.name

        if cmdline.baseurl is not None:
            baseurl = cmdline.baseurl.rstrip("/")
            db_instance2 = get_external_faf_by_baseurl(db, baseurl)
            if db_instance2 is not None:
                self.log_warn("Instance with base URL '{0}' is already defined"
                              " with ID {1}".format(baseurl, db_instance2.id))
            else:
                self.log_info("Updated base URL")
                db_instance.baseurl = baseurl

        db.session.flush()
示例#5
0
    def run(self, cmdline, db):
        for instance_id in cmdline.INSTANCE_ID:
            db_instance = get_external_faf_by_id(db, instance_id)
            if db_instance is None:
                self.log_warn("The instance with ID {0} is not defined "
                              "in storage".format(instance_id))
                continue

            self.log_debug("Processing instance '{0}'".format(db_instance.name))

            if len(db_instance.reports) > 0:
                if not cmdline.cascade:
                    self.log_warn("The instance '{0}' with ID {1} has reports "
                                  "but --cascade has not been specified"
                                  .format(db_instance.name, instance_id))
                    continue

                for db_external_report in db_instance.reports:
                    self.log_debug("Deleting assigned report #{0}"
                                   .format(db_external_report.external_id))
                    db.session.delete(db_external_report)

            db.session.delete(db_instance)
            self.log_info("Deleted the instance '{0}' with ID {1}"
                          .format(db_instance.name, instance_id))

        db.session.flush()
示例#6
0
文件: extfaflink.py 项目: abrt/faf
    def run(self, cmdline, db):
        db_external_faf = get_external_faf_by_id(db, cmdline.INSTANCE_ID)
        if db_external_faf is None:
            self.log_error("An external FAF instance with ID #{0} does not "
                           "exist".format(cmdline.INSTANCE_ID))
            return 1

        parser = re.compile(r"{0}/reports/([0-9]+)/"
                            .format(db_external_faf.baseurl))

        db_reports = self._get_reports_query(db)
        cnt = db_reports.count()

        i = 0
        for db_report in db_reports:
            i += 1

            hashes = set()
            self.log_info("[{0} / {1}] Processing report #{2}"
                          .format(i, cnt, db_report.id))

            for db_reporthash in db_report.hashes:
                self.log_debug("Adding report hash '{0}'"
                               .format(db_reporthash.hash))
                hashes.add(db_reporthash.hash)

            for db_backtrace in db_report.backtraces:
                for db_bthash in db_backtrace.hashes:
                    self.log_debug("Adding backtrace hash '{0}'"
                                   .format(db_bthash.hash))
                    hashes.add(db_bthash.hash)

            j = 0
            for hashvalue in hashes:
                j += 1

                self.log_debug("[{0} / {1}] Processing hash '{2}'"
                               .format(j, len(hashes), hashvalue))
                external_id = self._find_hash(hashvalue,
                                              db_external_faf.baseurl,
                                              parser)
                if external_id is None:
                    continue

                if self._has_external_report(db_report, external_id):
                    self.log_debug("Skipping existing external report #{0}"
                                   .format(external_id))
                    continue

                self.log_info("Adding external report #{0}"
                              .format(external_id))

                db_externalfaf = ReportExternalFaf()
                db_externalfaf.report = db_report
                db_externalfaf.faf_instance = db_external_faf
                db_externalfaf.external_id = external_id
                db.session.add(db_externalfaf)

        db.session.flush()
        return 0