Add option to start autostarted apps and stop all apps

This commit is contained in:
Disassembler 2020-03-26 20:09:10 +01:00
parent cdb9768086
commit 6ee0912c79
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499

View File

@ -73,10 +73,20 @@ def publish(filename, force):
def unpublish(app_name):
App(app_name, False, False).unpublish()
def autostart(value):
def autostart(app_name, value):
value = value.lower() in ('1', 'on', 'enable', 'true')
App(app_name, False).set_autostart(value)
def start_autostarted():
apps = [App(a) for a,d in repo_local.get_apps() if d['autostart']]
for app in apps:
app.start()
def stop_all():
apps = [App(a) for a,d in repo_local.get_apps()]
for app in apps:
app.stop()
parser = argparse.ArgumentParser(description='SPOC application manager')
parser.set_defaults(action=None)
subparsers = parser.add_subparsers()
@ -120,8 +130,15 @@ parser_unpublish.add_argument('app')
parser_autostart = subparsers.add_parser('autostart')
parser_autostart.set_defaults(action=autostart)
parser_autostart.add_argument('app')
parser_autostart.add_argument('value', choices=('1', 'on', 'enable', 'true', '0', 'off', 'disable', 'false'), help='Sets the applications to be automatically started after the host boots up')
parser_start_autostarted = subparsers.add_parser('start-autostarted')
parser_start_autostarted.set_defaults(action=start_autostarted)
parser_stop_all = subparsers.add_parser('stop-all')
parser_stop_all.set_defaults(action=stop_all)
args = parser.parse_args()
if args.action is listing:
@ -143,6 +160,10 @@ elif args.action is publish:
elif args.action is unpublish:
unpublish(args.app)
elif args.action is autostart:
autostart(args.value)
autostart(args.app, args.value)
elif args.action is start_autostarted:
start_autostarted()
elif args.action is stop_all:
stop_all()
else:
parser.print_usage()