Exemplo n.º 1
0
def extract_with_progress(input, verbose=False):  # @ReservedAssignment
    """
    Extract archives and display progress.
    """
    if verbose:
        for xev in extract_archives(input, verbose=verbose):
            if not xev.done:
                click.secho('Extracting: ' + xev.source + ': ',
                            nl=False,
                            fg='green')
            else:
                if xev.warnings or xev.errors:
                    click.secho('done.', fg='red' if xev.errors else 'yellow')
                    display_extract_event(xev)
                else:
                    click.secho('done.', fg='green')
    else:
        extract_results = []
        # only display a progress bar
        with click.progressbar(extract_archives(input, verbose=verbose),
                               show_pos=True) as extractions:
            for xevent in extractions:
                extract_results.append(xevent)
        # display warnings/errors at the end
        for xev in extract_results:
            if xev.warnings or xev.errors:
                if xev.warnings or xev.errors:
                    click.secho('Extracting: ' + xev.source + ': ',
                                nl=False,
                                fg='green')
                    click.secho('done.', fg='red' if xev.errors else 'yellow')
                    display_extract_event(xev)
Exemplo n.º 2
0
def extract_with_progress(input, verbose=False):
    """
    Extract archives and display progress.
    """
    if verbose:
        for xev in extract_archives(input, verbose=verbose):
            if not xev.done:
                click.secho('Extracting: ' + xev.source + ': ', nl=False, fg='green')
            else:
                if xev.warnings or xev.errors:
                    click.secho('done.', fg='red' if xev.errors else 'yellow')
                    display_extract_event(xev)
                else:
                    click.secho('done.', fg='green')
    else:
        extract_results = []
        # only display a progress bar
        with click.progressbar(extract_archives(input, verbose=verbose), show_pos=True) as extractions:
            for xevent in extractions:
                extract_results.append(xevent)
        # display warnings/errors at the end
        for xev in extract_results:
            if xev.warnings or xev.errors:
                if xev.warnings or xev.errors:
                    click.secho('Extracting: ' + xev.source + ': ', nl=False, fg='green')
                    click.secho('done.', fg='red' if xev.errors else 'yellow')
                    display_extract_event(xev)
Exemplo n.º 3
0
def extractcode(ctx, input, verbose, quiet, shallow, *args, **kwargs):  # @ReservedAssignment
    """extract archives and compressed files found in the <input> file or directory tree.

    Use this command before scanning proper as an <input> preparation step.
    Archives found inside an extracted archive are extracted recursively.
    Extraction is done in-place in a directory named '-extract' side-by-side with an archive.
    """

    abs_location = fileutils.as_posixpath(os.path.abspath(os.path.expanduser(input)))

    def extract_event(item):
        """
        Display an extract event.
        """
        if quiet:
            return ''
        if not item:
            return ''
        source = item.source
        if not isinstance(source, unicode):
            source = toascii(source, translit=True).decode('utf-8', 'replace')
        if verbose:
            if item.done:
                return ''
            line = source and utils.get_relative_path(path=source, len_base_path=len_base_path, base_is_dir=base_is_dir) or ''
        else:
            line = source and fileutils.file_name(source) or ''
        if not isinstance(line, unicode):
            line = toascii(line, translit=True).decode('utf-8', 'replace')
        return 'Extracting: %(line)s' % locals()

    def display_extract_summary():
        """
        Display a summary of warnings and errors if any.
        """
        has_warnings = False
        has_errors = False
        summary = []
        for xev in extract_results:
            has_errors = has_errors or bool(xev.errors)
            has_warnings = has_warnings or bool(xev.warnings)
            source = fileutils.as_posixpath(xev.source)
            if not isinstance(source, unicode):
                source = toascii(source, translit=True).decode('utf-8', 'replace')
                source = utils.get_relative_path(path=source, len_base_path=len_base_path, base_is_dir=base_is_dir)
            for e in xev.errors:
                echo_stderr('ERROR extracting: %(source)s: %(e)s' % locals(), fg='red')
            for warn in xev.warnings:
                echo_stderr('WARNING extracting: %(source)s: %(warn)s' % locals(), fg='yellow')

        summary_color = 'green'
        if has_warnings:
            summary_color = 'yellow'
        if has_errors:
            summary_color = 'red'

        echo_stderr('Extracting done.', fg=summary_color, reset=True)


    # use for relative paths computation
    len_base_path = len(abs_location)
    base_is_dir = filetype.is_dir(abs_location)

    extract_results = []
    has_extract_errors = False
    if not quiet:
        echo_stderr('Extracting archives...', fg='green')

    with utils.progressmanager(extract_archives(abs_location, recurse=not shallow), item_show_func=extract_event,
                               verbose=verbose, quiet=quiet) as extraction_events:
        for xev in extraction_events:
            if xev.done and (xev.warnings or xev.errors):
                has_extract_errors = has_extract_errors or xev.errors
                extract_results.append(xev)

    if not quiet:
        display_extract_summary()

    rc = 1 if has_extract_errors else 0
    ctx.exit(rc)
