def _args(): command_map = Dodo.get("/MENU/commands", {}) default_session_id = Dodo.get("/MENU/session_id", os.path.expandvars("$USER")) parser = ArgumentParser() parser.add_argument( "category", choices=["all"] + list([_normalize(x) for x in command_map.keys()]), nargs="?", ) parser.add_argument("--continue", dest="cont", action="store_true", help=SUPPRESS) parser.add_argument("--tmux", action="store_true") parser.add_argument("--list", action="store_true") parser.add_argument("--run", type=int, nargs="?", const=-1) parser.add_argument( "--id", dest="session_id", default=default_session_id, help="The tmux session id", ) args = Dodo.parse_args(parser) args.category = args.category or "all" args.run = -1 if args.run is None else args.run args.command_map = command_map return args
def _args(): parser = ArgumentParser(description="Run typescript compiler") parser.add_argument("src_dir_name") parser.add_argument("--watch", action="store_true") # Parse the arguments. args = Dodo.parse_args(parser, config_args=[]) args.src_dir_map = Dodo.get("/TSC/src_dir_map") args.out_dir = Dodo.get("/TSC/out_dir", None) args.node_modules_dir = Dodo.get("/NODE/node_modules_dir") return args
def _args(): Dodo.parser.add_argument("number", nargs="?") Dodo.parser.add_argument("--list", action="store_true") Dodo.parser.add_argument("--group", "-g", default="default") args = Dodo.parse_args() args.dirs = Dodo.get("/DIAL", {}) return args
def handle_next_to(args): command_dirs = get_command_dirs_from_config(Dodo.get()) command_map = get_command_map(command_dirs) if args.next_to: item = command_map.get(args.next_to) if not item: raise CommandError("Script not found: %s" % args.next_to) dest_path = os.path.join(os.path.dirname(item.filename), args.name + ".py") if os.path.exists(dest_path) and not args.force: raise CommandError("Destination already exists: %s" % dest_path) with open(dest_path, "w") as f: f.write( script_py.format(parser_args_str="", params_str="", description="", args_str="")) print(dest_path) else: print( script_py.format(parser_args_str="", params_str="", description="", args_str=""))
def modify_args(self, command_line_args, root_node, cwd): # noqa if not getattr(command_line_args, "use_debugger", False): return root_node, cwd debugger_node = ArgsTreeNode("debugger", args=[Dodo.get("/BUILD/debugger")]) debugger_node.add_child(root_node) return debugger_node, cwd
def _choices(): choices = [] for key in Dodo.get("/DOCKER_OPTIONS", {}).keys(): keys = [key] if isinstance(key, str) else key for x in keys: if x not in choices and not x.startswith("!"): choices.append(str(x)) return choices
def _args(): parser = ArgumentParser(description="Publish own npm packages") parser.add_argument("--login", action="store_true") # Add arguments to the parser here # Parse the arguments. args = Dodo.parse_args(parser, config_args=[]) args.cwd = Dodo.get("/ROOT/project_dir") args.npm_dir = "/npm" args.src_sub_dirs = Dodo.get("/TSC/src_dir_map").keys() # Raise an error if something is not right if False: raise CommandError("Oops") return args
def _args(): Dodo.parser.add_argument( "name", choices=Dodo.get("/DOCKER_IMAGES").keys(), help="Key to look up in /DOCKER_IMAGES", ) Dodo.parser.add_argument("build_args", help="Extra args to pass to docker build") args = Dodo.parse_args() args.build_dir = Dodo.get( "/DOCKER_IMAGES/{name}/build_dir".format(name=args.name), "." ) args.docker_file = Dodo.get( "/DOCKER_IMAGES/{name}/docker_file".format(name=args.name), "Dockerfile" ) args.extra_dirs = Dodo.get( "/DOCKER_IMAGES/{name}/extra_dirs".format(name=args.name), [] ) args.docker_image = Dodo.get("/DOCKER_IMAGES/{name}/image".format(name=args.name)) return args
def _args(): # Create the parser parser = ArgumentParser(description='') parser.add_argument('version') # Use the parser to create the command arguments args = Dodo.parse_args(parser, config_args=[]) args.cwd = Dodo.get('/ROOT/src_dir') return args
def _which_script(script): command_dirs = get_command_dirs_from_config(Dodo.get()) for item in command_dirs: script_path = os.path.join(item, script + ".py") if os.path.exists(script_path): return os.path.realpath(script_path) for item in command_dirs: for fn in glob.glob(os.path.join(item, "dodo.*.sh")): return os.path.realpath(fn) return None
def _args(): parser = ArgumentParser(description="") parser.add_argument("--url") # Parse the arguments. args = Dodo.parse_args(parser) args.file_browser = load_global_config_parser().get( "settings", "file_browser") args.browser = load_global_config_parser().get("settings", "browser") args.project_dir = Dodo.get("/ROOT/project_dir") return args
def _args(): # Create the parser parser = ArgumentParser(description="") parser.add_argument("--functions", action="store_true") # Use the parser to create the command arguments args = Dodo.parse_args(parser, config_args=[]) args.cwd = Dodo.get("/ROOT/project_dir") # Raise an error if something is not right if False: raise CommandError("Oops") return args
def _args(): parser = ArgumentParser(description=("Edit the dodo configuration files")) parser.add_argument( "--key", help="Only edit this key. Used in conjunction with --val") parser.add_argument( "--val", help="The value to be used in conjunction with the --key option") args = Dodo.parse_args(parser) if args.key or args.val: if not args.key and args.val: raise CommandError( "The options --key and --val should always be used together") args.editor = load_global_config_parser().get("settings", "config_editor") args.config_dir = Dodo.get("/ROOT/config_dir") return args
def _args(): parser = ArgumentParser( description="Opens a shell in the docker container.") parser.add_argument( "service", choices=_choices(), help=("Use this key to look up the docker options in /DOCKER_OPTIONS"), ) parser.add_argument( "--image", choices=Dodo.get("/DOCKER_IMAGES", {}).keys(), help=("Use the docker image stored under this key in /DOCKER_IMAGES"), ) parser.add_argument("--image-name", help=("Use the docker image with this name")) parser.add_argument( "--name", help=("Override the name of the started docker container")) parser.add_argument("--command") args = Dodo.parse_args(parser) return args
def _drop_dir_by_package_name(): drop_dir_by_package_name = {} command_dirs = get_command_dirs_from_config(Dodo.get()) for item in command_dirs: dot_drop_path = _dot_drop_path(item) default_drop_src_dir = _drop_src_dir(item) if not dot_drop_path and not default_drop_src_dir: continue if dot_drop_path and default_drop_src_dir: print("Warning: found two drop-ins where only one was expected:\n") print("%s\n%s" % (dot_drop_path, default_drop_src_dir)) package_name = os.path.basename(item) drop_src_dir = default_drop_src_dir or _read_dot_drop_path( dot_drop_path) _register_drop_dir(drop_dir_by_package_name, package_name, drop_src_dir) return drop_dir_by_package_name
def _args(): parser = ArgumentParser() parser.add_argument("src_dir", help="The src directory for the bootstrapped project") parser.add_argument( "shared_config_dir", help= "Location relative to src_dir where the shared project config is stored", ) parser.add_argument("--force", dest="use_force", action="store_true") group = parser.add_mutually_exclusive_group() group.add_argument( "--git-url", dest="git_url", help="Clone this repository to the src_dir location", ) group.add_argument( "--link-dir", help="Make the src directory a symlink to this directory", ) group.add_argument( "--cookiecutter-url", help="Use cookiecutter to create the src_dir location", ) parser.add_argument("--depth", type=int, default=0, help="Depth for cloning repositories") parser.add_argument("--branch", help="Branch to checkout after cloning") parser.add_argument( "--src-subdir", help="Specify a subdirectory of src_dir to clone into", ) args = Dodo.parse_args(parser) args.project_dir = Dodo.get("/ROOT/project_dir") return args
def _args(): Dodo.parser.description = "Run docker compose" Dodo.parser.add_argument("compose_args", nargs="?") group = Dodo.parser.add_mutually_exclusive_group() group.add_argument("--cat", action="store_true") group.add_argument("--edit", action="store_true") args = Dodo.parse_args() key = "DOCKER_COMPOSE" args.cwd = Dodo.get("/" + key + "/cwd") args.progress = Dodo.get("/" + key + "/progress", "plain") args.files = Dodo.get("/" + key + "/files", None) args.env_file = Dodo.get("/" + key + "/env_file", None) args.map = Dodo.get("/" + key + "/map", {}) args.editor = load_global_config_parser().get("settings", "editor") args.compose_project_name = Dodo.get( "/" + key + "/compose_project_name", Dodo.get("/ROOT/env_name") ) return args
args.env_file = Dodo.get("/" + key + "/env_file", None) args.map = Dodo.get("/" + key + "/map", {}) args.editor = load_global_config_parser().get("settings", "editor") args.compose_project_name = Dodo.get( "/" + key + "/compose_project_name", Dodo.get("/ROOT/env_name") ) return args # Use safe=False if the script makes changes other than through Dodo.run if Dodo.is_main(__name__, safe=True): args = _args() for src, dest in args.map.items(): with open(src) as ifs: content = expand_keys(Dodo.get(), ifs.read()) with open(dest, "w") as ofs: ofs.write(content) def get_file_args(): result = [] for f in args.files: result.extend(["--file", f]) return result file_args = get_file_args() if args.files else [] env_file_args = [f"--env-file={args.env_file}"] if args.env_file else [] compose_args = to_arg_list(args.compose_args) if "build" in compose_args[:1]: if "--progress" not in compose_args:
def _shared_config_dir(): src_dir = Dodo.get("/ROOT/src_dir", None) default_shared_config_dir = ( os.path.join(src_dir, "extra", "dodo_commands", "res") if src_dir else None ) return Dodo.get("/ROOT/shared_config_dir", default_shared_config_dir)
parser.add_argument("--image-name", help=("Use the docker image with this name")) parser.add_argument( "--name", help=("Override the name of the started docker container")) parser.add_argument("--command") args = Dodo.parse_args(parser) return args if Dodo.is_main(__name__): args = _args() docker_options = DockerDecorator.merged_options(Dodo.get, args.service) if args.image: docker_options["image"] = Dodo.get( "/DOCKER_IMAGES/%s/image" % args.image, args.image) elif args.image_name: docker_options["image"] = args.image_name if args.name: docker_options["name"] = args.name else: docker_options["name"] = args.service Dodo.get()["DOCKER_OPTIONS"] = {Dodo.command_name: docker_options} with DecoratorScope("docker"): Dodo.run( [args.command] if args.command else ["sh"], cwd=docker_options.get("cwd", "/"), )
def _args(): parser = ArgumentParser(description="") args = Dodo.parse_args(parser) args.cwd = os.path.join(Dodo.get("/ROOT/src_dir"), "frontend") args.cypress = "./cypress/node_modules/.bin/cypress" return args
if Dodo.is_main(__name__, safe=False): args = _args() config = ConfigIO().load() if args.layer == False: # noqa filtered_layers = _layers(config, filter_abs_paths=True) for layer in filtered_layers: name = _layer_name(layer) if name: value = _layer_value(filtered_layers, name) if value: print(name + ": " + _layer_value(filtered_layers, name)) sys.exit(0) layers = _layers(config) if args.value == False: # noqa print(_layer_value(layers, args.layer)) sys.exit(0) layer_file = os.path.join( Dodo.get("/ROOT/config_dir"), "%s.%s.yaml" % (args.layer, args.value) ) if not args.force and not os.path.exists(layer_file): raise CommandError("Layer file %s does not exist" % layer_file) config["LAYERS"] = _update_list_of_layers(layers, args.layer, args.value) ConfigIO().save(config)
report(Paths().default_commands_dir() + "\n") elif args.script: report(_which_script(args.script) + "\n") elif args.env_dir: report(Paths().env_dir() + "\n") elif args.project_dir: report(_which_dir("project") + "\n") elif args.config_dir: report(_which_dir("config") + "\n") elif args.python_env_dir: python_env_dir = os.path.realpath( os.path.join(Paths().env_dir(), "python_env_dir")) if os.path.exists(python_env_dir): report(python_env_dir + "\n") elif args.decorators: report(", ".join(sorted(_all_decorators(Dodo.get()).keys())) + "\n") elif args.envs: report("\n".join(sorted(os.listdir(Paths().envs_dir()))) + "\n") elif args.env: if Dodo.get("/ROOT/env_name", None): report(Dodo.get("/ROOT/env_name") + "\n") elif args.layers: layer_paths = Dodo.get_container().layers.get_ordered_layer_paths() for layer_path in layer_paths: report(layer_path + "\n") elif args.what: x = _which_script(args.what) or _which_dir(args.what) if x: report(x + "\n") elif args.fish_config: report(
def _which_dir(directory): return Dodo.get("/ROOT/%s_dir" % directory, None)
return drop_dir_by_package_name if Dodo.is_main(__name__, safe=True): args = _args() drop_src_dir = _drop_dir_by_package_name().get(args.package) if not drop_src_dir: raise CommandError("No drop-in found for package %s" % args.package) if not os.path.isdir(drop_src_dir): raise CommandError("The drop-in directory does not exist: %s" % drop_src_dir) config_dir = Dodo.get("/ROOT/config_dir") drops_target_dir = os.path.join(config_dir, "drops") if not os.path.exists(drops_target_dir): Dodo.run(["mkdir", drops_target_dir]) target_dir = os.path.join(drops_target_dir, args.package) if os.path.exists(target_dir): msg = "" msg += "Target directory already exists: %s\n" % target_dir msg += "\nThis probably means that %s has been already dropped into %s.\n" % ( args.package, config_dir, ) msg += "To update the drop-in manually, please run:\n\n" msg += "%s %s %s" % (_diff_tool(), drop_src_dir, target_dir) raise CommandError(msg)
raise CommandError("Container not found: %s" % args.find) elif not args.name: containers = _containers() print("0 - exit") for idx, container in enumerate(containers): print("%d - %s" % (idx + 1, container)) print("\nSelect a container: ") choice = int(raw_input()) - 1 if choice == -1: sys.exit(0) args.name = containers[choice] if not args.cmd: default_shell = Dodo.get("/DOCKER/default_shell", "sh") docker_options = DockerDecorator.merged_options( Dodo.get, "docker-exec") args.cmd = docker_options.get("shell", default_shell) Dodo.run([ "docker", "exec", "-i", "-t", ] + (["--user", args.user] if args.user else []) + [ args.name, *args.cmd.split(), ], )
from argparse import ArgumentParser from dodo_commands import Dodo from dodo_commands.framework.config import expand_keys def _args(): parser = ArgumentParser() parser.add_argument("text") args = Dodo.parse_args(parser) return args if Dodo.is_main(__name__): args = _args() print(expand_keys(Dodo.get(), args.text))
from argparse import ArgumentParser from dodo_commands import Dodo from dodo_commands.framework.global_config import load_global_config_parser def _args(): parser = ArgumentParser(description="") parser.add_argument("--url") # Parse the arguments. args = Dodo.parse_args(parser) args.file_browser = load_global_config_parser().get( "settings", "file_browser") args.browser = load_global_config_parser().get("settings", "browser") args.project_dir = Dodo.get("/ROOT/project_dir") return args # Use safe=False if the script makes changes other than through Dodo.run if Dodo.is_main(__name__, safe=True): args = _args() if args.url: url = Dodo.get("/URLS/" + args.url) Dodo.run([args.browser, url]) else: Dodo.run([args.file_browser, args.project_dir])
parser.add_argument("file", nargs="?", help="Show diff for this file") parser.add_argument( "--env-name", help="Compare to files from an alternative environment") args = Dodo.parse_args(parser) return args def _diff_tool(): return load_global_config_parser().get("settings", "diff_tool") if Dodo.is_main(__name__): args = _args() file = args.file or "." project_dir = Paths().project_dir() if not project_dir: raise CommandError("No active dodo commands project") if args.env_name: ref_project_dir = os.path.abspath( os.path.join(project_dir, "..", args.env_name)) original_file = os.path.join(ref_project_dir, file) copied_file = os.path.join(project_dir, file) else: shared_config_dir = Dodo.get("/ROOT/shared_config_dir") original_file = os.path.realpath(os.path.join(shared_config_dir, file)) copied_file = os.path.join(Paths().config_dir(), file) Dodo.run([_diff_tool(), original_file, copied_file])