From e7a34a0ed47dc5fa19a40c1d95c0bc45c676280d Mon Sep 17 00:00:00 2001 From: Dmitry Gurovich Date: Sun, 31 Aug 2025 00:52:35 +0300 Subject: [PATCH 1/3] add watch option to test-spice tool --- test-spice | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/test-spice b/test-spice index e93103c0660..f5788a86976 100755 --- a/test-spice +++ b/test-spice @@ -6,6 +6,7 @@ import os import sys import shutil import subprocess +import time from pathlib import Path DEV_PREFIX = "devtest-" @@ -62,6 +63,26 @@ def reload_xlet(uuid): print(out.stderr.decode('ascii') + '\nReload error!') +def watch(uuid, action): + print('Watching for changes. Press Ctrl+C to stop.') + cmd = ["inotifywait", "--recursive", "--quiet", "--event", "modify", "--monitor", uuid] + last_run = 0 + try: + with subprocess.Popen(cmd, stdout=subprocess.PIPE, text=True) as proc: + for line in proc.stdout: + now = time.time() + if (now - last_run) > 1: + action(uuid) + last_run = now + except KeyboardInterrupt: + sys.exit(0) + + +def validate_and_copy(uuid): + if validate_spice(uuid): + copy_xlet(uuid) + + def main(): """ Simpler testing of Spices for developers @@ -72,9 +93,12 @@ def main(): help='Remove all test Spices') parser.add_argument('-s', '--skip', action='store_true', help='Skip Spice validation with validate-spice') + parser.add_argument('-w', '--watch', action='store_true', + help='Watch for changes in the spice directory and reload the applet') parser.add_argument('uuid', type=str, metavar='UUID', nargs='?', help='the UUID of the Spice') args = parser.parse_args() + uuid = args.uuid.rstrip('/') if args.uuid else None if args.remove and not args.uuid: for file_path in os.listdir(APPLETS_PATH): @@ -84,10 +108,13 @@ def main(): shutil.rmtree(rm_path) sys.exit(0) elif args.skip and args.uuid: - copy_xlet(args.uuid.rstrip('/')) + copy_xlet(uuid) elif args.uuid and not args.remove: - if validate_spice(args.uuid.rstrip('/')): - copy_xlet(args.uuid.rstrip('/')) + if args.watch: + validate_and_copy(uuid) + watch(uuid, validate_and_copy) + else: + validate_and_copy(uuid) else: parser.print_help() sys.exit(2) From fa686797f352471a5eb2bc8e047e1c01b1db0555 Mon Sep 17 00:00:00 2001 From: Dmitry Gurovich Date: Sun, 31 Aug 2025 01:07:01 +0300 Subject: [PATCH 2/3] error handling --- test-spice | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test-spice b/test-spice index f5788a86976..6502259f602 100755 --- a/test-spice +++ b/test-spice @@ -64,16 +64,19 @@ def reload_xlet(uuid): def watch(uuid, action): - print('Watching for changes. Press Ctrl+C to stop.') cmd = ["inotifywait", "--recursive", "--quiet", "--event", "modify", "--monitor", uuid] last_run = 0 try: with subprocess.Popen(cmd, stdout=subprocess.PIPE, text=True) as proc: + print('Watching for changes. Press Ctrl+C to stop.') for line in proc.stdout: now = time.time() if (now - last_run) > 1: action(uuid) last_run = now + except FileNotFoundError: + print('Failed to start watcher. Make sure inotify-tools package is installed.') + sys.exit(3) except KeyboardInterrupt: sys.exit(0) @@ -81,6 +84,9 @@ def watch(uuid, action): def validate_and_copy(uuid): if validate_spice(uuid): copy_xlet(uuid) + return True + else: + return False def main(): @@ -111,8 +117,8 @@ def main(): copy_xlet(uuid) elif args.uuid and not args.remove: if args.watch: - validate_and_copy(uuid) - watch(uuid, validate_and_copy) + if validate_and_copy(uuid): + watch(uuid, validate_and_copy) else: validate_and_copy(uuid) else: From 8bcfc166c136971ee33c1603486f53338bc28339 Mon Sep 17 00:00:00 2001 From: Dmitry Gurovich Date: Sun, 31 Aug 2025 01:14:18 +0300 Subject: [PATCH 3/3] rephrase switch help text --- test-spice | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-spice b/test-spice index 6502259f602..92530cff429 100755 --- a/test-spice +++ b/test-spice @@ -100,7 +100,7 @@ def main(): parser.add_argument('-s', '--skip', action='store_true', help='Skip Spice validation with validate-spice') parser.add_argument('-w', '--watch', action='store_true', - help='Watch for changes in the spice directory and reload the applet') + help='Watch the Spice directory for changes and update the applet with reload') parser.add_argument('uuid', type=str, metavar='UUID', nargs='?', help='the UUID of the Spice') args = parser.parse_args()