def export(devices=[dd, sd], suffix='.json', preffix=''): """ save devices in .json files """ devices = fn.toList(devices) files = [] if preffix and not preffix.endswith('/'): preffix += '/' for d in devices: values = ft.export_device_to_dict(d) files.append(preffix + dev2file(d, suffix)) json.dump(values, open(files[-1], 'w')) return files
def tango2table(filters,opts=[]): """ New method to generate .csv using export_device_to_dict and dict2array Valid options are: --hosts, --text, --print, --skip-attributes Calling tango2table(filters,['--hosts','--skip-attributes']) will return same output that the old tango2csv scripts """ import fandango as fd import fandango.tango as ft devices = [] [devices.extend(ft.find_devices(f)) for f in filters] output = fd.defaultdict(lambda :fd.defaultdict(dict)) attr_info = ('display_unit','standard_unit','label','unit','min_alarm', 'events','description','format','max_alarm','polling','alarms',) excluded = ('None','No standard unit','No display unit','Not specified' 'nada',) for d in devices: v = ft.export_device_to_dict(d) if '--hosts' in opts: d = output[v['host']][v['server']] else: d = output[v['server']] if '--skip-attributes' not in opts: d[v['name']] = {'properties':v['properties']} da = d[v['name']]['attributes'] = fd.defaultdict(dict) for a,t in v['attributes'].items(): da[a] = dict((i,t.get(i)) for i in attr_info) else: d[v['name']] = v['properties'] table = fd.arrays.dict2array(output, branch_filter = (lambda x: str(x)!='extensions'), leave_filter = (lambda y: y and str(y).split()[0] not in excluded), empty='') if '--text' in opts or '--print' in opts: text = '\n'.join('\t'.join(map(str,r)) for r in table) if '--print' in opts: print(text) return text if '--text' in opts else table
def export(devices, suffix='.json', preffix=''): """ save devices in .json files """ devices = fn.toList(devices) files = [] if preffix and not preffix.endswith('/'): preffix += '/' for d in devices: try: values = ft.export_device_to_dict(d) files.append(preffix + dev2file(d, suffix)) json.dump(dict2json(values), open(files[-1], 'w')) except: print('%s failed' % d) traceback.print_exc() return files
def export(devices,suffix='.json',preffix=''): """ save devices in .json files """ devices = fn.toList(devices) files = [] if preffix and not preffix.endswith('/'): preffix+='/' for d in devices: try: values = ft.export_device_to_dict(d) files.append(preffix+dev2file(d,suffix)) json.dump(dict2json(values),open(files[-1],'w')) except: print('%s failed'%d) traceback.print_exc() return files