Ejemplo n.º 1
0
def main(prev_dependency=None):
    """Wrapper around cli(), providing exception handling for dependency
    errors. When a dependency is missing, this will try to resolve that
    dependency and then retry running cli(). When retrying, the
    `prev_dependency` parameter indirectly tells us if we've progressed, due
    to the dependency changing"""
    try:
        cli()
    except dependency.Missing, e:
        resolvers = [resolver(e.dependency)
                     for resolver in DependencyResolver.__subclasses__()]
        resolvers = [r for r in resolvers if r.has_resolution()]
        if e.dependency == prev_dependency or len(resolvers) != 1:
            raise e
        else:
            click.echo("Attempting to resolve dependency: " + e.dependency)
            resolvers[0].resolution()
            main(e.dependency)
Ejemplo n.º 2
0
def run_or_resolve(cmd, prev_dependency=None):
    """Wrapper around a click command or group, providing exception handling for
    dependency errors. When a dependency is missing, this will try to resolve
    that dependency and then retry running cli(). When retrying, the
    `prev_dependency` parameter indirectly tells us if we've progressed, due
    to the dependency changing"""
    try:
        cmd()
    except dependency.Missing as e:
        resolvers = [resolver(e.dependency)
                     for resolver in DependencyResolver.__subclasses__()]
        resolvers = [r for r in resolvers if r.has_resolution()]
        if e.dependency == prev_dependency or len(resolvers) != 1:
            raise e
        else:
            logger.info("Attempting to resolve dependency: %s", e.dependency)
            resolvers[0].resolution()
            run_or_resolve(cmd, e.dependency)
    except pyparsing.ParseException as exc:
        logger.error(u"%s:\n'%s'", exc, exc.line)
        raise