Пример #1
0
def get_rpm_header(path, ts):
    s = StringIO()
    with open(path, 'r') as f:
        try:
            hdr = ts.hdrFromFdno(f)
        except rpm.error as e:
            logger.error("reading rpm header failed: %s", str(e))
            return str(e)
        for rpmtag in sorted(rpm.tagnames):
            if rpmtag not in hdr:
                continue
            s.write(u"%s: " % rpm.tagnames[rpmtag])
            convert_header_field(s, hdr[rpmtag])
            s.write(u"\n")
    return s.getvalue()
Пример #2
0
def get_rpm_header(path, ts):
    s = StringIO()
    with open(path, 'r') as f:
        try:
            hdr = ts.hdrFromFdno(f)
        except rpm.error as e:
            logger.error("reading rpm header failed: %s", str(e))
            return str(e)
        for rpmtag in sorted(rpm.tagnames):
            if rpmtag not in hdr:
                continue
            s.write(u"%s: " % rpm.tagnames[rpmtag])
            convert_header_field(s, hdr[rpmtag])
            s.write(u"\n")
    return s.getvalue()
Пример #3
0
    def open_archive(self):
        if not guestfs:
            return None

        self.g = guestfs.GuestFS (python_return_dict=True)
        self.g.add_drive_opts (self.source.path, format="raw", readonly=1)
        try:
            self.g.launch()
        except RuntimeError:
            logger.exception("guestfs can't be launched")
            logger.error("If memory is too tight for 512 MiB, try running with LIBGUESTFS_MEMSIZE=256 or lower.")
            return None
        devices = self.g.list_devices()
        self.g.mount(devices[0], "/")
        self.fs = self.g.list_filesystems()[devices[0]]
        return self
Пример #4
0
    def open_archive(self):
        if not guestfs:
            return None

        self.g = guestfs.GuestFS (python_return_dict=True)
        self.g.add_drive_opts (self.source.path, format="raw", readonly=1)
        try:
            self.g.launch()
        except RuntimeError:
            logger.exception("guestfs can't be launched")
            logger.error("If memory is too tight for 512 MiB, try running with LIBGUESTFS_MEMSIZE=256 or lower.")
            return None
        devices = self.g.list_devices()
        self.g.mount(devices[0], "/")
        self.fs = self.g.list_filesystems()[devices[0]]
        return self
Пример #5
0
def create_parser():
    parser = argparse.ArgumentParser(
        description='Highlight differences between two builds '
        'of Debian packages')
    parser.add_argument('--version',
                        action='version',
                        version='diffoscope %s' % VERSION)
    parser.add_argument('--list-tools',
                        nargs='?',
                        type=str,
                        action=ListToolsAction,
                        help='show external tools required and exit')
    parser.add_argument('--debug',
                        dest='debug',
                        action='store_true',
                        default=False,
                        help='display debug messages')
    parser.add_argument('--debugger',
                        action='store_true',
                        help='Open the python debugger in case of crashes.')
    parser.add_argument(
        '--html',
        metavar='output',
        dest='html_output',
        help='write HTML report to given file (use - for stdout)')
    parser.add_argument('--html-dir',
                        metavar='output',
                        dest='html_output_directory',
                        help='write multi-file HTML report to given directory')
    parser.add_argument(
        '--text',
        metavar='output',
        dest='text_output',
        help='write plain text output to given file (use - for stdout)')
    parser.add_argument(
        '--max-report-size',
        metavar='BYTES',
        dest='max_report_size',
        type=int,
        help='maximum bytes written in report (default: %d)' %
        Config.general.max_report_size,
        default=Config.general.max_report_size).completer = RangeCompleter(
            0, Config.general.max_report_size, 200000)
    parser.add_argument(
        '--separate-file-diff-size',
        metavar='BYTES',
        dest='separate_file_diff_size',
        type=int,
        help='diff size to load diff on demand, with --html-dir (default: %d)'
        % Config.general.separate_file_diff_size,
        default=Config.general.separate_file_diff_size
    ).completer = RangeCompleter(0, Config.general.separate_file_diff_size,
                                 20000)
    parser.add_argument(
        '--max-diff-block-lines',
        dest='max_diff_block_lines',
        type=int,
        help='maximum number of lines per diff block (default: %d)' %
        Config.general.max_diff_block_lines,
        default=Config.general.max_diff_block_lines
    ).completer = RangeCompleter(0, Config.general.max_diff_block_lines, 5)
    parser.add_argument(
        '--max-diff-input-lines',
        dest='max_diff_input_lines',
        type=int,
        help='maximum number of lines fed to diff (default: %d)' %
        Config.general.max_diff_input_lines,
        default=Config.general.max_diff_input_lines
    ).completer = RangeCompleter(0, Config.general.max_diff_input_lines, 5000)
    parser.add_argument(
        '--fuzzy-threshold',
        dest='fuzzy_threshold',
        type=int,
        help='threshold for fuzzy-matching '
        '(0 to disable, %d is default, 400 is high fuzziness)' %
        (Config.general.fuzzy_threshold),
        default=Config.general.fuzzy_threshold).completer = RangeCompleter(
            0, 400, 20)
    parser.add_argument('--new-file',
                        dest='new_file',
                        action='store_true',
                        help='treat absent files as empty')
    parser.add_argument('--css',
                        metavar='url',
                        dest='css_url',
                        help='link to an extra CSS for the HTML report')
    parser.add_argument(
        '--jquery',
        metavar='url',
        dest='jquery_url',
        help=
        'link to the jquery url, with --html-dir. Specify “disable” to disable JavaScript. When omitted diffoscope will try to create a symlink to a system installation. Known locations: %s'
        % ', '.join(JQUERY_SYSTEM_LOCATIONS))
    parser.add_argument('file1', help='first file to compare')
    parser.add_argument('file2', help='second file to compare')
    if not tlsh:
        parser.epilog = 'File renaming detection based on fuzzy-matching is currently disabled. It can be enabled by installing the “tlsh” module available at https://github.com/trendmicro/tlsh'
    if argcomplete:
        argcomplete.autocomplete(parser)
    elif '_ARGCOMPLETE' in os.environ:
        logger.error(
            'Argument completion requested but the "argcomplete" module is not installed. It can be obtained at https://pypi.python.org/pypi/argcomplete'
        )
        sys.exit(1)

    return parser
