Exemple #1
0
    def test_tar_finder(self):
        self.tar = tarfile.open(name=self.tmppath("test.tar.bz2"), mode="w:bz2")
        self.prepare_match_test()
        self.tar.close()
        with tarfile.open(name=self.tmppath("test.tar.bz2"), mode="r:bz2") as tarreader:
            self.finder = TarFinder(self.tmppath("test.tar.bz2"), tarreader)
            self.do_match_test()

            self.assertIsNone(self.finder.get("does-not-exist"))
            self.assertIsInstance(self.finder.get("bar"), ExtractedTarFile)
Exemple #2
0
    def test_tar_finder(self):
        self.tar = tarfile.open(name=self.tmppath('test.tar.bz2'),
                                mode='w:bz2')
        self.prepare_match_test()
        self.tar.close()
        with tarfile.open(name=self.tmppath('test.tar.bz2'),
                          mode='r:bz2') as tarreader:
            self.finder = TarFinder(self.tmppath('test.tar.bz2'), tarreader)
            self.do_match_test()

            self.assertIsNone(self.finder.get('does-not-exist'))
            self.assertIsInstance(self.finder.get('bar'), ExtractedTarFile)
    def process_package_artifact(self, filename, processed_filename):
        added_entry = False

        with JarWriter(file=processed_filename,
                       optimize=False,
                       compress_level=5) as writer:
            with tarfile.open(filename) as reader:
                for p, f in UnpackFinder(TarFinder(filename, reader)):
                    if not any(
                            mozpath.match(p, pat)
                            for pat in self.package_artifact_patterns):
                        continue

                    # We strip off the relative "firefox/" bit from the path,
                    # but otherwise preserve it.
                    destpath = mozpath.join('bin',
                                            mozpath.relpath(p, "firefox"))
                    self.log(logging.INFO, 'artifact', {'destpath': destpath},
                             'Adding {destpath} to processed archive')
                    writer.add(destpath.encode('utf-8'), f.open(), mode=f.mode)
                    added_entry = True

        if not added_entry:
            raise ValueError(
                'Archive format changed! No pattern from "{patterns}" '
                'matched an archive path.'.format(
                    patterns=LinuxArtifactJob.package_artifact_patterns))
Exemple #4
0
class TestTarFinder(MatchTestTemplate, TestWithTmpDir):
    def add(self, path):
        self.tar.addfile(tarfile.TarInfo(name=path))

    def do_check(self, pattern, result):
        do_check(self, self.finder, pattern, result)

    def test_tar_finder(self):
        self.tar = tarfile.open(name=self.tmppath("test.tar.bz2"), mode="w:bz2")
        self.prepare_match_test()
        self.tar.close()
        with tarfile.open(name=self.tmppath("test.tar.bz2"), mode="r:bz2") as tarreader:
            self.finder = TarFinder(self.tmppath("test.tar.bz2"), tarreader)
            self.do_match_test()

            self.assertIsNone(self.finder.get("does-not-exist"))
            self.assertIsInstance(self.finder.get("bar"), ExtractedTarFile)
Exemple #5
0
class TestTarFinder(MatchTestTemplate, TestWithTmpDir):
    def add(self, path):
        self.tar.addfile(tarfile.TarInfo(name=path))

    def do_check(self, pattern, result):
        do_check(self, self.finder, pattern, result)

    def test_tar_finder(self):
        self.tar = tarfile.open(name=self.tmppath('test.tar.bz2'),
                                mode='w:bz2')
        self.prepare_match_test()
        self.tar.close()
        with tarfile.open(name=self.tmppath('test.tar.bz2'),
                          mode='r:bz2') as tarreader:
            self.finder = TarFinder(self.tmppath('test.tar.bz2'), tarreader)
            self.do_match_test()

            self.assertIsNone(self.finder.get('does-not-exist'))
            self.assertIsInstance(self.finder.get('bar'), ExtractedTarFile)
Exemple #6
0
    def test_tar_finder(self):
        self.tar = tarfile.open(name=self.tmppath('test.tar.bz2'),
                                mode='w:bz2')
        self.prepare_match_test()
        self.tar.close()
        with tarfile.open(name=self.tmppath('test.tar.bz2'),
                          mode='r:bz2') as tarreader:
            self.finder = TarFinder(self.tmppath('test.tar.bz2'), tarreader)
            self.do_match_test()

            self.assertIsNone(self.finder.get('does-not-exist'))
            self.assertIsInstance(self.finder.get('bar'), ExtractedTarFile)
Exemple #7
0
    def process_tests_tar_artifact(self, filename, processed_filename):
        from mozbuild.action.test_archive import OBJDIR_TEST_FILES
        added_entry = False

        with JarWriter(file=processed_filename, compress_level=5) as writer:
            with tarfile.open(filename) as reader:
                for filename, entry in TarFinder(filename, reader):
                    for pattern, (src_prefix, dest_prefix) in self.test_artifact_patterns:
                        if not mozpath.match(filename, pattern):
                            continue

                        destpath = mozpath.relpath(filename, src_prefix)
                        destpath = mozpath.join(dest_prefix, destpath)
                        self.log(logging.INFO, 'artifact',
                                 {'destpath': destpath},
                                 'Adding {destpath} to processed archive')
                        mode = entry.mode
                        writer.add(destpath.encode('utf-8'), entry.open(), mode=mode)
                        added_entry = True
                        break
                    for files_entry in OBJDIR_TEST_FILES.values():
                        origin_pattern = files_entry['pattern']
                        leaf_filename = filename
                        if 'dest' in files_entry:
                            dest = files_entry['dest']
                            origin_pattern = mozpath.join(dest, origin_pattern)
                            leaf_filename = filename[len(dest) + 1:]
                        if mozpath.match(filename, origin_pattern):
                            destpath = mozpath.join('..', files_entry['base'], leaf_filename)
                            mode = entry.mode
                            writer.add(destpath.encode('utf-8'), entry.open(), mode=mode)

        if not added_entry:
            raise ValueError('Archive format changed! No pattern from "{patterns}"'
                             'matched an archive path.'.format(
                                 patterns=LinuxArtifactJob.test_artifact_patterns))