def set_package_info(target):
    """Set Package and Dependencies field"""
    if not os.path.isfile(target):
        raise SystemError("%s is not a file" % target)

    report = Report()
    with open(target, 'rb') as f:
        try:
            report.load(f)
        except Exception as exc:
            raise SystemError("Cannot load file %s: %s" % (target, exc))

        additional_deps = ""
        if 'ExecutablePath' in report and re.search('samba', report['ExecutablePath']):
            try:
                for pkg_name in ('openchangeserver', 'openchange-rpcproxy', 'openchange-ocsmanager',
                                 'sogo-openchange'):
                    packaging.get_version(pkg_name)
                    report.add_package_info(pkg_name)
                    if additional_deps:
                        additional_deps += '\n'
                    additional_deps += report['Package'] + "\n" + report['Dependencies']
            except ValueError:
                # Any of previous packages is not installed
                pass

        # Add executable deps
        report.add_package_info()
        if additional_deps:
            report['Dependencies'] += '\n' + additional_deps
            report['Dependencies'] = '\n'.join(sorted(set(report['Dependencies'].split('\n'))))

        with open(target, 'wb') as f:
            report.write(f)
Beispiel #2
0
    def download(self, id):
        """
        Download the report from the database

        :raises TypeError: if the report does not exist
        """
        cur = self.db.cursor()
        cur.execute("""SELECT crash_url
                       FROM crashes
                       WHERE crash_id = ?""", [id])
        url = cur.fetchone()[0]

        fh = urlopen(url)

        # Actually read the content
        buf = BytesIO(bytes(fh.read()))

        report = Report()
        report.load(buf)
        return report
def run(target):
    crashes_files = []
    if os.path.isdir(target):
        for fname in os.listdir(target):
            crashes_files.append(os.path.join(target, fname))
    elif os.path.isfile(target):
        crashes_files = [target]
    else:
        raise SystemError("%s is not a directory neither a file" % target)

    for fpath in crashes_files:
        report = Report()

        # This may lead to bad guesses...
        if fpath.endswith('.gz'):
            open_f = gzip.open
        else:
            open_f = open

        with open_f(fpath, 'rb') as f:
            try:
                report.load(f)
                log('%s loaded.' % fpath)
            except Exception as exc:
                log("Cannot load %s: %s" % (fpath, exc))
                continue

        if 'Package' in report:
            log("%s has already the Package field: %s" %
                (fpath, report['Package']))
        else:
            try:
                mapped_package = map_package(report)
            except KeyError as exc:
                log("Cannot map the package field %s: %s" % (fpath, exc))
                continue
            log("%s package is set to %s" % (fpath, mapped_package))
            report['Package'] = "%s %s" % (mapped_package[0],
                                           mapped_package[1])
            with open_f(fpath, 'wb') as f:
                report.write(f)
Beispiel #4
0
    def download(self, id):
        """
        Download the report from the database

        :raises TypeError: if the report does not exist
        """
        cur = self.db.cursor()
        cur.execute(
            """SELECT crash_url
                       FROM crashes
                       WHERE crash_id = ?""", [id])
        url = cur.fetchone()[0]

        fh = urlopen(url)

        # Actually read the content
        buf = BytesIO(bytes(fh.read()))

        report = Report()
        report.load(buf)
        return report
def run(target):
    crashes_files = []
    if os.path.isdir(target):
        for fname in os.listdir(target):
            crashes_files.append(os.path.join(target, fname))
    elif os.path.isfile(target):
        crashes_files = [target]
    else:
        raise SystemError("%s is not a directory neither a file" % target)

    for fpath in crashes_files:
        report = Report()

        # This may lead to bad guesses...
        if fpath.endswith('.gz'):
            open_f = gzip.open
        else:
            open_f = open

        with open_f(fpath, 'rb') as f:
            try:
                report.load(f)
                log('%s loaded.' % fpath)
            except Exception as exc:
                log("Cannot load %s: %s" % (fpath, exc))
                continue

        if 'Package' in report:
            log("%s has already the Package field: %s" % (fpath, report['Package']))
        else:
            try:
                mapped_package = map_package(report)
            except KeyError as exc:
                log("Cannot map the package field %s: %s" % (fpath, exc))
                continue
            log("%s package is set to %s" % (fpath, mapped_package))
            report['Package'] = "%s %s" % (mapped_package[0], mapped_package[1])
            with open_f(fpath, 'wb') as f:
                report.write(f)