mirror of https://github.com/m-labs/artiq.git
master: support DDB rescan
This commit is contained in:
parent
50a5a3baf0
commit
0e3927b01a
|
@ -61,16 +61,6 @@ def get_argparser():
|
|||
parser_delete.add_argument("rid", type=int,
|
||||
help="run identifier (RID)")
|
||||
|
||||
parser_set_device = subparsers.add_parser(
|
||||
"set-device", help="add or modify a device")
|
||||
parser_set_device.add_argument("name", help="name of the device")
|
||||
parser_set_device.add_argument("description",
|
||||
help="description in PYON format")
|
||||
|
||||
parser_del_device = subparsers.add_parser(
|
||||
"del-device", help="delete a device")
|
||||
parser_del_device.add_argument("name", help="name of the device")
|
||||
|
||||
parser_set_parameter = subparsers.add_parser(
|
||||
"set-parameter", help="add or modify a parameter")
|
||||
parser_set_parameter.add_argument("name", help="name of the parameter")
|
||||
|
@ -87,9 +77,12 @@ def get_argparser():
|
|||
"what",
|
||||
help="select object to show: schedule/log/devices/parameters")
|
||||
|
||||
parser_scan = subparsers.add_parser("scan-repository",
|
||||
help="trigger a repository (re)scan")
|
||||
parser_scan.add_argument("revision", default=None, nargs="?",
|
||||
subparsers.add_parser(
|
||||
"scan-ddb", help="trigger a device database (re)scan")
|
||||
|
||||
parser_scan_repos = subparsers.add_parser(
|
||||
"scan-repository", help="trigger a repository (re)scan")
|
||||
parser_scan_repos.add_argument("revision", default=None, nargs="?",
|
||||
help="use a specific repository revision "
|
||||
"(defaults to head)")
|
||||
|
||||
|
@ -131,14 +124,6 @@ def _action_delete(remote, args):
|
|||
remote.delete(args.rid)
|
||||
|
||||
|
||||
def _action_set_device(remote, args):
|
||||
remote.set(args.name, pyon.decode(args.description))
|
||||
|
||||
|
||||
def _action_del_device(remote, args):
|
||||
remote.delete(args.name)
|
||||
|
||||
|
||||
def _action_set_parameter(remote, args):
|
||||
remote.set(args.name, pyon.decode(args.value))
|
||||
|
||||
|
@ -147,6 +132,10 @@ def _action_del_parameter(remote, args):
|
|||
remote.delete(args.name)
|
||||
|
||||
|
||||
def _action_scan_ddb(remote, args):
|
||||
remote.scan()
|
||||
|
||||
|
||||
def _action_scan_repository(remote, args):
|
||||
remote.scan_async(args.revision)
|
||||
|
||||
|
@ -275,10 +264,9 @@ def main():
|
|||
target_name = {
|
||||
"submit": "master_schedule",
|
||||
"delete": "master_schedule",
|
||||
"set_device": "master_ddb",
|
||||
"del_device": "master_ddb",
|
||||
"set_parameter": "master_pdb",
|
||||
"del_parameter": "master_pdb",
|
||||
"scan_ddb": "master_ddb",
|
||||
"scan_repository": "master_repository"
|
||||
}[action]
|
||||
remote = Client(args.server, port, target_name)
|
||||
|
|
|
@ -7,6 +7,7 @@ import os
|
|||
|
||||
from artiq.protocols.pc_rpc import Server
|
||||
from artiq.protocols.sync_struct import Notifier, Publisher, process_mod
|
||||
from artiq.master.ddb import DDB
|
||||
from artiq.protocols.file_db import FlatFileDB
|
||||
from artiq.master.scheduler import Scheduler
|
||||
from artiq.master.worker_db import get_last_rid
|
||||
|
@ -64,7 +65,7 @@ def main():
|
|||
loop = asyncio.get_event_loop()
|
||||
atexit.register(lambda: loop.close())
|
||||
|
||||
ddb = FlatFileDB(args.ddb)
|
||||
ddb = DDB(args.ddb)
|
||||
pdb = FlatFileDB(args.pdb)
|
||||
rtr = Notifier(dict())
|
||||
log = Log(1000)
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
from artiq.protocols.sync_struct import Notifier
|
||||
from artiq.protocols import pyon
|
||||
|
||||
|
||||
class DDB:
|
||||
def __init__(self, backing_file):
|
||||
self.backing_file = backing_file
|
||||
self.data = Notifier(pyon.load_file(self.backing_file))
|
||||
|
||||
def scan(self):
|
||||
new_data = pyon.load_file(self.backing_file)
|
||||
|
||||
for k in list(self.data.read.keys()):
|
||||
if k not in new_data:
|
||||
del self.data[k]
|
||||
for k in new_data.keys():
|
||||
if k not in self.data.read or self.data.read[k] != new_data[k]:
|
||||
self.data[k] = new_data[k]
|
||||
|
||||
def get(self, key):
|
||||
return self.data.read[key]
|
Loading…
Reference in New Issue