How to use the extractcode.tar.extract function in extractcode

To help you get started, we’ve selected a few extractcode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nexB / scancode-toolkit / tests / extractcode / test_tar.py View on Github external
def test_extract_targz_with_absolute_path(self):
        non_result = '/tmp/subdir'
        assert not os.path.exists(non_result)

        test_dir = self.get_temp_dir()
        test_file = self.get_test_loc('archive/tgz/absolute_path.tar.gz')
        tar.extract(test_file, test_dir)
        assert not os.path.exists(non_result)
        result = os.path.join(test_dir, 'tmp/subdir/a.txt')
        assert os.path.exists(result)
github nexB / scancode-toolkit / tests / extractcode / test_tar.py View on Github external
def test_extract_tar_bz2_absolute_path(self):
        assert not os.path.exists('/tmp/subdir')
        test_dir = self.get_temp_dir()
        test_file = self.get_test_loc('archive/tbz/absolute_path.tar.bz2')
        tar.extract(test_file, test_dir)
        assert not os.path.exists('/tmp/subdir')
        result = os.path.join(test_dir, 'tmp/subdir/a.txt')
        assert os.path.exists(result)
github nexB / scancode-toolkit / tests / extractcode / test_tar.py View on Github external
def test_extract_tar_bz2_basic_bz(self):
        test_file = self.get_test_loc('archive/tbz/tarred_bzipped.bz')
        test_dir = self.get_temp_dir()
        tar.extract(test_file, test_dir)
        result = os.path.join(test_dir, 'e/a/b.txt')
        assert os.path.exists(result)
github nexB / scancode-toolkit / tests / extractcode / test_tar.py View on Github external
def test_extract_tar_basic(self):
        test_file = self.get_test_loc('archive/tar/tarred.tar')
        test_dir = self.get_temp_dir()
        tar.extract(test_file, test_dir)
        result = os.path.join(test_dir, 'e/a/b.txt')
        assert os.path.exists(result)
github nexB / scancode-toolkit / tests / extractcode / test_tar.py View on Github external
def test_extract_tar_bz2_relative_path(self):
        test_file = self.get_test_loc('archive/tbz/bz2withtar_relative.tar.bz2')
        """
        This test file was created with:
            import tarfile
            tar = tarfile.open("TarTest.tar.gz", "w:bz")
            tar.add('a.txt', '../a_parent_folder.txt')
            tar.add('b.txt', '../../another_folder/b_two_root.txt')
            tar.add('b.txt', '../folder/subfolder/b_subfolder.txt')
            tar.close()
        """
        test_dir = self.get_temp_dir()
        tar.extract(test_file, test_dir)

        non_result = os.path.join(test_dir, '../a_parent_folder.txt')
        assert not os.path.exists(non_result)

        result = os.path.join(test_dir, 'dotdot/folder/subfolder/b_subfolder.txt')
        assert os.path.exists(result)
        result = os.path.join(test_dir, 'dotdot', 'a_parent_folder.txt')
        assert os.path.exists(result)
github nexB / scancode-toolkit / tests / extractcode / test_tar.py View on Github external
def test_extract_targz_with_mixed_case_and_symlink(self):
        test_file = self.get_test_loc('archive/tgz/mixed_case_and_symlink.tgz')
        test_dir = self.get_temp_dir()
        expected = [
            'skinenigmang/hqlogos/arte.xpm: Skipping duplicate file name.',
            'skinenigmang/hqlogos/MTV Hits.xpm: Skipping duplicate file name.',
            'skinenigmang/hqlogos/Disney Channel.xpm: Skipping duplicate file name.',
            'skinenigmang/hqlogos/EuroNews.xpm: Skipping duplicate file name.',
            'skinenigmang/hqlogos/Jetix.xpm: Skipping duplicate file name.',
            "skinenigmang/hqlogos/MTV France.xpm: Skipping link to special file: skinenigmang/hqlogos/MTV F.xpm"
        ]
        result = tar.extract(test_file, test_dir)
        result = [m.replace(test_dir, '').strip('\\/') for m in result]
        assert expected == result
#         expected_files = []
github nexB / scancode-toolkit / tests / extractcode / test_archive.py View on Github external
'weird_names/win/lpt1: Skipping duplicate file name.',
            'weird_names/win/lpt2: Skipping duplicate file name.',
            'weird_names/win/lpt3: Skipping duplicate file name.',
            'weird_names/win/lpt4: Skipping duplicate file name.',
            'weird_names/win/lpt5: Skipping duplicate file name.',
            'weird_names/win/lpt6: Skipping duplicate file name.',
            'weird_names/win/lpt7: Skipping duplicate file name.',
            'weird_names/win/lpt8: Skipping duplicate file name.',
            'weird_names/win/lpt9: Skipping duplicate file name.',
            'weird_names/win/nul.txt: Skipping duplicate file name.',
            'weird_names/win/nul: Skipping duplicate file name.',
            'weird_names/win/prn.txt: Skipping duplicate file name.',
            'weird_names/win/prn: Skipping duplicate file name.'
        ]

        self.check_extract(tar.extract, test_file, expected_warnings=warns, expected_suffix='pytar')
github nexB / scancode-toolkit / tests / extractcode / test_tar.py View on Github external
def test_extract_targz_basic(self):
        test_file = self.get_test_loc('archive/tgz/tarred_gzipped.tar.gz')
        test_dir = self.get_temp_dir()
        tar.extract(test_file, test_dir)
        result = os.path.join(test_dir, 'e/a/b.txt')
        assert os.path.exists(result)
github nexB / scancode-toolkit / tests / extractcode / test_tar.py View on Github external
def test_extract_targz_with_trailing_data2(self):
        test_dir1 = self.get_temp_dir()
        test_file = self.get_test_loc('archive/tgz/trailing2.tar.gz')
        tar.extract(test_file, test_dir1)

        test_dir2 = self.get_temp_dir()
        test_file2 = self.get_test_loc('archive/tgz/no_trailing.tar.gz')
        tar.extract(test_file2, test_dir2)
        assert commoncode.testcase.is_same(test_dir1, test_dir2)