コード例 #1
0
ファイル: build_tar.py プロジェクト: tomorrowkey/bazel
    def add_deb(self, deb):
        """Extract a debian package in the output tar.

    All files presents in that debian package will be added to the
    output tar under the same paths. No user name nor group names will
    be added to the output.

    Args:
      deb: the tar file to add

    Raises:
      DebError: if the format of the deb archive is incorrect.
    """
        with archive.SimpleArFile(deb) as arfile:
            current = arfile.next()
            while current and not current.filename.startswith('data.'):
                current = arfile.next()
            if not current:
                raise self.DebError(deb + ' does not contains a data file!')
            tmpfile = tempfile.mkstemp(
                suffix=os.path.splitext(current.filename)[-1])
            with open(tmpfile[1], 'wb') as f:
                f.write(current.data)
            self.add_tar(tmpfile[1])
            os.remove(tmpfile[1])
コード例 #2
0
    def assertArFileContent(self, arfile, content):
        """Assert that arfile contains exactly the entry described by `content`.

    Args:
        arfile: the path to the AR file to test.
        content: an array describing the expected content of the AR file.
            Each entry in that list should be a dictionary where each field
            is a field to test in the corresponding SimpleArFileEntry. For
            testing the presence of a file "x", then the entry could simply
            be `{"filename": "x"}`, the missing field will be ignored.
    """
        with archive.SimpleArFile(arfile) as f:
            current = f.next()
            i = 0
            while current:
                error_msg = "Extraneous file at end of archive %s: %s" % (
                    arfile, current.filename)
                self.assertTrue(i < len(content), error_msg)
                for k, v in content[i].items():
                    value = getattr(current, k)
                    error_msg = " ".join([
                        "Value `%s` for key `%s` of file" % (value, k),
                        "%s in archive %s does" % (current.filename, arfile),
                        "not match expected value `%s`" % v
                    ])
                    self.assertEqual(value, v, error_msg)
                current = f.next()
                i += 1
            if i < len(content):
                self.fail("Missing file %s in archive %s" %
                          (content[i], arfile))
コード例 #3
0
ファイル: build_tar.py プロジェクト: syml/rules_docker
    def add_deb(self, deb):
        """Extract a debian package in the output tar.

    All files presents in that debian package will be added to the
    output tar under the same paths. No user name nor group names will
    be added to the output.

    Args:
      deb: the tar file to add

    Raises:
      DebError: if the format of the deb archive is incorrect.
    """
        pkg_data_found = False
        pkg_metadata_found = False
        with archive.SimpleArFile(deb) as arfile:
            current = arfile.next()
            while current:
                parts = current.filename.split(".")
                name = parts[0]
                if parts[-1].lower() == 'xz':
                    current.data = self._xz_decompress(current.data)
                    ext = '.'.join(parts[1:-1])
                else:
                    ext = '.'.join(parts[1:])
                if name == 'data':
                    pkg_data_found = True
                    # Add pkg_data to image tar
                    with self.write_temp_file(suffix=ext,
                                              data=current.data) as tmpfile:
                        self.add_tar(tmpfile)
                elif name == 'control':
                    pkg_metadata_found = True
                    # Add metadata file to image tar
                    with self.write_temp_file(suffix=ext,
                                              data=current.data) as tmpfile:
                        self.add_pkg_metadata(metadata_tar=tmpfile, deb=deb)
                current = arfile.next()

        if not pkg_data_found:
            raise self.DebError(deb + ' does not contains a data file!')
        if not pkg_metadata_found:
            raise self.DebError(deb + ' does not contains a control file!')