Пример #6
0
def create_parser():
    parser = argparse.ArgumentParser(
        description='Highlight differences between two builds '
                    'of Debian packages')
    parser.add_argument('--version', action='version',
                        version='diffoscope %s' % VERSION)
    parser.add_argument('--list-tools', nargs='?', type=str, action=ListToolsAction,
                        help='show external tools required and exit')
    parser.add_argument('--debug', dest='debug', action='store_true',
                        default=False, help='display debug messages')
    parser.add_argument('--debugger', action='store_true',
                        help='Open the python debugger in case of crashes.')
    parser.add_argument('--html', metavar='output', dest='html_output',
                        help='write HTML report to given file (use - for stdout)')
    parser.add_argument('--html-dir', metavar='output', dest='html_output_directory',
                        help='write multi-file HTML report to given directory')
    parser.add_argument('--text', metavar='output', dest='text_output',
                        help='write plain text output to given file (use - for stdout)')
    parser.add_argument('--max-report-size', metavar='BYTES',
                        dest='max_report_size', type=int,
                        help='maximum bytes written in report (default: %d)' %
                        Config.general.max_report_size,
                        default=Config.general.max_report_size).completer=RangeCompleter(0,
                        Config.general.max_report_size, 200000)
    parser.add_argument('--separate-file-diff-size', metavar='BYTES',
                        dest='separate_file_diff_size', type=int,
                        help='diff size to load diff on demand, with --html-dir (default: %d)' %
                        Config.general.separate_file_diff_size,
                        default=Config.general.separate_file_diff_size).completer=RangeCompleter(0,
                        Config.general.separate_file_diff_size, 20000)
    parser.add_argument('--max-diff-block-lines', dest='max_diff_block_lines', type=int,
                        help='maximum number of lines per diff block (default: %d)' %
                        Config.general.max_diff_block_lines,
                        default=Config.general.max_diff_block_lines).completer=RangeCompleter(0,
                        Config.general.max_diff_block_lines, 5)
    parser.add_argument('--max-diff-input-lines', dest='max_diff_input_lines', type=int,
                        help='maximum number of lines fed to diff (default: %d)' %
                        Config.general.max_diff_input_lines,
                        default=Config.general.max_diff_input_lines).completer=RangeCompleter(0,
                        Config.general.max_diff_input_lines, 5000)
    parser.add_argument('--fuzzy-threshold', dest='fuzzy_threshold', type=int,
                        help='threshold for fuzzy-matching '
                             '(0 to disable, %d is default, 400 is high fuzziness)' %
                             (Config.general.fuzzy_threshold),
                        default=Config.general.fuzzy_threshold).completer=RangeCompleter(0,
                        400, 20)
    parser.add_argument('--new-file', dest='new_file', action='store_true',
                        help='treat absent files as empty')
    parser.add_argument('--css', metavar='url', dest='css_url',
                        help='link to an extra CSS for the HTML report')
    parser.add_argument('--jquery', metavar='url', dest='jquery_url',
                        help='link to the jquery url, with --html-dir. Specify “disable” to disable JavaScript. When omitted diffoscope will try to create a symlink to a system installation. Known locations: %s' % ', '.join(JQUERY_SYSTEM_LOCATIONS))
    parser.add_argument('file1', help='first file to compare')
    parser.add_argument('file2', help='second file to compare')
    if not tlsh:
        parser.epilog = 'File renaming detection based on fuzzy-matching is currently disabled. It can be enabled by installing the “tlsh” module available at https://github.com/trendmicro/tlsh'
    if argcomplete:
        argcomplete.autocomplete(parser)
    elif '_ARGCOMPLETE' in os.environ:
        logger.error('Argument completion requested but the "argcomplete" module is not installed. It can be obtained at https://pypi.python.org/pypi/argcomplete')
        sys.exit(1)

    return parser
