Skip to content

Commit 0b8da75

Browse files
committed
exit with final command's status code
1 parent a7b6fb8 commit 0b8da75

9 files changed

Lines changed: 20 additions & 16 deletions

File tree

userdocker/helpers/execute.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ def exec_cmd(cmd, dry_run=False, return_status=True, loglvl=logging.INFO):
3636
except subprocess.CalledProcessError as e:
3737
ret = e.returncode
3838
sys.exit(ret)
39+
40+
41+
def exit_exec_cmd(cmd, dry_run=False):
42+
sys.exit(exec_cmd(cmd, dry_run=dry_run))

userdocker/subcommands/attach.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from ..config import uid
77
from ..helpers.cmd import init_cmd
88
from ..helpers.exceptions import UserDockerException
9-
from ..helpers.execute import exec_cmd
9+
from ..helpers.execute import exit_exec_cmd
1010
from ..helpers.logger import logger
1111
from ..helpers.parser import init_subcommand_parser
1212

@@ -63,4 +63,4 @@ def exec_cmd_attach(args):
6363
'denied!' % (container, userdocker_uid, uid)
6464
)
6565

66-
exec_cmd(cmd, dry_run=args.dry_run)
66+
exit_exec_cmd(cmd, dry_run=args.dry_run)

userdocker/subcommands/dockviz.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
from ..helpers.execute import exec_cmd
3+
from ..helpers.execute import exit_exec_cmd
44

55

66
def exec_cmd_dockviz(args):
@@ -10,4 +10,4 @@ def exec_cmd_dockviz(args):
1010
"-v", "/var/run/docker.sock:/var/run/docker.sock",
1111
"nate/dockviz", "images", "--tree"
1212
]
13-
exec_cmd(cmd, dry_run=args.dry_run)
13+
exit_exec_cmd(cmd, dry_run=args.dry_run)

userdocker/subcommands/images.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
from ..helpers.cmd import init_cmd
4-
from ..helpers.execute import exec_cmd
4+
from ..helpers.execute import exit_exec_cmd
55
from ..helpers.parser import init_subcommand_parser
66

77

@@ -20,4 +20,4 @@ def exec_cmd_images(args):
2020
if args.repo_tag:
2121
cmd.append("--")
2222
cmd.append(args.repo_tag)
23-
exec_cmd(cmd, dry_run=args.dry_run)
23+
exit_exec_cmd(cmd, dry_run=args.dry_run)

userdocker/subcommands/ps.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from ..helpers.cmd import init_cmd
3-
from ..helpers.execute import exec_cmd
3+
from ..helpers.execute import exit_exec_cmd
44
from ..helpers.nvidia import nvidia_get_available_gpus
55
from ..helpers.nvidia import nvidia_get_gpus_used_by_containers
66
from ..helpers.parser import init_subcommand_parser
@@ -25,8 +25,7 @@ def parser_ps(parser):
2525

2626
def exec_cmd_ps(args):
2727
if not args.gpu_used and not args.gpu_free:
28-
exec_cmd(init_cmd(args), dry_run=args.dry_run)
29-
return
28+
exit_exec_cmd(init_cmd(args), dry_run=args.dry_run)
3029

3130
if args.gpu_used:
3231
gpus_used = nvidia_get_gpus_used_by_containers(args.executor_path)

userdocker/subcommands/pull.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
from ..helpers.cmd import init_cmd
4-
from ..helpers.execute import exec_cmd
4+
from ..helpers.execute import exit_exec_cmd
55
from ..helpers.parser import init_subcommand_parser
66

77

@@ -19,4 +19,4 @@ def exec_cmd_pull(args):
1919
if args.name_tag_digest:
2020
cmd.append("--")
2121
cmd.append(args.name_tag_digest)
22-
exec_cmd(cmd, dry_run=args.dry_run)
22+
exit_exec_cmd(cmd, dry_run=args.dry_run)

userdocker/subcommands/run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from ..helpers.cmd import init_cmd
2929
from ..helpers.exceptions import UserDockerException
3030
from ..helpers.execute import exec_cmd
31+
from ..helpers.execute import exit_exec_cmd
3132
from ..helpers.logger import logger
3233
from ..helpers.nvidia import nvidia_get_available_gpus
3334
from ..helpers.parser import init_subcommand_parser
@@ -286,4 +287,4 @@ def exec_cmd_run(args):
286287
cmd.append(img)
287288
cmd.extend(args.image_args)
288289

289-
exec_cmd(cmd, dry_run=args.dry_run)
290+
exit_exec_cmd(cmd, dry_run=args.dry_run)

userdocker/subcommands/version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from .. import __version__
44
from ..helpers.cmd import init_cmd
5-
from ..helpers.execute import exec_cmd
5+
from ..helpers.execute import exit_exec_cmd
66

77

88
def exec_cmd_version(args):
99
print("Userdocker Version: %s\n" % __version__)
10-
exec_cmd(init_cmd(args), dry_run=args.dry_run)
10+
exit_exec_cmd(init_cmd(args), dry_run=args.dry_run)

userdocker/userdocker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from .helpers.cmd import init_cmd
1111
from .helpers.exceptions import UserDockerException
12-
from .helpers.execute import exec_cmd
12+
from .helpers.execute import exit_exec_cmd
1313
from .parser import parse_args
1414
from .subcommands import specific_command_executors
1515

@@ -24,7 +24,7 @@ def prepare_and_exec_cmd(args):
2424
if scmd in specific_command_executors:
2525
specific_command_executors[scmd](args)
2626
else:
27-
exec_cmd(init_cmd(args), dry_run=args.dry_run)
27+
exit_exec_cmd(init_cmd(args), dry_run=args.dry_run)
2828

2929

3030
def parse_and_exec_cmd():

0 commit comments

Comments
 (0)