forked from M-Labs/artiq
1
0
Fork 0

master/repository: fix experiment name conflict handling

This commit is contained in:
Sebastien Bourdeauducq 2015-11-16 22:46:40 +08:00
parent d32c2c091f
commit 723ef71a87
1 changed files with 14 additions and 13 deletions

View File

@ -12,8 +12,8 @@ from artiq.tools import exc_to_warning
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
async def _get_repository_entries(root, filename, get_device_db, log): async def _get_repository_entries(entry_dict,
r = dict() root, filename, get_device_db, log):
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)
@ -25,11 +25,15 @@ async def _get_repository_entries(root, filename, get_device_db, log):
for class_name, class_desc in description.items(): for class_name, class_desc in description.items():
name = class_desc["name"] name = class_desc["name"]
arguments = class_desc["arguments"] arguments = class_desc["arguments"]
if name in r: if "/" in name:
logger.warning("Character '/' is not allowed in experiment "
"name (%s)", name)
name = name.replace("/", "_")
if name in entry_dict:
logger.warning("Duplicate experiment name: '%s'", name) logger.warning("Duplicate experiment name: '%s'", name)
basename = name basename = name
i = 1 i = 1
while name in r: while name in entry_dict:
name = basename + str(i) name = basename + str(i)
i += 1 i += 1
entry = { entry = {
@ -37,31 +41,28 @@ async def _get_repository_entries(root, filename, get_device_db, log):
"class_name": class_name, "class_name": class_name,
"arguments": arguments "arguments": arguments
} }
r[name] = entry entry_dict[name] = entry
return r
async def _scan_experiments(root, get_device_db, log, subdir=""): async def _scan_experiments(root, get_device_db, log, subdir=""):
r = dict() entry_dict = dict()
for de in os.scandir(os.path.join(root, subdir)): for de in os.scandir(os.path.join(root, subdir)):
if de.name.startswith("."): if de.name.startswith("."):
continue continue
if de.is_file() and de.name.endswith(".py"): if de.is_file() and de.name.endswith(".py"):
filename = os.path.join(subdir, de.name) filename = os.path.join(subdir, de.name)
try: try:
entries = await _get_repository_entries( await _get_repository_entries(
root, filename, get_device_db, log) entry_dict, root, filename, get_device_db, log)
except: except:
logger.warning("Skipping file '%s'", filename, exc_info=True) logger.warning("Skipping file '%s'", filename, exc_info=True)
else:
r.update(entries)
if de.is_dir(): if de.is_dir():
subentries = await _scan_experiments( subentries = await _scan_experiments(
root, get_device_db, log, root, get_device_db, log,
os.path.join(subdir, de.name)) os.path.join(subdir, de.name))
entries = {de.name + "/" + k: v for k, v in subentries.items()} entries = {de.name + "/" + k: v for k, v in subentries.items()}
r.update(entries) entry_dict.update(entries)
return r return entry_dict
def _sync_explist(target, source): def _sync_explist(target, source):