How to use the pypyr.utils.filesystem.get_glob function in pypyr

To help you get started, we’ve selected a few pypyr 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 pypyr / pypyr-cli / pypyr / steps / pathcheck.py View on Github external
f"value for {__name__}.")

    # pathsToCheck can be a string or a list in case there are multiple paths
    if isinstance(paths_to_check, list):
        check_me = paths_to_check
    else:
        # assuming it's a str/path at this point
        check_me = [paths_to_check]

    out = {}
    total_found = 0

    for path in check_me:
        logger.debug("checking path: %s", path)
        formatted_path = context.get_formatted_string(path)
        found_paths = pypyr.utils.filesystem.get_glob(formatted_path)
        no_of_paths = len(found_paths)
        out[path] = {
            'exists': no_of_paths > 0,
            'count': no_of_paths,
            'found': found_paths
        }
        total_found = total_found + no_of_paths

    context['pathCheckOut'] = out

    logger.info(f'checked {len(out)} path(s) and found {total_found}')
    logger.debug("done")
github pypyr / pypyr-cli / pypyr / steps / glob.py View on Github external
"""
    logger.debug("started")
    context.assert_key_has_value(key='glob', caller=__name__)

    paths = context.get_formatted('glob')
    if isinstance(paths, list):
        if not paths or any(not p for p in paths):
            raise KeyInContextHasNoValueError("The glob list has an empty str")
        in_count = len(paths)
    else:
        if not paths:
            raise KeyInContextHasNoValueError("The glob path is an empty str")
        in_count = 1

    context['globOut'] = pypyr.utils.filesystem.get_glob(paths)

    logger.info("glob checked %s globs and saved "
                "%s paths to globOut", in_count, len(context['globOut']))
    logger.debug("done")