Exemplo n.º 4
0
def extractcode(ctx, input, verbose, quiet, shallow, *args, **kwargs):  # @ReservedAssignment
    """extract archives and compressed files found in the <input> file or directory tree.

    Use this command before scanning proper as an <input> preparation step.
    Archives found inside an extracted archive are extracted recursively.
    Extraction is done in-place in a directory named '-extract' side-by-side with an archive.
    """

    abs_location = fileutils.as_posixpath(os.path.abspath(os.path.expanduser(input)))

    def extract_event(item):
        """
        Display an extract event.
        """
        if quiet:
            return ''
        if not item:
            return ''
        source = item.source
        if not isinstance(source, unicode):
            source = toascii(source, translit=True).decode('utf-8', 'replace')
        if verbose:
            if item.done:
                return ''
            line = source and utils.get_relative_path(path=source, len_base_path=len_base_path, base_is_dir=base_is_dir) or ''
        else:
            line = source and fileutils.file_name(source) or ''
        if not isinstance(line, unicode):
            line = toascii(line, translit=True).decode('utf-8', 'replace')
        return 'Extracting: %(line)s' % locals()

    def display_extract_summary():
        """
        Display a summary of warnings and errors if any.
        """
        has_warnings = False
        has_errors = False
        summary = []
        for xev in extract_results:
            has_errors = has_errors or bool(xev.errors)
            has_warnings = has_warnings or bool(xev.warnings)
            source = fileutils.as_posixpath(xev.source)
            if not isinstance(source, unicode):
                source = toascii(source, translit=True).decode('utf-8', 'replace')
                source = utils.get_relative_path(path=source, len_base_path=len_base_path, base_is_dir=base_is_dir)
            for e in xev.errors:
                echo_stderr('ERROR extracting: %(source)s: %(e)s' % locals(), fg='red')
            for warn in xev.warnings:
                echo_stderr('WARNING extracting: %(source)s: %(warn)s' % locals(), fg='yellow')

        summary_color = 'green'
        if has_warnings:
            summary_color = 'yellow'
        if has_errors:
            summary_color = 'red'

        echo_stderr('Extracting done.', fg=summary_color, reset=True)


    # use for relative paths computation
    len_base_path = len(abs_location)
    base_is_dir = filetype.is_dir(abs_location)

    extract_results = []
    has_extract_errors = False
    if not quiet:
        echo_stderr('Extracting archives...', fg='green')

    with utils.progressmanager(extract_archives(abs_location, recurse=not shallow), item_show_func=extract_event,
                               verbose=verbose, quiet=quiet) as extraction_events:
        for xev in extraction_events:
            if xev.done and (xev.warnings or xev.errors):
                has_extract_errors = has_extract_errors or xev.errors
                extract_results.append(xev)

    if not quiet:
        display_extract_summary()

    rc = 1 if has_extract_errors else 0
    ctx.exit(rc)
Exemplo n.º 5
0
def extractcode(ctx, input, verbose, quiet, *args,
                **kwargs):  # @ReservedAssignment
    """extract archives and compressed files found in the <input> file or directory tree.

    Use this command before scanning proper, as an <input> preparation step.
    Archives found inside an extracted archive are extracted recursively.
    Extraction is done in-place in a directory named '-extract' side-by-side with an archive.
    """

    original_input = fileutils.as_posixpath(input)
    abs_input = fileutils.as_posixpath(
        os.path.abspath(os.path.expanduser(input)))

    # note: we inline functions so they can close on local variables

    def extract_start():
        return style('Extracting archives...', fg='green')

    def extract_event(item):
        """
        Display an extract event.
        """
        if not item:
            return ''
        if verbose:
            if item.done:
                return ''
            line = utils.get_relative_path(original_input, abs_input,
                                           as_posixpath(item.source)) or ''
        else:
            line = fileutils.file_name(item.source) or ''
        return 'Extracting: %(line)s' % locals()

    def extract_end():
        """
        Display a summary of warnings and errors if any.
        """
        has_warnings = False
        has_errors = False
        summary = []
        for xev in extract_results:
            has_errors = has_errors or bool(xev.errors)
            has_warnings = has_warnings or bool(xev.warnings)
            source = as_posixpath(xev.source)
            source = utils.get_relative_path(original_input, abs_input, source)
            for e in xev.errors:
                summary.append(
                    style('ERROR extracting: %(source)s: %(e)r' % locals(),
                          fg='red',
                          reset=False))
            for warn in xev.warnings:
                summary.append(
                    style('WARNING extracting: %(source)s: %(warn)r' %
                          locals(),
                          fg='yellow',
                          reset=False))

        summary_color = 'green'
        if has_warnings:
            summary_color = 'yellow'
        if has_errors:
            summary_color = 'red'

        summary.append(style('Extracting done.', fg=summary_color, reset=True))
        return '\n'.join(summary)

    extract_results = []
    has_extract_errors = False

    with utils.progressmanager(
            extract_archives(abs_input),
            item_show_func=extract_event,
            start_show_func=extract_start,
            finish_show_func=extract_end,
            verbose=verbose,
            quiet=quiet,
    ) as extraction_events:
        for xev in extraction_events:
            if xev.done and (xev.warnings or xev.errors):
                has_extract_errors = has_extract_errors or xev.errors
                extract_results.append(xev)

    rc = 1 if has_extract_errors else 0
    ctx.exit(rc)
Exemplo n.º 6
0
def extractcode(ctx, input, verbose, quiet, *args, **kwargs):  # @ReservedAssignment
    """extract archives and compressed files found in the <input> file or directory tree.

    Use this command before scanning proper, as an <input> preparation step.
    Archives found inside an extracted archive are extracted recursively.
    Extraction is done in-place in a directory named '-extract' side-by-side with an archive.
    """

    original_input = fileutils.as_posixpath(input)
    abs_input = fileutils.as_posixpath(os.path.abspath(os.path.expanduser(input)))

    # note: we inline functions so they can close on local variables

    def extract_start():
        return style('Extracting archives...', fg='green')


    def extract_event(item):
        """
        Display an extract event.
        """
        if not item:
            return ''
        if verbose:
            if item.done:
                return ''
            line = utils.get_relative_path(original_input, abs_input, as_posixpath(item.source)) or ''
        else:
            line = fileutils.file_name(item.source) or ''
        return 'Extracting: %(line)s' % locals()


    def extract_end():
        """
        Display a summary of warnings and errors if any.
        """
        has_warnings = False
        has_errors = False
        summary = []
        for xev in extract_results:
            has_errors = has_errors or bool(xev.errors)
            has_warnings = has_warnings or bool(xev.warnings)
            source = as_posixpath(xev.source)
            source = utils.get_relative_path(original_input, abs_input, source)
            for e in xev.errors:
                summary.append(style('ERROR extracting: %(source)s: %(e)r' % locals(), fg='red', reset=False))
            for warn in xev.warnings:
                summary.append(style('WARNING extracting: %(source)s: %(warn)r' % locals(), fg='yellow', reset=False))

        summary_color = 'green'
        if has_warnings:
            summary_color = 'yellow'
        if has_errors:
            summary_color = 'red'

        summary.append(style('Extracting done.', fg=summary_color, reset=True))
        return '\n'.join(summary)


    extract_results = []
    has_extract_errors = False

    with utils.progressmanager(extract_archives(abs_input),
                               item_show_func=extract_event,
                               start_show_func=extract_start,
                               finish_show_func=extract_end,
                               verbose=verbose,
                               quiet=quiet,
                               ) as extraction_events:
        for xev in extraction_events:
            if xev.done and (xev.warnings or xev.errors):
                has_extract_errors = has_extract_errors or xev.errors
                extract_results.append(xev)

    rc = 1 if has_extract_errors else 0
    ctx.exit(rc)