From 6ee0912c79786afb2b34faee5e7119adb8066b24 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Thu, 26 Mar 2020 20:09:10 +0100 Subject: [PATCH] Add option to start autostarted apps and stop all apps --- usr/bin/spoc-app | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/usr/bin/spoc-app b/usr/bin/spoc-app index 6e32556..1642a94 100755 --- a/usr/bin/spoc-app +++ b/usr/bin/spoc-app @@ -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()