예제 #1
0
def extract_file(location, target, kinds=extractcode.default_kinds, verbose=False):
    """
    Extract a single archive at `location` in the `target` directory if it is
    of a kind supported in the `kinds` kind tuple.
    """
    warnings = []
    errors = []
    extractor = archive.get_extractor(location, kinds)
    if TRACE:
        logger.debug('extract_file: extractor: for: %(location)r with kinds: %(kinds)r : ' % locals()
                     + getattr(extractor, '__module__', '')
                     + '.' + getattr(extractor, '__name__', ''))
    if extractor:
        yield ExtractEvent(location, target, done=False, warnings=[], errors=[])
        try:
            # extract first to a temp directory: if there is an error,  the
            # extracted files will not be moved to target
            tmp_tgt = fileutils.get_temp_dir(prefix='scancode-extract-')
            abs_location = abspath(expanduser(location))
            warns = extractor(abs_location, tmp_tgt) or []
            warnings.extend(warns)
            fileutils.copytree(tmp_tgt, target)
            fileutils.delete(tmp_tgt)
        except Exception as e:
            errors = [str(e).strip(' \'"')]
            if verbose:
                errors.append(traceback.format_exc())
            if TRACE:
                tb = traceback.format_exc()
                logger.debug('extract_file: ERROR: %(location)r: %(errors)r\n%(e)r\n%(tb)s' % locals())

        finally:
            yield ExtractEvent(location, target, done=True, warnings=warnings, errors=errors)
예제 #2
0
def extract_file(location, target, kinds=extractcode.default_kinds):
    """
    Extract a single archive at `location` in the `target` directory if it is
    of a kind supported in the `kinds` kind tuple.
    """
    warnings = []
    errors = []
    extractor = archive.get_extractor(location, kinds)
    if TRACE:
        logger.debug('extract_file: extractor: for: %(location)r with kinds: %(kinds)r : ' % locals()
                     + getattr(extractor, '__module__', '')
                     + '.' + getattr(extractor, '__name__', ''))
    if extractor:
        yield ExtractEvent(location, target, done=False, warnings=[], errors=[])
        try:
            # extract first to a temp directory.
            # if there is an error,  the extracted files will not be moved
            # to target
            tmp_tgt = fileutils.get_temp_dir('extract')
            abs_location = abspath(expanduser(location))
            warnings.extend(extractor(abs_location, tmp_tgt))
            fileutils.copytree(tmp_tgt, target)
            fileutils.delete(tmp_tgt)
        except Exception, e:
            if TRACE:
                logger.debug('extract_file: ERROR: %(location)r: %(errors)r, %(e)r.\n' % locals())
            errors = [str(e).strip(' \'"')]
        finally:
예제 #3
0
def extract_file(location, target, kinds=extractcode.default_kinds):
    """
    Extract a single archive at `location` in the `target` directory if it is
    of a kind supported in the `kinds` kind tuple.
    """
    warnings = []
    errors = []
    extractor = archive.get_extractor(location, kinds)
    if DEBUG:
        logger.debug(
            'extract_file: extractor: for: %(location)r with kinds: r(kinds)r : '
            % locals() + getattr(extractor, '__module__', '') + '.' +
            getattr(extractor, '__name__', ''))
    if extractor:
        yield ExtractEvent(location,
                           target,
                           done=False,
                           warnings=[],
                           errors=[])
        try:
            # extract first to a temp directory.
            # if there is an error,  the extracted files will not be moved
            # to target
            tmp_tgt = fileutils.get_temp_dir('extract')
            abs_location = abspath(expanduser(location))
            warnings.extend(extractor(abs_location, tmp_tgt))
            fileutils.copytree(tmp_tgt, target)
            fileutils.delete(tmp_tgt)
        except Exception, e:
            if DEBUG:
                logger.debug(
                    'extract_file: ERROR: %(location)r: %(errors)r, %(e)r.\n' %
                    locals())
            errors = [str(e).strip(' \'"')]
        finally: