def list_files(self, mask, files=None): if not files: if '/' in mask: folder, mask = mask.rsplit('/', 1) else: folder, mask = '', mask #if self.SaveFolder and not folder.startswith('/'): folder = self.SaveFolder + '/' + folder #SAFER TO FORCE ALWAYS PATH return fn.listdir(folder, mask) else: #using cache return [f for f in files if fn.clmatch(mask, f)]
def merge_csv_attrs(exported = True, currents = True, check_dups = True): """ OJU! Correctors are not exported but should be archived anyway! """ folder = fn.tango.get_free_property('PyTangoArchiving','CSVFolder') csvs = [f for f in fn.listdir(folder) if f.endswith('csv')] print('Parsing %d files from %s' % (len(csvs),folder)) archattrs = fn.defaultdict(dict) alldevs = fn.tango.get_all_devices(exported = exported) sources = dict() for f in csvs: try: sources[f] = pta.ParseCSV(folder+f) except Exception,e: print('%s failed: %s\n'%(f,e))
def create_simulators(filein, instance='', path='', domains={}, server='', tango_host='', filters='', override=True): #domains = {'wr/rf':'test/rf'} path = path or os.path.abspath(os.path.dirname(filein)) + '/' print('create_simulators:' + str( (filein, instance, path, domains, tango_host))) files = fd.listdir(path) if not any(f.endswith('_attributes.txt') for f in files): q = raw_input('Property files do not exist yet,\n' 'Do you want to generate them? (y/n)') if q.lower().startswith('y'): cur = os.path.abspath(os.curdir) os.chdir(path) generate_class_properties(filein) os.chdir(cur) ## CHECK IS MANDATORY, YOU SHOULD EXPORT AND SIMULATE IN DIFFERENT HOSTS assert tango_host and tango_host in str(fd.tango.get_tango_host()),\ 'Tango Host (%s!=%s) does not match!'%(tango_host,fd.tango.get_tango_host()) devs, org = {}, pickle.load( open(filein if '/' in filein else path + filein)) done = [] all_devs = fd.get_all_devices() print('>' * 80) if not filters: print('%d devices in %s: %s' % (len(org), filein, sorted(org.keys()))) filters = raw_input('Enter a filter for device names: [*/*/*]').lower() for d, t in org.items(): k = ('/'.join( d.split('/')[-3:])).lower() #Removing tango host from the name for a, b in domains.items(): if k.startswith(a): k = k.replace(a, b) if not filters or fd.matchCl(filters, d) or fd.matchCl( filters, org[d].dev_class): devs[k] = t if override is not False: dds = [ d for d in devs if ('/'.join(d.split('/')[-3:])).lower() in all_devs ] if dds: print('%d devices already exist: %s' % (len(dds), sorted(dds))) override = raw_input( 'Do you want to override existing properties? (y/n)').lower( ).startswith('y') else: override = False if not instance: instance = raw_input( 'Enter your instance name for the simulated server (use "instance-" to use multiple instances):' ) elif '/' in instance: server, instance = instance.split('/') keepclass = 'y' in raw_input('Keep original Class names?').lower() if keepclass: server = 'SimulatorDS' elif not server: server = raw_input( 'Enter your server name (SimulatorDS/DynamicDS): [SimulatorDS]') \ or 'SimulatorDS' print('>' * 80) for d, t in sorted(devs.items()): t.dev_class = t.dev_class or d.split('/')[-1] if t.dev_class == 'PyStateComposer': klass = t.dev_class elif keepclass: klass = t.dev_class + '_sim' else: klass = 'SimulatorDS' instance_temp = '%s%s' % (instance, t.dev_class) if '-' in instance else instance print('%s/%s:%s , "%s" => %s ' % (server, instance_temp, d, t.dev_class, klass)) its_new = ('/'.join(('dserver', server, instance_temp)) ).lower() not in all_devs or d.lower() not in all_devs if its_new or override: print('writing ... %s(%s)' % (type(t), d)) fd.tango.add_new_device('%s/%s' % (server, instance_temp), klass, d) for p, v in t.props.items(): if not p.startswith( '__' ): #p not in ('DynamicCommands','DynamicStates','LoadFromFile','DevicesList') and fd.tango.put_device_property(d, p, v) #Overriding Dynamic* properties try: fd.tango.put_device_property( d, 'LoadFromFile', path + '%s_attributes.txt' % t.dev_class) fd.tango.put_device_property( d, 'DynamicAttributes', filter( bool, map( str.strip, open(path + '%s_attributes.txt' % t.dev_class).readlines()))) fd.tango.put_device_property( d, 'DynamicCommands', filter( bool, map( str.strip, open(path + '%s_commands.txt' % t.dev_class).readlines()))) fd.tango.put_device_property( d, 'DynamicStates', filter( bool, map( str.strip, open(path + '%s_states.txt' % t.dev_class).readlines()))) except: print('Unable to configure %s(%s) properties ' % (d, t.dev_class)) #traceback.print_exc() fd.tango.put_device_property(d, 'OFFSET', random.randint(0, len(devs))) done.append(d) exported = fd.get_all_devices(exported=True) update = [d for d in done if d in exported] print('Updating %d Devices ...' % len(update)) for d in update: if fd.check_device(d): print('Updating %s ...' % d) try: fd.get_device(d).updateDynamicAttributes() except Exception, e: print(e) else: print('%s failed!' % d) time.sleep(.2)