How to use the extractcode.libarchive2.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_libarchive2.py View on Github external
# To use relative paths, we use our tmp dir at the root of the code tree
        from os.path import dirname, join, abspath
        import tempfile
        import shutil
        from extractcode.libarchive2 import extract

        test_file = self.get_test_loc('archive/relative_path/basic.zip')
        scancode_root = dirname(dirname(dirname(__file__)))
        scancode_tmp = join(scancode_root, 'tmp')
        fileutils.create_dir(scancode_tmp)
        scancode_root_abs = abspath(scancode_root)
        test_src_dir = tempfile.mkdtemp(dir=scancode_tmp).replace(scancode_root_abs, '').strip('\\/')
        test_tgt_dir = tempfile.mkdtemp(dir=scancode_tmp).replace(scancode_root_abs, '').strip('\\/')
        shutil.copy(test_file, test_src_dir)
        test_src_file = join(test_src_dir, 'basic.zip')
        result = list(extract(test_src_file, test_tgt_dir))
        assert [] == result
        expected = ['c/a/a.txt', 'c/b/a.txt', 'c/c/a.txt']
        check_files(test_tgt_dir, expected)
github nexB / scancode-toolkit / tests / extractcode / test_archive.py View on Github external
def test_extract_ar_with_weird_filenames_with_libarchive(self):
        test_file = self.get_test_loc('archive/weird_names/weird_names.ar')
        warns = ['None: \nIncorrect file header signature']
        self.check_extract(libarchive2.extract, test_file, expected_warnings=warns, expected_suffix='libarch')
github nexB / scancode-toolkit / tests / extractcode / test_archive.py View on Github external
# To use relative paths, we use our tmp dir at the root of the code tree
        from os.path import dirname, join, abspath
        import tempfile
        import shutil
        from extractcode.libarchive2 import extract

        test_file = self.get_test_loc('archive/relative_path/basic.zip')
        scancode_root = dirname(dirname(dirname(__file__)))
        scancode_tmp = join(scancode_root, 'tmp')
        fileutils.create_dir(scancode_tmp)
        scancode_root_abs = abspath(scancode_root)
        test_src_dir = tempfile.mkdtemp(dir=scancode_tmp).replace(scancode_root_abs, '').strip('\\/')
        test_tgt_dir = tempfile.mkdtemp(dir=scancode_tmp).replace(scancode_root_abs, '').strip('\\/')
        shutil.copy(test_file, test_src_dir)
        test_src_file = join(test_src_dir, 'basic.zip')
        result = list(extract(test_src_file, test_tgt_dir))
        assert [] == result
        expected = ['c/a/a.txt', 'c/b/a.txt', 'c/c/a.txt']
        check_files(test_tgt_dir, expected)
github nexB / scancode-toolkit / src / extractcode / archive.py View on Github external
########################################################


extract_tar = libarchive2.extract
extract_patch = patch.extract

extract_deb = libarchive2.extract
extract_ar = libarchive2.extract
extract_msi = sevenzip.extract
extract_cpio = libarchive2.extract

# sevenzip should be best at extracting 7zip but most often libarchive is better first
extract_7z = functional.partial(extract_with_fallback, extractor1=libarchive2.extract, extractor2=sevenzip.extract)

# libarchive is best for the run of the mill zips, but sevenzip sometimes is better
extract_zip = functional.partial(extract_with_fallback, extractor1=libarchive2.extract, extractor2=sevenzip.extract)

extract_springboot = functional.partial(try_to_extract, extractor=extract_zip)

extract_lzip = libarchive2.extract

extract_iso = sevenzip.extract
extract_rar = libarchive2.extract
extract_rpm = sevenzip.extract
extract_xz = sevenzip.extract
extract_lzma = sevenzip.extract
extract_squashfs = sevenzip.extract
extract_cab = sevenzip.extract
extract_nsis = sevenzip.extract
extract_ishield = sevenzip.extract
extract_Z = sevenzip.extract
extract_xarpkg = sevenzip.extract
github nexB / scancode-toolkit / src / extractcode / archive.py View on Github external
logger.debug('try_to_extract: temp_target: %(temp_target)r' % locals())
        fileutils.copytree(temp_target, abs_target_dir)
    except:
        return warnings
    finally:
        fileutils.delete(temp_target)
    return warnings

# High level aliases to lower level extraction functions
########################################################


extract_tar = libarchive2.extract
extract_patch = patch.extract

extract_deb = libarchive2.extract
extract_ar = libarchive2.extract
extract_msi = sevenzip.extract
extract_cpio = libarchive2.extract

# sevenzip should be best at extracting 7zip but most often libarchive is better first
extract_7z = functional.partial(extract_with_fallback, extractor1=libarchive2.extract, extractor2=sevenzip.extract)

# libarchive is best for the run of the mill zips, but sevenzip sometimes is better
extract_zip = functional.partial(extract_with_fallback, extractor1=libarchive2.extract, extractor2=sevenzip.extract)

extract_springboot = functional.partial(try_to_extract, extractor=extract_zip)

extract_lzip = libarchive2.extract

extract_iso = sevenzip.extract
extract_rar = libarchive2.extract
github nexB / scancode-toolkit / src / extractcode / archive.py View on Github external
return warnings

# High level aliases to lower level extraction functions
########################################################


extract_tar = libarchive2.extract
extract_patch = patch.extract

extract_deb = libarchive2.extract
extract_ar = libarchive2.extract
extract_msi = sevenzip.extract
extract_cpio = libarchive2.extract

# sevenzip should be best at extracting 7zip but most often libarchive is better first
extract_7z = functional.partial(extract_with_fallback, extractor1=libarchive2.extract, extractor2=sevenzip.extract)

# libarchive is best for the run of the mill zips, but sevenzip sometimes is better
extract_zip = functional.partial(extract_with_fallback, extractor1=libarchive2.extract, extractor2=sevenzip.extract)

extract_springboot = functional.partial(try_to_extract, extractor=extract_zip)

extract_lzip = libarchive2.extract

extract_iso = sevenzip.extract
extract_rar = libarchive2.extract
extract_rpm = sevenzip.extract
extract_xz = sevenzip.extract
extract_lzma = sevenzip.extract
extract_squashfs = sevenzip.extract
extract_cab = sevenzip.extract
extract_nsis = sevenzip.extract
github nexB / scancode-toolkit / src / extractcode / archive.py View on Github external
fileutils.copytree(temp_target, abs_target_dir)
    except:
        return warnings
    finally:
        fileutils.delete(temp_target)
    return warnings

# High level aliases to lower level extraction functions
########################################################


extract_tar = libarchive2.extract
extract_patch = patch.extract

extract_deb = libarchive2.extract
extract_ar = libarchive2.extract
extract_msi = sevenzip.extract
extract_cpio = libarchive2.extract

# sevenzip should be best at extracting 7zip but most often libarchive is better first
extract_7z = functional.partial(extract_with_fallback, extractor1=libarchive2.extract, extractor2=sevenzip.extract)

# libarchive is best for the run of the mill zips, but sevenzip sometimes is better
extract_zip = functional.partial(extract_with_fallback, extractor1=libarchive2.extract, extractor2=sevenzip.extract)

extract_springboot = functional.partial(try_to_extract, extractor=extract_zip)

extract_lzip = libarchive2.extract

extract_iso = sevenzip.extract
extract_rar = libarchive2.extract
extract_rpm = sevenzip.extract