Exemplo n.º 1
0
    def dump(self, file):
        t = get_named_temporary_file()

        subprocess.check_call((
            'ssconvert',
            '--export-type=Gnumeric_stf:stf_assistant',
            file.path,
            t.name,
        ))

        with open(t.name) as f:
            return f.read().strip()
Exemplo n.º 2
0
def flicker_difference(image1_path, image2_path):
    compared_filename = get_named_temporary_file(suffix='.gif').name

    subprocess.check_call((
        'convert',
        '-delay',
        '50',
        image1_path,
        image2_path,
        '-loop',
        '0',
        '-compose',
        'difference',
        compared_filename,
    ))

    with open(compared_filename, 'rb') as f:
        content = base64.b64encode(f.read()).decode('utf8')

    return VisualDifference('image/gif;base64', content, "Flicker difference")
Exemplo n.º 3
0
def pixel_difference(image1_path, image2_path):
    compared_filename = get_named_temporary_file(suffix='.png').name

    try:
        subprocess.check_call((
            'compare',
            image1_path,
            image2_path,
            '-compose',
            'src',
            compared_filename,
        ))
    except subprocess.CalledProcessError as e:
        # ImageMagick's `compare` will return 1 if images are different
        if e.returncode == 1:
            pass

    with open(compared_filename, 'rb') as f:
        content = base64.b64encode(f.read()).decode('utf8')

    return VisualDifference('image/png;base64', content, "Pixel difference")
Exemplo n.º 4
0
 def create_placeholder(self):
     with get_named_temporary_file('w+', delete=False) as f:
         f.write('destination: %s\n' % self.symlink_destination)
         f.flush()
         return f.name
Exemplo n.º 5
0
    def _install_debug_symbols(self):
        if Config().use_dbgsym == 'no':
            return

        # Figure out if we are in a Debian package first
        try:
            deb = (
                self.source.container.source.container.source.container.source)
        except AttributeError:
            return

        # It needs to be a .deb and we need access a to a -dbgsym package in
        # the same .changes, directory or archive
        if not isinstance(deb, DebFile) or not deb.container:
            return

        # If the .deb in question is the top-level of the source we have passed
        # a .deb directly to diffoscope (versus finding one specified in a
        # .changes or .buildinfo file). In this case, don't automatically
        # search for a -dbgsym file unless the user specified
        # `Config().use_dbgsym`.
        if (not hasattr(deb.container.source, 'container')
                and Config().use_dbgsym != 'yes'):
            return

        # Retrieve the Build ID for the ELF file we are examining
        build_id = get_build_id(self.source.path)
        debuglink = get_debug_link(self.source.path)
        if not build_id or not debuglink:
            return

        logger.debug(
            "Looking for a dbgsym package for Build Id %s (debuglink: %s)",
            build_id,
            debuglink,
        )

        # Build a map of Build-Ids if it doesn't exist yet
        if not hasattr(deb.container, 'dbgsym_build_id_map'):
            deb.container.dbgsym_build_id_map = get_build_id_map(deb.container)

        if build_id not in deb.container.dbgsym_build_id_map:
            logger.debug(
                'Unable to find a matching debug package for Build Id %s',
                build_id,
            )
            return

        dbgsym_package = deb.container.dbgsym_build_id_map[build_id]
        debug_file_path = './usr/lib/debug/.build-id/{0}/{1}.debug'.format(
            build_id[:2], build_id[2:])
        debug_file = dbgsym_package.as_container.data_tar.as_container.lookup_file(
            debug_file_path)
        if not debug_file:
            logger.debug(
                'Unable to find the matching debug file %s in %s',
                debug_file_path,
                dbgsym_package,
            )
            return

        # Create a .debug directory and link the debug symbols there with the
        # right name
        dest_path = os.path.join(
            os.path.dirname(self.source.path),
            '.debug',
            os.path.basename(debuglink),
        )
        os.makedirs(os.path.dirname(dest_path), exist_ok=True)

        def objcopy(*args):
            subprocess.check_call(
                (get_tool_name('objcopy'), ) + args,
                shell=False,
                stderr=subprocess.DEVNULL,
            )

        # If #812089 was fixed, we would just do os.link(debug_file.path,
        # dest_path) but for now, we need to do more complicated things…
        # 1. Use objcopy to create a file with only the original .gnu_debuglink
        # section as we will have to update it to get the CRC right.
        debuglink_path = get_named_temporary_file(
            prefix='{}.debuglink.'.format(self.source.path)).name

        objcopy('--only-section=.gnu_debuglink', self.source.path,
                debuglink_path)

        # 2. Monkey-patch the ElfSection object created for the .gnu_debuglink
        # to change the path to point to this new file
        section = self._sections['.gnu_debuglink']

        class MonkeyPatchedElfSection(section.__class__):
            @property
            def path(self):
                return debuglink_path

        section.__class__ = MonkeyPatchedElfSection

        # 3. Create a file with the debug symbols in uncompressed form
        objcopy('--decompress-debug-sections', debug_file.path, dest_path)

        # 4. Update the .gnu_debuglink to this new file so we get the CRC right
        objcopy('--remove-section=.gnu_debuglink', self.source.path)
        objcopy('--add-gnu-debuglink={}'.format(dest_path), self.source.path)

        logger.debug('Installed debug symbols at %s', dest_path)
Exemplo n.º 6
0
 def create_placeholder(self):
     with get_named_temporary_file(mode='w+', delete=False) as f:
         f.write(format_device(*self.get_device()))
         f.flush()
         return f.name
Exemplo n.º 7
0
    def convert(file):
        result = get_named_temporary_file(suffix='.png').name

        subprocess.check_call(('convert', file.path, result))

        return result