Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
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)
Exemplo n.º 4
0
def _write_apport_report_to_file(exc_info):
    import traceback
    from apport.report import Report

    exc_type, exc_object, exc_tb = exc_info

    pr = Report()
    # add_proc_info sets the ExecutablePath, InterpreterPath, etc.
    pr.add_proc_info()
    # It also adds ProcMaps which for us is rarely useful and mostly noise, so
    # let's remove it.
    del pr['ProcMaps']
    pr.add_user_info()

    # Package and SourcePackage are needed so that apport will report about even
    # non-packaged versions of bzr; also this reports on their packaged
    # dependencies which is useful.
    pr['SourcePackage'] = 'bzr'
    pr['Package'] = 'bzr'

    pr['CommandLine'] = pprint.pformat(sys.argv)
    pr['BzrVersion'] = bzrlib.__version__
    pr['PythonVersion'] = bzrlib._format_version_tuple(sys.version_info)
    pr['Platform'] = platform.platform(aliased=1)
    pr['UserEncoding'] = osutils.get_user_encoding()
    pr['FileSystemEncoding'] = sys.getfilesystemencoding()
    pr['Locale'] = os.environ.get('LANG', 'C')
    pr['BzrPlugins'] = _format_plugin_list()
    pr['PythonLoadedModules'] = _format_module_list()
    pr['BzrDebugFlags'] = pprint.pformat(debug.debug_flags)

    # actually we'd rather file directly against the upstream product, but
    # apport does seem to count on there being one in there; we might need to
    # redirect it elsewhere anyhow
    pr['SourcePackage'] = 'bzr'
    pr['Package'] = 'bzr'

    # tell apport to file directly against the bzr package using 
    # <https://bugs.launchpad.net/bzr/+bug/391015>
    #
    # XXX: unfortunately apport may crash later if the crashdb definition
    # file isn't present
    pr['CrashDb'] = 'bzr'

    tb_file = StringIO()
    traceback.print_exception(exc_type, exc_object, exc_tb, file=tb_file)
    pr['Traceback'] = tb_file.getvalue()

    _attach_log_tail(pr)

    # We want to use the 'bzr' crashdb so that it gets sent directly upstream,
    # which is a reasonable default for most internal errors.  However, if we
    # set it here then apport will crash later if it doesn't know about that
    # crashdb.  Instead, we rely on the bzr package installing both a
    # source hook telling crashes to go to this crashdb, and a crashdb
    # configuration describing it.

    # these may contain some sensitive info (smtp_passwords)
    # TODO: strip that out and attach the rest
    #
    #attach_file_if_exists(report,
    #   os.path.join(dot_bzr, 'bazaar.conf', 'BzrConfig')
    #attach_file_if_exists(report,
    #   os.path.join(dot_bzr, 'locations.conf', 'BzrLocations')
    
    # strip username, hostname, etc
    pr.anonymize()

    if pr.check_ignored():
        # eg configured off in ~/.apport-ignore.xml
        return None
    else:
        crash_file_name, crash_file = _open_crash_file()
        pr.write(crash_file)
        crash_file.close()
        return crash_file_name
Exemplo n.º 5
0
def _write_apport_report_to_file(exc_info):
    import traceback
    from apport.report import Report

    exc_type, exc_object, exc_tb = exc_info

    pr = Report()
    # add_proc_info sets the ExecutablePath, InterpreterPath, etc.
    pr.add_proc_info()
    # It also adds ProcMaps which for us is rarely useful and mostly noise, so
    # let's remove it.
    del pr['ProcMaps']
    pr.add_user_info()

    # Package and SourcePackage are needed so that apport will report about even
    # non-packaged versions of brz; also this reports on their packaged
    # dependencies which is useful.
    pr['SourcePackage'] = 'brz'
    pr['Package'] = 'brz'

    pr['CommandLine'] = pprint.pformat(sys.argv)
    pr['BrzVersion'] = breezy.__version__
    pr['PythonVersion'] = breezy._format_version_tuple(sys.version_info)
    pr['Platform'] = platform.platform(aliased=1)
    pr['UserEncoding'] = osutils.get_user_encoding()
    pr['FileSystemEncoding'] = sys.getfilesystemencoding()
    pr['Locale'] = os.environ.get('LANG', 'C')
    pr['BrzPlugins'] = _format_plugin_list()
    pr['PythonLoadedModules'] = _format_module_list()
    pr['BrzDebugFlags'] = pprint.pformat(debug.debug_flags)

    # actually we'd rather file directly against the upstream product, but
    # apport does seem to count on there being one in there; we might need to
    # redirect it elsewhere anyhow
    pr['SourcePackage'] = 'brz'
    pr['Package'] = 'brz'

    # tell apport to file directly against the brz package using
    # <https://bugs.launchpad.net/bzr/+bug/391015>
    #
    # XXX: unfortunately apport may crash later if the crashdb definition
    # file isn't present
    pr['CrashDb'] = 'brz'

    tb_file = StringIO()
    traceback.print_exception(exc_type, exc_object, exc_tb, file=tb_file)
    pr['Traceback'] = tb_file.getvalue()

    _attach_log_tail(pr)

    # We want to use the 'brz' crashdb so that it gets sent directly upstream,
    # which is a reasonable default for most internal errors.  However, if we
    # set it here then apport will crash later if it doesn't know about that
    # crashdb.  Instead, we rely on the brz package installing both a
    # source hook telling crashes to go to this crashdb, and a crashdb
    # configuration describing it.

    # these may contain some sensitive info (smtp_passwords)
    # TODO: strip that out and attach the rest
    #
    # attach_file_if_exists(report,
    #   os.path.join(dot_brz, 'breezy.conf', 'BrzConfig')
    # attach_file_if_exists(report,
    #   os.path.join(dot_brz, 'locations.conf', 'BrzLocations')

    # strip username, hostname, etc
    pr.anonymize()

    if pr.check_ignored():
        # eg configured off in ~/.apport-ignore.xml
        return None
    else:
        crash_file_name, crash_file = _open_crash_file()
        pr.write(crash_file)
        crash_file.close()
        return crash_file_name