'ssh_agent_image_name', help= 'The name of the docker image that contains the ssh-agent tool' ), ConfigArg( '/SSH_AGENT/key_names', 'ssh_agent_key_name', nargs='+', help= 'The names of the public keys that should be added to the ssh-agent container' ), ]) return args if Dodo.is_main(__name__): args = _args() for i in range(2): try: # Find agent container id try: container_id = (docker['ps', '-a'] | grep['ssh-agent'] | awk['{print $1}'])()[:-1] except: container_id = None # Stop command if args.command in ('stop', 'restart') and container_id: Dodo.run([ 'docker', 'run', '--rm', '--volumes-from=ssh-agent', '-it',
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="")) if Dodo.is_main(__name__, safe=False): args = _args() handle_next_to(args)
from dodo_commands import Dodo def _args(): parser = ArgumentParser() parser.add_argument("where") parser.add_argument("what") parser.add_argument("--pattern", default="*") parser.add_argument("--replace") args = Dodo.parse_args(parser) return args def _replace(where, what, replace_with): for filepath in glob.iglob(os.path.join(where, "**/" + args.pattern), recursive=True): with open(filepath) as file: s = file.read() s2 = s.replace(what, replace_with) if s != s2: with open(filepath, "w") as file: file.write(s2) args = _args() if Dodo.is_main(__name__, safe=not args.replace): if args.replace: _replace(args.where, args.what, args.replace) else: Dodo.run(["grep", "-rnw", args.where, "-e", "'{}'".format(args.what)])
Dodo.parser.add_argument("--cat", action="store_true") Dodo.parser.add_argument("--edit", action="store_true") args = Dodo.parse_args() args.cwd = Dodo.get_config("/MAKE/cwd") args.file = Dodo.get_config("/MAKE/file", "Makefile") global_config = load_global_config_parser() args.editor = global_config_get(global_config, "settings", "editor") # Raise an error if something is not right if False: raise CommandError("Oops") 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.cat: Dodo.run(["cat", args.file], cwd=args.cwd) elif args.edit: with DecoratorScope("docker", remove=True): Dodo.run([args.editor, args.file], cwd=invert_path(args.cwd)) else: file_args = ["-f", args.file] if args.file != "Makefile" else [] Dodo.run(["make", *file_args, *to_arg_list(args.make_args)], cwd=args.cwd)
"--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 if Dodo.is_main(__name__, safe=("--key" not in sys.argv)): try: args = _args() except configparser.NoOptionError as e: raise CommandError("{error}. Please check {filename}".format( error=str(e), filename=Paths().global_config_filename())) config = ConfigIO().load() if args.key and args.val: key = Key(config, args.key) key.set(args.val) ConfigIO().save(config) sys.exit(0) def add_global_config_filename(layer_paths):