def run_conda_command(command, prefix, *arguments): """ Run conda command, Args: command: conda create , list, info prefix: The prefix or the name of environment *arguments: Extra arguments """ p, sub_parsers = generate_parser() assert command in parser_config, "Wrong command for conda {0}".format(command) parser_config[command](sub_parsers) prefix = escape_for_winpath(prefix) if arguments: arguments = list(map(escape_for_winpath, arguments)) if command is Commands.INFO: # INFO command_line = "{0} {1}".format(command, " ".join(arguments)) elif command is Commands.LIST: # LIST command_line = "{0} -n {1} {2}".format(command, prefix, " ".join(arguments)) else: # CREATE command_line = "{0} -y -q -n {1} {2}".format(command, prefix, " ".join(arguments)) args = p.parse_args(split(command_line)) context._add_argparse_args(args) with captured() as c: args.func(args, p) return c.stdout, c.stderr
def run_command(command, prefix, *arguments): p, sub_parsers = generate_parser() parser_config[command](sub_parsers) prefix = escape_for_winpath(prefix) arguments = list(map(escape_for_winpath, arguments)) if command is Commands.CONFIG: command_line = "{0} --file {1} {2}".format(command, join(prefix, 'condarc'), " ".join(arguments)) elif command is Commands.SEARCH: command_line = "{0} {1}".format(command, " ".join(arguments)) elif command is Commands.LIST: command_line = "{0} -p {1} {2}".format(command, prefix, " ".join(arguments)) else: # CREATE, INSTALL, REMOVE, UPDATE command_line = "{0} -y -q -p {1} {2}".format(command, prefix, " ".join(arguments)) args = p.parse_args(split(command_line)) context._add_argparse_args(args) with captured(disallow_stderr=False) as c: args.func(args, p) print(c.stdout) print(c.stderr, file=sys.stderr) if command is Commands.CONFIG: reload_config(prefix) return c.stdout, c.stderr
def run_env_command(command, prefix, *arguments): """ Run conda env commands Args: command: The command, create, remove, export prefix: The prefix, for remove and create *arguments: The extra arguments """ p = create_parser() prefix = escape_for_winpath(prefix) if arguments: arguments = list(map(escape_for_winpath, arguments)) if command is Commands.ENV_EXPORT: command_line = "{0} -n {1} {2}".format(command, prefix, " ".join(arguments)) elif command is Commands.ENV_CREATE: # CREATE if prefix : command_line = "{0} -f {1} {2}".format(command, prefix, " ".join(arguments)) else: command_line = "{0} ".format(command) elif command is Commands.ENV_REMOVE: # REMOVE command_line = "{0} --yes -n {1} {2}".format(command, prefix, " ".join(arguments)) elif command is Commands.ENV_UPDATE: command_line = "{0} -n {1} {2}".format(command, prefix, " ".join(arguments)) else: command_line = " --help " args = p.parse_args(split(command_line)) context._add_argparse_args(args) with captured() as c: args.func(args, p) return c.stdout, c.stderr
def run_command(command, prefix, *arguments, **kwargs): use_exception_handler = kwargs.get('use_exception_handler', False) arguments = list(arguments) p, sub_parsers = generate_parser() parser_config[command](sub_parsers) if command is Commands.CONFIG: arguments.append("--file {0}".format(join(prefix, 'condarc'))) if command in (Commands.LIST, Commands.CREATE, Commands.INSTALL, Commands.REMOVE, Commands.UPDATE): arguments.append("-p {0}".format(prefix)) if command in (Commands.CREATE, Commands.INSTALL, Commands.REMOVE, Commands.UPDATE): arguments.extend(["-y", "-q"]) arguments = list(map(escape_for_winpath, arguments)) command_line = "{0} {1}".format(command, " ".join(arguments)) args = p.parse_args(split(command_line)) context._add_argparse_args(args) print("executing command >>>", command_line) with captured() as c, replace_log_streams(): if use_exception_handler: conda_exception_handler(args.func, args, p) else: args.func(args, p) print(c.stderr, file=sys.stderr) print(c.stdout) if command is Commands.CONFIG: reload_config(prefix) return c.stdout, c.stderr
def run_conda_command(command, prefix, *arguments): """ Run conda command, Args: command: conda create , list, info prefix: The prefix or the name of environment *arguments: Extra arguments """ p, sub_parsers = generate_parser() assert command in parser_config, "Wrong command for conda {0}".format( command) parser_config[command](sub_parsers) prefix = escape_for_winpath(prefix) if arguments: arguments = list(map(escape_for_winpath, arguments)) if command is Commands.INFO: # INFO command_line = "{0} {1}".format(command, " ".join(arguments)) elif command is Commands.LIST: # LIST command_line = "{0} -n {1} {2}".format(command, prefix, " ".join(arguments)) else: # CREATE command_line = "{0} -y -q -n {1} {2}".format(command, prefix, " ".join(arguments)) args = p.parse_args(split(command_line)) context._add_argparse_args(args) with captured() as c: args.func(args, p) return c.stdout, c.stderr
def main(): parser = create_parser() args = parser.parse_args() context._add_argparse_args(args) if getattr(args, 'json', False): # # Silence logging info to avoid interfering with JSON output # for logger in Logger.manager.loggerDict: # if logger not in ('fetch', 'progress'): # getLogger(logger).setLevel(CRITICAL + 1) for logger in ('print', 'dotupdate', 'stdoutlog', 'stderrlog'): getLogger(logger).setLevel(CRITICAL + 1) return conda_exception_handler(args.func, args, parser)
def run_env_command(command, prefix, *arguments): """ Run conda env commands Args: command: The command, create, remove, export prefix: The prefix, for remove and create *arguments: The extra arguments """ p = create_parser() prefix = escape_for_winpath(prefix) if arguments: arguments = list(map(escape_for_winpath, arguments)) if command is Commands.ENV_EXPORT: command_line = "{0} -n {1} {2}".format(command, prefix, " ".join(arguments)) elif command is Commands.ENV_CREATE: # CREATE if prefix: command_line = "{0} -f {1} {2}".format(command, prefix, " ".join(arguments)) else: command_line = "{0} ".format(command) elif command is Commands.ENV_REMOVE: # REMOVE command_line = "{0} --yes -n {1} {2}".format(command, prefix, " ".join(arguments)) elif command is Commands.ENV_UPDATE: command_line = "{0} -n {1} {2}".format(command, prefix, " ".join(arguments)) else: command_line = " --help " args = p.parse_args(split(command_line)) context._add_argparse_args(args) with captured() as c: args.func(args, p) return c.stdout, c.stderr
def main(): parser = create_parser() args = parser.parse_args() context._add_argparse_args(args) return conda_exception_handler(args.func, args, parser)