Files
VoiceStudio/scripts/freeze_cli.py
mostafa-ismail-2004 4708ae9a51 feat(cli): add the voicestudio terminal command
Add a terminal command that drives the desktop app's local backend.

- The desktop app owns the backend. When no backend answers, the CLI
  starts the installed app in the background (no window); it publishes
  its address in backend.json and quits after 10 idle minutes. Opening
  the app later shows a window in the same process, so a terminal
  session and the GUI never run two backends.
- The backend reports activity (requests, jobs, downloads, installs,
  calls) at /system/activity so idle shutdown never interrupts work, and
  holds a kernel lock on its data directory so a second backend fails
  fast with an actionable message.
- `voicestudio stop` stops a background app; commands that only report
  state never start it, and `status` exits 3 when it is not running.
- Output is readable tables and fields chosen from each result's shape;
  `--json` prints the raw data and piped output is tab-separated.
- Tab completion for bash, zsh, fish and PowerShell
  (`voicestudio completion <shell>`), without building the command tree.
- `voicestudio update` opens the app's updater; the CLI itself makes no
  network requests.
- Settings → General shows the terminal command and can add it to PATH
  on request; shell profiles are only edited with that consent.
2026-11-05 18:18:58 +02:00

34 lines
1.3 KiB
Python

"""Build the standalone CLI and carry interpreter/bootloader notices with it."""
from importlib import metadata
from pathlib import Path
import shutil
import sys
import sysconfig
from PyInstaller.__main__ import run
def main():
arguments = sys.argv[1:]
work = Path(arguments[arguments.index('--specpath') + 1])
notices = work / 'notices'
notices.mkdir()
candidates = [Path(sysconfig.get_path('stdlib')) / 'LICENSE.txt', Path(sys.base_prefix) / 'LICENSE.txt']
license_file = next((path for path in candidates if path.is_file()), None)
if license_file is None:
raise RuntimeError('Python runtime license is missing; refusing to bundle it without its notice.')
shutil.copy2(license_file, notices / 'Python-LICENSE.txt')
dist = metadata.distribution('pyinstaller')
license_files = [file for file in dist.files or [] if '.dist-info/licenses/' in str(file).replace('\\', '/')]
if not license_files:
raise RuntimeError('PyInstaller bootloader license is missing.')
for file in license_files:
target = notices / 'PyInstaller' / Path(str(file).split('licenses/', 1)[-1])
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(dist.locate_file(file), target)
run([*arguments, '--add-data', f'{notices}:licenses'])
if __name__ == '__main__':
main()