DRY
This commit is contained in:
parent
7f59891a4e
commit
6a6680403f
1 changed files with 24 additions and 41 deletions
65
blend
65
blend
|
@ -83,6 +83,13 @@ def error(err):
|
||||||
print(colors.bold + colors.fg.red + '>> e: ' +
|
print(colors.bold + colors.fg.red + '>> e: ' +
|
||||||
colors.reset + colors.bold + err + colors.reset)
|
colors.reset + colors.bold + err + colors.reset)
|
||||||
|
|
||||||
|
|
||||||
|
def podman_it_remover(cmd: list):
|
||||||
|
'''
|
||||||
|
Removes `-it` from a podman command if stdout is not a tty
|
||||||
|
'''
|
||||||
|
return [x for x in cmd if x != '-it' or stdout.isatty()]
|
||||||
|
|
||||||
# END
|
# END
|
||||||
|
|
||||||
|
|
||||||
|
@ -239,21 +246,15 @@ def host_get_output(cmd): return subprocess.run(['bash', '-c', cmd],
|
||||||
|
|
||||||
|
|
||||||
def core_get_retcode(cmd):
|
def core_get_retcode(cmd):
|
||||||
# only use `-it` if stdout is a tty
|
podman_command = podman_it_remover(['podman', 'exec', '--user', getpass.getuser(), '-it',
|
||||||
cmd = ['podman', 'exec', '--user', getpass.getuser(), '-it',
|
args.container_name, 'bash', '-c', cmd])
|
||||||
args.container_name, 'bash', '-c', cmd]
|
return subprocess.run(podman_command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode
|
||||||
cmd = [x for x in cmd if x != '-it' or stdout.isatty()]
|
|
||||||
return subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode
|
|
||||||
|
|
||||||
|
|
||||||
def core_run_container(cmd):
|
def core_run_container(cmd):
|
||||||
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
||||||
# only use `-it` if stdout is a tty
|
subprocess.call(podman_it_remover(['podman', 'exec', '--user', getpass.getuser(),
|
||||||
cmd = ['podman', 'exec', '--user', getpass.getuser(),
|
'-w', os.getcwd(), '-it', args.container_name, 'bash', '-c', cmd]))
|
||||||
'-w', os.getcwd(), '-it', args.container_name, 'bash', '-c', cmd]
|
|
||||||
cmd = [x for x in cmd if x != '-it' or stdout.isatty()]
|
|
||||||
|
|
||||||
subprocess.call(cmd)
|
|
||||||
|
|
||||||
|
|
||||||
def core_install_pkg(pkg):
|
def core_install_pkg(pkg):
|
||||||
|
@ -432,46 +433,28 @@ def enter_container():
|
||||||
if not os.environ.get('BLEND_COMMAND'):
|
if not os.environ.get('BLEND_COMMAND'):
|
||||||
if args.pkg == []:
|
if args.pkg == []:
|
||||||
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
||||||
# only use `-it` if stdout is a tty
|
exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args,
|
||||||
cmd = [*sudo, 'podman', 'exec', *podman_args,
|
'-w', os.getcwd(), '-it', args.container_name, 'bash'])))
|
||||||
'-w', os.getcwd(), '-it', args.container_name, 'bash']
|
|
||||||
cmd = [x for x in cmd if x != '-it' or stdout.isatty()]
|
|
||||||
exit(subprocess.call(cmd))
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# only use `-it` if stdout is a tty
|
exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args, '-w',
|
||||||
cmd = [*sudo, 'podman', 'exec', *podman_args, '-w',
|
'/run/host' + os.getcwd(), '-it', args.container_name, 'bash'])))
|
||||||
'/run/host' + os.getcwd(), '-it', args.container_name, 'bash']
|
|
||||||
cmd = [x for x in cmd if x != '-it' or stdout.isatty()]
|
|
||||||
exit(subprocess.call(cmd))
|
|
||||||
else:
|
else:
|
||||||
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
||||||
# only use `-it` if stdout is a tty
|
exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args,
|
||||||
cmd = [*sudo, 'podman', 'exec', *podman_args,
|
'-w', os.getcwd(), '-it', args.container_name, *args.pkg])))
|
||||||
'-w', os.getcwd(), '-it', args.container_name, *args.pkg]
|
|
||||||
cmd = [x for x in cmd if x != '-it' or stdout.isatty()]
|
|
||||||
exit(subprocess.call(cmd))
|
|
||||||
else:
|
else:
|
||||||
# only use `-it` if stdout is a tty
|
exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args, '-w',
|
||||||
cmd = [*sudo, 'podman', 'exec', *podman_args, '-w',
|
'/run/host' + os.getcwd(), '-it', args.container_name, *args.pkg])))
|
||||||
'/run/host' + os.getcwd(), '-it', args.container_name, *args.pkg]
|
|
||||||
cmd = [x for x in cmd if x != '-it' or stdout.isatty()]
|
|
||||||
exit(subprocess.call(cmd))
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
||||||
# only use `-it` if stdout is a tty
|
exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args, '-w', os.getcwd(), '-it',
|
||||||
cmd = [*sudo, 'podman', 'exec', *podman_args, '-w', os.getcwd(), '-it',
|
args.container_name, 'bash', '-c', os.environ.get('BLEND_COMMAND')])))
|
||||||
args.container_name, 'bash', '-c', os.environ.get('BLEND_COMMAND')]
|
|
||||||
cmd = [x for x in cmd if x != '-it' or stdout.isatty()]
|
|
||||||
exit(subprocess.call(cmd))
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# only use `-it` if stdout is a tty
|
exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args, '-w',
|
||||||
cmd = [*sudo, 'podman', 'exec', *podman_args, '-w',
|
'/run/host' + os.getcwd(), '-it', args.container_name, 'bash'])))
|
||||||
'/run/host' + os.getcwd(), '-it', args.container_name, 'bash']
|
|
||||||
cmd = [x for x in cmd if x != '-it' or stdout.isatty()]
|
|
||||||
exit(subprocess.call(cmd))
|
|
||||||
|
|
||||||
|
|
||||||
def create_container():
|
def create_container():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue