forked from M-Labs/artiq
1
0
Fork 0

master,client: support repository rescan

This commit is contained in:
Sebastien Bourdeauducq 2015-07-17 18:55:48 +02:00
parent 4907991ea3
commit 6b36d93cc2
3 changed files with 20 additions and 3 deletions

View File

@ -82,6 +82,9 @@ def get_argparser():
"what", "what",
help="select object to show: schedule/devices/parameters") help="select object to show: schedule/devices/parameters")
parser_scan_repository = subparsers.add_parser(
"scan-repository", help="rescan repository")
return parser return parser
@ -134,6 +137,10 @@ def _action_del_parameter(remote, args):
remote.delete(args.name) remote.delete(args.name)
def _action_scan_repository(remote, args):
remote.scan_async()
def _show_schedule(schedule): def _show_schedule(schedule):
clear_screen() clear_screen()
if schedule: if schedule:
@ -228,6 +235,7 @@ def main():
"del_device": "master_ddb", "del_device": "master_ddb",
"set_parameter": "master_pdb", "set_parameter": "master_pdb",
"del_parameter": "master_pdb", "del_parameter": "master_pdb",
"scan_repository": "master_repository"
}[action] }[action]
remote = Client(args.server, port, target_name) remote = Client(args.server, port, target_name)
try: try:

View File

@ -56,18 +56,19 @@ def main():
scheduler.start() scheduler.start()
atexit.register(lambda: loop.run_until_complete(scheduler.stop())) atexit.register(lambda: loop.run_until_complete(scheduler.stop()))
repository = Repository()
repository.scan_async()
server_control = Server({ server_control = Server({
"master_ddb": ddb, "master_ddb": ddb,
"master_pdb": pdb, "master_pdb": pdb,
"master_schedule": scheduler, "master_schedule": scheduler,
"master_repository": repository
}) })
loop.run_until_complete(server_control.start( loop.run_until_complete(server_control.start(
args.bind, args.port_control)) args.bind, args.port_control))
atexit.register(lambda: loop.run_until_complete(server_control.stop())) atexit.register(lambda: loop.run_until_complete(server_control.stop()))
repository = Repository()
loop.run_until_complete(repository.scan())
server_notify = Publisher({ server_notify = Publisher({
"schedule": scheduler.notifier, "schedule": scheduler.notifier,
"devices": ddb.data, "devices": ddb.data,

View File

@ -54,8 +54,16 @@ def _sync_explist(target, source):
class Repository: class Repository:
def __init__(self): def __init__(self):
self.explist = Notifier(dict()) self.explist = Notifier(dict())
self._scanning = False
@asyncio.coroutine @asyncio.coroutine
def scan(self): def scan(self):
if self._scanning:
return
self._scanning = True
new_explist = yield from _scan_experiments() new_explist = yield from _scan_experiments()
_sync_explist(self.explist, new_explist) _sync_explist(self.explist, new_explist)
self._scanning = False
def scan_async(self):
asyncio.async(self.scan())