Пример #7
0
def create_parser():
    parser = argparse.ArgumentParser(description="Highlight differences between two builds " "of Debian packages")
    parser.add_argument("--version", action="version", version="diffoscope %s" % VERSION)
    parser.add_argument(
        "--list-tools", nargs="?", type=str, action=ListToolsAction, help="show external tools required and exit"
    )
    parser.add_argument("--debug", dest="debug", action="store_true", default=False, help="display debug messages")
    parser.add_argument("--debugger", action="store_true", help="Open the python debugger in case of crashes.")
    parser.add_argument(
        "--html", metavar="output", dest="html_output", help="write HTML report to given file (use - for stdout)"
    )
    parser.add_argument(
        "--html-dir",
        metavar="output",
        dest="html_output_directory",
        help="write multi-file HTML report to given directory",
    )
    parser.add_argument(
        "--text", metavar="output", dest="text_output", help="write plain text output to given file (use - for stdout)"
    )
    parser.add_argument(
        "--max-report-size",
        metavar="BYTES",
        dest="max_report_size",
        type=int,
        help="maximum bytes written in report (default: %d)" % Config.general.max_report_size,
        default=Config.general.max_report_size,
    ).completer = RangeCompleter(0, Config.general.max_report_size, 200000)
    parser.add_argument(
        "--separate-file-diff-size",
        metavar="BYTES",
        dest="separate_file_diff_size",
        type=int,
        help="diff size to load diff on demand, with --html-dir (default: %d)" % Config.general.separate_file_diff_size,
        default=Config.general.separate_file_diff_size,
    ).completer = RangeCompleter(0, Config.general.separate_file_diff_size, 20000)
    parser.add_argument(
        "--max-diff-block-lines",
        dest="max_diff_block_lines",
        type=int,
        help="maximum number of lines per diff block (default: %d)" % Config.general.max_diff_block_lines,
        default=Config.general.max_diff_block_lines,
    ).completer = RangeCompleter(0, Config.general.max_diff_block_lines, 5)
    parser.add_argument(
        "--max-diff-input-lines",
        dest="max_diff_input_lines",
        type=int,
        help="maximum number of lines fed to diff (default: %d)" % Config.general.max_diff_input_lines,
        default=Config.general.max_diff_input_lines,
    ).completer = RangeCompleter(0, Config.general.max_diff_input_lines, 5000)
    parser.add_argument(
        "--fuzzy-threshold",
        dest="fuzzy_threshold",
        type=int,
        help="threshold for fuzzy-matching "
        "(0 to disable, %d is default, 400 is high fuzziness)" % (Config.general.fuzzy_threshold),
        default=Config.general.fuzzy_threshold,
    ).completer = RangeCompleter(0, 400, 20)
    parser.add_argument("--new-file", dest="new_file", action="store_true", help="treat absent files as empty")
    parser.add_argument("--css", metavar="url", dest="css_url", help="link to an extra CSS for the HTML report")
    parser.add_argument(
        "--jquery",
        metavar="url",
        dest="jquery_url",
        help="link to the jquery url, with --html-dir. Specify “disable” to disable JavaScript. When omitted diffoscope will try to create a symlink to a system installation. Known locations: %s"
        % ", ".join(JQUERY_SYSTEM_LOCATIONS),
    )
    parser.add_argument("path1", help="first file or directory to compare")
    parser.add_argument("path2", help="second file or directory to compare")
    if not tlsh:
        parser.epilog = "File renaming detection based on fuzzy-matching is currently disabled. It can be enabled by installing the “tlsh” module available at https://github.com/trendmicro/tlsh"
    if argcomplete:
        argcomplete.autocomplete(parser)
    elif "_ARGCOMPLETE" in os.environ:
        logger.error(
            'Argument completion requested but the "argcomplete" module is not installed. It can be obtained at https://pypi.python.org/pypi/argcomplete'
        )
        sys.exit(1)

    return parser