From 9a2e630fed3905bce9933fa26dda158c7dab754a Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Tue, 22 Jan 2019 00:00:00 +0000 Subject: [PATCH] docker: fix after args refactor --- run-docker | 33 +++++++++++++++++---------------- shell_helpers.py | 2 +- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/run-docker b/run-docker index b3411c9..b51136d 100755 --- a/run-docker +++ b/run-docker @@ -4,18 +4,19 @@ import argparse import os import common +import shell_helpers from shell_helpers import LF -container_name = kwargs['repo_short_id'] -container_hostname = kwargs['repo_short_id'] -image_name = kwargs['repo_short_id'] -target_dir = '/root/{}'.format(kwargs['repo_short_id']) +container_name = common.consts['repo_short_id'] +container_hostname = common.consts['repo_short_id'] +image_name = common.consts['repo_short_id'] +target_dir = '/root/{}'.format(common.consts['repo_short_id']) docker = ['sudo', 'docker'] def create(args): - self.sh.run_cmd(docker + ['build', '-t', image_name, '.', LF]) + sh.run_cmd(docker + ['build', '-t', image_name, '.', LF]) # --privileged for KVM: # https://stackoverflow.com/questions/48422001/launching-qemu-kvm-from-inside-docker-container - self.sh.run_cmd( + sh.run_cmd( docker + [ 'create', LF, @@ -32,34 +33,34 @@ def create(args): ) def destroy(args): stop(args) - self.sh.run_cmd(docker + ['rm', container_name, LF]) - self.sh.run_cmd(docker + ['rmi', image_name, LF]) -def sh(args): + sh.run_cmd(docker + ['rm', container_name, LF]) + sh.run_cmd(docker + ['rmi', image_name, LF]) +def sh_func(args): start(args) if args: sh_args = args else: sh_args = ['bash'] - self.sh.run_cmd( + sh.run_cmd( docker + ['exec', '-i', '-t', container_name] + sh_args + [LF], ) def start(args): - self.sh.run_cmd(docker + ['start', container_name, LF]) + sh.run_cmd(docker + ['start', container_name, LF]) def stop(args): - self.sh.run_cmd(docker + ['stop', container_name, LF]) + sh.run_cmd(docker + ['stop', container_name, LF]) cmd_action_map = { 'create': lambda args: create(args), 'DESTROY': lambda args: destroy(args), - 'sh': lambda args: sh(args), + 'sh': lambda args: sh_func(args), 'start': lambda args: start(args), 'stop': lambda args: stop(args), } parser = argparse.ArgumentParser() +parser.add_argument('--dry-run', default=False, action='store_true') parser.add_argument('cmd', choices=cmd_action_map) parser.add_argument('args', nargs='*') -self.add_dry_run_argument(parser) args = parser.parse_args() -self.setup_dry_run_arguments(args) -cmd_action_map[kwargs['cmd']](kwargs['args']) +sh = shell_helpers.ShellHelpers(dry_run=args.dry_run) +cmd_action_map[args.cmd](args.args) diff --git a/shell_helpers.py b/shell_helpers.py index 41cd2bc..9996d9b 100644 --- a/shell_helpers.py +++ b/shell_helpers.py @@ -36,7 +36,7 @@ class ShellHelpers: :param dry_run: don't run the commands, just potentially print them. Debug aid. :type dry_run: Bool - :param quiet: don't print the commands. + :param quiet: don't print the commands :type dry_run: Bool ''' self.dry_run = dry_run