From d32c2c091fdb30fcd16b7f4b7ac8be8f44ae55ea Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 14 Nov 2015 00:06:52 +0800 Subject: [PATCH] master: scan subdirectories in repos --- artiq/master/repository.py | 74 ++++++++++++------- .../photon_histogram.py | 0 .../simple}/blink_forever.py | 0 .../simple}/dds_test.py | 0 .../simple}/handover.py | 0 .../simple}/mandelbrot.py | 0 .../{ => coredevice_examples}/tdr.py | 0 .../{ => coredevice_examples}/transport.py | 0 .../repository/{ => utilities}/dds_setter.py | 0 .../{ => utilities}/terminate_all.py | 0 10 files changed, 46 insertions(+), 28 deletions(-) rename examples/master/repository/{ => coredevice_examples}/photon_histogram.py (100%) rename examples/master/repository/{ => coredevice_examples/simple}/blink_forever.py (100%) rename examples/master/repository/{ => coredevice_examples/simple}/dds_test.py (100%) rename examples/master/repository/{ => coredevice_examples/simple}/handover.py (100%) rename examples/master/repository/{ => coredevice_examples/simple}/mandelbrot.py (100%) rename examples/master/repository/{ => coredevice_examples}/tdr.py (100%) rename examples/master/repository/{ => coredevice_examples}/transport.py (100%) rename examples/master/repository/{ => utilities}/dds_setter.py (100%) rename examples/master/repository/{ => utilities}/terminate_all.py (100%) diff --git a/artiq/master/repository.py b/artiq/master/repository.py index f060fee87..b784d1932 100644 --- a/artiq/master/repository.py +++ b/artiq/master/repository.py @@ -12,37 +12,55 @@ from artiq.tools import exc_to_warning logger = logging.getLogger(__name__) -async def _scan_experiments(wd, get_device_db, log): +async def _get_repository_entries(root, filename, get_device_db, log): r = dict() - for f in os.listdir(wd): - if f.endswith(".py"): + worker = Worker({ + "get_device_db": get_device_db, + "log": lambda message: log("scan", message) + }) + try: + description = await worker.examine(os.path.join(root, filename)) + finally: + await worker.close() + for class_name, class_desc in description.items(): + name = class_desc["name"] + arguments = class_desc["arguments"] + if name in r: + logger.warning("Duplicate experiment name: '%s'", name) + basename = name + i = 1 + while name in r: + name = basename + str(i) + i += 1 + entry = { + "file": filename, + "class_name": class_name, + "arguments": arguments + } + r[name] = entry + return r + + +async def _scan_experiments(root, get_device_db, log, subdir=""): + r = dict() + for de in os.scandir(os.path.join(root, subdir)): + if de.name.startswith("."): + continue + if de.is_file() and de.name.endswith(".py"): + filename = os.path.join(subdir, de.name) try: - worker = Worker({ - "get_device_db": get_device_db, - "log": lambda message: log("scan", message) - }) - try: - description = await worker.examine(os.path.join(wd, f)) - finally: - await worker.close() - for class_name, class_desc in description.items(): - name = class_desc["name"] - arguments = class_desc["arguments"] - if name in r: - logger.warning("Duplicate experiment name: '%s'", name) - basename = name - i = 1 - while name in r: - name = basename + str(i) - i += 1 - entry = { - "file": f, - "class_name": class_name, - "arguments": arguments - } - r[name] = entry + entries = await _get_repository_entries( + root, filename, get_device_db, log) except: - logger.warning("Skipping file '%s'", f, exc_info=True) + logger.warning("Skipping file '%s'", filename, exc_info=True) + else: + r.update(entries) + if de.is_dir(): + subentries = await _scan_experiments( + root, get_device_db, log, + os.path.join(subdir, de.name)) + entries = {de.name + "/" + k: v for k, v in subentries.items()} + r.update(entries) return r diff --git a/examples/master/repository/photon_histogram.py b/examples/master/repository/coredevice_examples/photon_histogram.py similarity index 100% rename from examples/master/repository/photon_histogram.py rename to examples/master/repository/coredevice_examples/photon_histogram.py diff --git a/examples/master/repository/blink_forever.py b/examples/master/repository/coredevice_examples/simple/blink_forever.py similarity index 100% rename from examples/master/repository/blink_forever.py rename to examples/master/repository/coredevice_examples/simple/blink_forever.py diff --git a/examples/master/repository/dds_test.py b/examples/master/repository/coredevice_examples/simple/dds_test.py similarity index 100% rename from examples/master/repository/dds_test.py rename to examples/master/repository/coredevice_examples/simple/dds_test.py diff --git a/examples/master/repository/handover.py b/examples/master/repository/coredevice_examples/simple/handover.py similarity index 100% rename from examples/master/repository/handover.py rename to examples/master/repository/coredevice_examples/simple/handover.py diff --git a/examples/master/repository/mandelbrot.py b/examples/master/repository/coredevice_examples/simple/mandelbrot.py similarity index 100% rename from examples/master/repository/mandelbrot.py rename to examples/master/repository/coredevice_examples/simple/mandelbrot.py diff --git a/examples/master/repository/tdr.py b/examples/master/repository/coredevice_examples/tdr.py similarity index 100% rename from examples/master/repository/tdr.py rename to examples/master/repository/coredevice_examples/tdr.py diff --git a/examples/master/repository/transport.py b/examples/master/repository/coredevice_examples/transport.py similarity index 100% rename from examples/master/repository/transport.py rename to examples/master/repository/coredevice_examples/transport.py diff --git a/examples/master/repository/dds_setter.py b/examples/master/repository/utilities/dds_setter.py similarity index 100% rename from examples/master/repository/dds_setter.py rename to examples/master/repository/utilities/dds_setter.py diff --git a/examples/master/repository/terminate_all.py b/examples/master/repository/utilities/terminate_all.py similarity index 100% rename from examples/master/repository/terminate_all.py rename to examples/master/repository/utilities/terminate_all.py