Settings dialog, per-program install defaults, Options after install; Update only when needed

This commit is contained in:
sarah committed 2026-10-07 21:47:15 +02:00
1 parent 7018d57dbc
commit 08c9071b48
8 files changed
+360 -30

No files matched your search

+29 -6
View File
@@ -3,14 +3,15 @@
SaraSuite list
SaraSuite install <Name> [--set Id=Value ...] [--option Id=on|off ...]
SaraSuite update <Name>
SaraSuite options <Name> [--option Id=on|off ...] (no --option: list them)
SaraSuite remove <Name> [--configs] [--keep-runtime]
Install uses each question's default and each option's default unless set.
Install starts from your defaults (Settings, or the manifest's) unless set.
"""
import argparse
from Installer import Apply, GetStatus, Remove
from Installer import Apply, DefaultAnswers, DefaultOptions, FetchCommit, GetStatus, Remove
from Manifests import LoadPrograms
@@ -24,6 +25,10 @@ def _Pairs(Items: list[str]) -> dict[str, str]:
return Pairs
def _Switches(Items: list[str]) -> dict[str, bool]:
return {Key: Value.lower() in ("on", "yes", "true", "1") for Key, Value in _Pairs(Items).items()}
def Run(Arguments: list[str]) -> int:
Parser = argparse.ArgumentParser(prog="SaraSuite")
Commands = Parser.add_subparsers(dest="Command", required=True)
@@ -33,6 +38,9 @@ def Run(Arguments: list[str]) -> int:
Install.add_argument("--set", action="append", default=[], dest="Answers")
Install.add_argument("--option", action="append", default=[], dest="Options")
Commands.add_parser("update").add_argument("Name")
OptionsCommand = Commands.add_parser("options")
OptionsCommand.add_argument("Name")
OptionsCommand.add_argument("--option", action="append", default=[], dest="Options")
RemoveCommand = Commands.add_parser("remove")
RemoveCommand.add_argument("Name")
RemoveCommand.add_argument("--configs", action="store_true")
@@ -51,20 +59,35 @@ def Run(Arguments: list[str]) -> int:
if Program is None:
print(f"Unknown program {Args.Name!r}. Known: {', '.join(P.Name for P in Programs.values())}")
return 1
Installed = GetStatus(Program).Installed
Current = GetStatus(Program)
Installed = Current.Installed
if Args.Command == "install":
if Installed:
print(f"{Program.Name} is already installed; use update.")
return 1
Options = {Option.Id: Option.Default for Option in Program.Options}
Options.update({Key: Value.lower() in ("on", "yes", "true", "1") for Key, Value in _Pairs(Args.Options).items()})
Apply(Program, print, Options, _Pairs(Args.Answers))
Options = DefaultOptions(Program)
Options.update(_Switches(Args.Options))
Answers = DefaultAnswers(Program)
Answers.update(_Pairs(Args.Answers))
Apply(Program, print, Options, Answers)
elif Args.Command == "update":
if not Installed:
print(f"{Program.Name} isn't installed.")
return 1
Apply(Program, print)
elif Args.Command == "options":
if not Installed:
print(f"{Program.Name} isn't installed.")
return 1
if not Args.Options:
for Option in Program.Options:
State = "on" if Current.Receipt.Options.get(Option.Id) else "off"
print(f"{Option.Id:20} {State:4} {Option.Label}")
return 0
Options = dict(Current.Receipt.Options)
Options.update(_Switches(Args.Options))
Apply(Program, print, Options, Source=FetchCommit(Program, Current.Receipt.Commit, print))
elif Args.Command == "remove":
Remove(Program, Args.configs, not Args.keep_runtime, print)
return 0