Files
Das-OS/srcpkgs/das-shell/files/python/das_shell/cli.py
T
dasandClaude Opus 5.5 a2bffc7fe9
build / build (push) Successful in 38m26s
Terminal: Das prompt, dprompt and dbanner (0.9.1)
- das-shell 0.1.0: the Das two-line bash prompt by default (replaces the
  PS1 of Void's skel .bashrc once), dprompt (Textual prompt builder with
  presets and live preview) and dbanner (SSH login banner editor: canvas
  tools, fields with values, widgets, das-banner service for cached ones,
  Das OS logo and tryzub pictures). Python tests in make test.
- das-server 0.3.0 depends on das-shell; the server installer mentions
  dprompt and dbanner; the desktop image includes it.
- run-qemu.sh forwards the guest's SSH to localhost:2222.
- Hardware fixes: Ventoy menu icon, boot menu titles "Das OS <version>".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 09:17:10 +03:00

50 lines
1.3 KiB
Python

"""Shared bits of the dprompt and dbanner command lines."""
import os
import sys
from .i18n import t
def die(prog, uk, en, code=1):
print(f"{prog}: {t(uk, en)}", file=sys.stderr)
sys.exit(code)
def need_root(argv):
"""Runs the command again through sudo with the same arguments."""
if os.geteuid() == 0:
return
script = os.path.abspath(sys.argv[0])
try:
os.execvp("sudo", ["sudo", sys.executable, script] + argv)
except OSError as e:
print(f"sudo: {e}", file=sys.stderr)
sys.exit(1)
def resolve(spec):
"""A file argument as an absolute path (sudo starts elsewhere); names stay names."""
if os.sep in spec or spec.endswith(".json"):
return os.path.abspath(spec)
return spec
def run_tui(prog, loader):
try:
app = loader()
except ImportError as e:
die(prog, f"немає бібліотеки Textual ({e}); встановіть python3-textual",
f"the Textual library is missing ({e}); install python3-textual")
app.run()
return 0
def write_file(path, text, mode=0o644):
os.makedirs(os.path.dirname(path), exist_ok=True)
tmp = path + ".tmp"
with open(tmp, "w", encoding="utf-8") as f:
f.write(text)
os.chmod(tmp, mode)
os.replace(tmp, path)