How to use the extractcode.ExtractErrorFailedToExtract 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_archive.py View on Github external
def test_extract_7z_with_broken_archive_does_not_fail_when_using_fallback(self):
        test_file = self.get_test_loc('archive/7z/corrupted7z.7z')
        test_dir = self.get_temp_dir()
        msg = 'Unknown extraction error'
        self.assertRaisesInstance(ExtractErrorFailedToExtract(msg), archive.extract_7z, test_file, test_dir)
github nexB / scancode-toolkit / tests / extractcode / test_archive.py View on Github external
def test_extract_zip_with_password(self):
        test_file = self.get_test_loc('archive/zip/zip_password_nexb.zip')
        test_dir = self.get_temp_dir()
        try:
            archive.extract_zip(test_file, test_dir)
        except Exception, e:
            assert isinstance(e, ExtractErrorFailedToExtract)
            assert 'Password protected archive, unable to extract' in str(e)
github nexB / scancode-toolkit / tests / extractcode / test_archive.py View on Github external
def test_extract_7z_with_broken_archive_with7z(self):
        test_file = self.get_test_loc('archive/7z/corrupted7z.7z')
        test_dir = self.get_temp_dir()
        msg = 'Unknown extraction error'
        self.assertRaisesInstance(ExtractErrorFailedToExtract(msg), sevenzip.extract, test_file, test_dir)
github nexB / scancode-toolkit / src / extractcode / patch.py View on Github external
def patch_info(location):
    """
    Yield an iterable of tuples of (src_path, target_path, patch_text)
    for each patch segment of a patch file at location.

    Raise an exception if the file is not a patch file or cannot be parsed.
    """
    patchset = pythonpatch.fromfile(location)
    if not patchset:
        msg = 'Unable to parse patch file: %(location)s' % locals()
        raise ExtractErrorFailedToExtract(msg)

    for ptch in patchset.items:
        src = fileutils.as_posixpath(ptch.source.strip())
        tgt = fileutils.as_posixpath(ptch.target.strip())
        text = [l.strip() for l in patch_text(ptch) if l]
        yield src, tgt, text
github nexB / scancode-toolkit / src / extractcode / sevenzip.py View on Github external
timezone = os.environ.update({'TZ': 'GMT'})

    # Note: 7z does extract in the current directory so we cwd to the target dir first
    args = [extract, yes_to_all, auto_rename_dupe_names,
            arch_type, password, abs_location]
    rc, stdout, _stderr = command.execute(
        cmd='7z',
        args=args,
        cwd=abs_target_dir,
        env=timezone,
        root_dir=root_dir
    )

    if rc != 0:
        error = get_7z_errors(stdout) or UNKNOWN_ERROR
        raise ExtractErrorFailedToExtract(error)

    extractcode.remove_backslashes_and_dotdots(abs_target_dir)
    return get_7z_warnings(stdout)