def __init__(self, fn=None): super().__init__(self) self._yamld = {} if fn: print('Loading yaml...') self._yamld = pr.yamlToData(fName=fn)
def setYaml(self, yml, writeEach, modes, incGroups, excGroups): """ Set variable values from a yaml file modes is a list of variable modes to act on. writeEach is set to true if accessing a single variable at a time. Writes will be performed as each variable is updated. If set to false a bulk write will be performed after all of the variable updates are completed. Bulk writes provide better performance when updating a large quantity of variables. """ d = pr.yamlToData(yml) with self.pollBlock(), self.updateGroup(): self._setDictRoot(d=d, writeEach=writeEach, modes=modes, incGroups=incGroups, excGroups=excGroups) if not writeEach: self._write() if self.InitAfterConfig.value(): self.initialize()
def loadYaml(self, name, writeEach, modes, incGroups, excGroups): """Load YAML configuration from a file. Called from command""" # Pass arg is a python list if isinstance(name, list): rawlst = name # Passed arg is a comma separated list of files elif ',' in name: rawlst = name.split(',') # Not a list else: rawlst = [name] # Init final list lst = [] # Iterate through raw list and look for directories for rl in rawlst: # Name ends with .yml or .yaml if rl[-4:] == '.yml' or rl[-5:] == '.yaml': lst.append(rl) # Entry is a zip file directory elif '.zip' in rl: base = rl.split('.zip')[0] + '.zip' sub = rl.split('.zip')[1][1:] # Open zipfile with zipfile.ZipFile(base, 'r', compression=zipfile.ZIP_LZMA) as myzip: # Check if passed name is a directory, otherwise generate an error if not any( x.startswith("%s/" % sub.rstrip("/")) for x in myzip.namelist()): raise Exception( "loadYaml: Invalid load file: {}, must be a directory or end in .yml or .yaml" .format(rl)) else: # Iterate through directory contents for zfn in myzip.namelist(): # Filter by base directory if zfn.find(sub) == 0: spt = zfn.split('%s/' % sub.rstrip('/'))[1] # Entry ends in .yml or *.yml and is in current directory if '/' not in spt and (spt[-4:] == '.yml' or spt[-5:] == '.yaml'): lst.append(base + '/' + zfn) # Entry is a directory elif os.path.isdir(rl): dlst = glob.glob('{}/*.yml'.format(rl)) dlst.extend(glob.glob('{}/*.yaml'.format(rl))) lst.extend(sorted(dlst)) # Not a zipfile, not a directory and does not end in .yml else: raise Exception( "loadYaml: Invalid load file: {}, must be a directory or end in .yml or .yaml" .format(rl)) # Read each file with self.pollBlock(), self.updateGroup(): for fn in lst: d = pr.yamlToData(fName=fn) self._setDictRoot(d=d, writeEach=writeEach, modes=modes, incGroups=incGroups, excGroups=excGroups) if not writeEach: self._write() if self.InitAfterConfig.value(): self.initialize() return True
def yamlUpdate(old, new): dictUpdate(old, pr.yamlToData(new))
top.set( 'expert.DevPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer.PauseThreshold', 16, 'UINT32') top.set('expert.cfgyaml:RO', 'NoYaml', 'CHARSTR') return top if __name__ == "__main__": create = True dbname = 'configDB' #this is the name of the database running on the server. Only client care about this name. args = cdb.createArgs().args print(f"Load configuration from: {args.yaml}") data_from_yaml = pyrogue.yamlToData(fName=args.yaml) #print(f'keys {d}') db = 'configdb' if args.prod else 'devconfigdb' mycdb = cdb.configdb(f'https://pswww.slac.stanford.edu/ws-auth/{db}/ws/', args.inst, create, root=dbname, user=args.user, password=args.password) mycdb.add_alias(args.alias) mycdb.add_device_config('epix100') top = epix100_cdict(data_from_yaml=data_from_yaml) top.setInfo('epix100', args.name, args.segm, args.id, 'No comment')
# path+'ePixHr10kT_TriggerRegisters_100Hz.yml', ] fload = files['320MHz'] create = False dbname = 'configDB' #this is the name of the database running on the server. Only client care about this name. args = cdb.createArgs().args args.inst = 'asc' args.prod = False args.name = 'epixhr' args.segm = 0 args.user = '******' args.password = '******' db = 'configdb' if args.prod else 'devconfigdb' mycdb = cdb.configdb(f'https://pswww.slac.stanford.edu/ws-auth/{db}/ws/', args.inst, create, root=dbname, user=args.user, password=args.password) top = mycdb.get_configuration(args.alias, args.name + '_%d' % args.segm) base = 'ePixHr10kT' for fn in fload: d = pr.yamlToData(fName=fn) copyValues(d[base], top, 'expert') mycdb.modify_device(args.alias, top)