forked from M-Labs/artiq
master: scan subdirectories in repos
This commit is contained in:
parent
96ddf73a8b
commit
d32c2c091f
|
@ -12,17 +12,14 @@ from artiq.tools import exc_to_warning
|
||||||
logger = logging.getLogger(__name__)
|
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()
|
r = dict()
|
||||||
for f in os.listdir(wd):
|
|
||||||
if f.endswith(".py"):
|
|
||||||
try:
|
|
||||||
worker = Worker({
|
worker = Worker({
|
||||||
"get_device_db": get_device_db,
|
"get_device_db": get_device_db,
|
||||||
"log": lambda message: log("scan", message)
|
"log": lambda message: log("scan", message)
|
||||||
})
|
})
|
||||||
try:
|
try:
|
||||||
description = await worker.examine(os.path.join(wd, f))
|
description = await worker.examine(os.path.join(root, filename))
|
||||||
finally:
|
finally:
|
||||||
await worker.close()
|
await worker.close()
|
||||||
for class_name, class_desc in description.items():
|
for class_name, class_desc in description.items():
|
||||||
|
@ -36,13 +33,34 @@ async def _scan_experiments(wd, get_device_db, log):
|
||||||
name = basename + str(i)
|
name = basename + str(i)
|
||||||
i += 1
|
i += 1
|
||||||
entry = {
|
entry = {
|
||||||
"file": f,
|
"file": filename,
|
||||||
"class_name": class_name,
|
"class_name": class_name,
|
||||||
"arguments": arguments
|
"arguments": arguments
|
||||||
}
|
}
|
||||||
r[name] = entry
|
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:
|
||||||
|
entries = await _get_repository_entries(
|
||||||
|
root, filename, get_device_db, log)
|
||||||
except:
|
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
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue