bit of code cleanup, format

This commit is contained in:
askiiart 2025-04-08 21:18:14 -05:00
parent 4732a5735d
commit e4d2ca043c
Signed by untrusted user who does not match committer: askiiart
GPG key ID: 6A32977DAF31746A
2 changed files with 20 additions and 13 deletions

10
blend
View file

@ -129,7 +129,7 @@ def check_container(name):
def check_container_status(name): def check_container_status(name):
if os.environ.get('SUDO_USER') == None: if os.environ.get('SUDO_USER'):
return host_get_output("podman inspect --type container " + name + " --format \"{{.State.Status}}\"") return host_get_output("podman inspect --type container " + name + " --format \"{{.State.Status}}\"")
else: else:
return host_get_output(f"sudo -u {os.environ.get('SUDO_USER')} podman inspect --type container " + name + " --format \"{{.State.Status}}\"") return host_get_output(f"sudo -u {os.environ.get('SUDO_USER')} podman inspect --type container " + name + " --format \"{{.State.Status}}\"")
@ -137,7 +137,7 @@ def check_container_status(name):
def core_start_container(name, new_container=False): def core_start_container(name, new_container=False):
sudo = [] sudo = []
if os.environ.get('SUDO_USER') != None: if os.environ.get('SUDO_USER'):
sudo = ['sudo', '-u', os.environ.get('SUDO_USER')] sudo = ['sudo', '-u', os.environ.get('SUDO_USER')]
subprocess.call([*sudo, 'podman', 'start', name], subprocess.call([*sudo, 'podman', 'start', name],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
@ -150,7 +150,7 @@ def core_start_container(name, new_container=False):
subprocess.call(['podman', 'logs', '--since', str(start_time), name]) subprocess.call(['podman', 'logs', '--since', str(start_time), name])
exit(1) exit(1)
if os.environ.get('SUDO_USER') == None: if not os.environ.get('SUDO_USER'):
logproc = pexpect.spawn( logproc = pexpect.spawn(
'podman', args=['logs', '-f', '--since', str(start_time), name], timeout=3600) 'podman', args=['logs', '-f', '--since', str(start_time), name], timeout=3600)
else: else:
@ -411,7 +411,7 @@ def enter_container():
podman_args = ['--env', 'LC_ALL=C.UTF-8'] podman_args = ['--env', 'LC_ALL=C.UTF-8']
sudo = [] sudo = []
if os.environ.get('SUDO_USER') == None: if not os.environ.get('SUDO_USER'):
podman_args = ['--user', getpass.getuser()] podman_args = ['--user', getpass.getuser()]
else: else:
sudo = ['sudo', '-u', os.environ.get( sudo = ['sudo', '-u', os.environ.get(
@ -420,7 +420,7 @@ def enter_container():
if name not in ['LANG', 'LC_CTYPE', 'LC_ALL', 'PATH', 'HOST', 'HOSTNAME', 'SHELL'] and not name.startswith('_'): if name not in ['LANG', 'LC_CTYPE', 'LC_ALL', 'PATH', 'HOST', 'HOSTNAME', 'SHELL'] and not name.startswith('_'):
podman_args.append('--env') podman_args.append('--env')
podman_args.append(name + '=' + val) podman_args.append(name + '=' + val)
if os.environ.get('BLEND_COMMAND') == None or 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('~') + '/'):
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args,

23
user
View file

@ -162,7 +162,8 @@ def create_container(container_name, distro):
Create a container Create a container
''' '''
if subprocess.run(['podman', 'container', 'exists', container_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0: if subprocess.run(['podman', 'container', 'exists', container_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0:
error(f'container {colors.bold}{container_name}{colors.reset} already exists') error(
f'container {colors.bold}{container_name}{colors.reset} already exists')
exit(1) exit(1)
args = ['blend', 'create-container', '-cn', container_name] args = ['blend', 'create-container', '-cn', container_name]
# blend handles no distro being specified already # blend handles no distro being specified already
@ -178,7 +179,8 @@ def delete_container(container):
Delete a container Delete a container
''' '''
if subprocess.run(['podman', 'container', 'exists', container], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode != 0: if subprocess.run(['podman', 'container', 'exists', container], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode != 0:
error(f'container {colors.bold}{container}{colors.reset} does not exist') error(
f'container {colors.bold}{container}{colors.reset} does not exist')
exit(1) exit(1)
subprocess.run(['blend', 'remove-container', container]) subprocess.run(['blend', 'remove-container', container])
@ -190,7 +192,8 @@ def shell(container):
Enter a shell inside a container Enter a shell inside a container
''' '''
if subprocess.run(['podman', 'container', 'exists', container], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode != 0: if subprocess.run(['podman', 'container', 'exists', container], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode != 0:
error(f'container {colors.bold}{container}{colors.reset} does not exist') error(
f'container {colors.bold}{container}{colors.reset} does not exist')
exit(1) exit(1)
creation_env = os.environ.copy() creation_env = os.environ.copy()
creation_env['BLEND_NO_CHECK'] = 'true' creation_env['BLEND_NO_CHECK'] = 'true'
@ -205,12 +208,14 @@ def exec_c(container, cmds):
Run a command inside a container Run a command inside a container
''' '''
if subprocess.run(['podman', 'container', 'exists', container], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode != 0: if subprocess.run(['podman', 'container', 'exists', container], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode != 0:
error(f'container {colors.bold}{container}{colors.reset} does not exist') error(
f'container {colors.bold}{container}{colors.reset} does not exist')
exit(1) exit(1)
creation_env = os.environ.copy() creation_env = os.environ.copy()
creation_env['BLEND_NO_CHECK'] = 'true' creation_env['BLEND_NO_CHECK'] = 'true'
cmds = [ cmd.replace('\\-', '-') for cmd in cmds] cmds = [cmd.replace('\\-', '-') for cmd in cmds]
subprocess.run(['blend', 'enter', '-cn', container, '--', *cmds], env=creation_env) subprocess.run(['blend', 'enter', '-cn', container,
'--', *cmds], env=creation_env)
@cli.command("install") @cli.command("install")
@ -228,7 +233,8 @@ def install_c(container, pkgs):
elif os.path.isfile(os.path.expanduser(f'~/.local/bin/blend_bin/pacman.{container}')): elif os.path.isfile(os.path.expanduser(f'~/.local/bin/blend_bin/pacman.{container}')):
subprocess.run([f'sudo.{container}', 'pacman', '-Syu', *pkgs]) subprocess.run([f'sudo.{container}', 'pacman', '-Syu', *pkgs])
else: else:
error(f'container {colors.bold}{container}{colors.reset} does not exist') error(
f'container {colors.bold}{container}{colors.reset} does not exist')
exit(1) exit(1)
@ -246,7 +252,8 @@ def remove_c(container, pkgs):
elif os.path.isfile(os.path.expanduser(f'~/.local/bin/blend_bin/pacman.{container}')): elif os.path.isfile(os.path.expanduser(f'~/.local/bin/blend_bin/pacman.{container}')):
subprocess.run([f'sudo.{container}', 'pacman', '-Rcns', *pkgs]) subprocess.run([f'sudo.{container}', 'pacman', '-Rcns', *pkgs])
else: else:
error(f'container {colors.bold}{container}{colors.reset} does not exist') error(
f'container {colors.bold}{container}{colors.reset} does not exist')
exit(1) exit(1)