def _load_object(k, obj, dct): rd = obj m = rd.split('(')[0].rsplit('.', 1)[0] c = rd[len(m) + 1:] if m not in k.MODULES: fandango.evalX('import %s' % m, modules=k.MODULES) #print('getSchema(%s): load %s reader'%(schema,dct.get('reader'))) return fandango.evalX(obj, modules=k.MODULES, _locals=dct)
def _load_object(k,obj,dct): rd = obj m = rd.split('(')[0].rsplit('.',1)[0] c = rd[len(m)+1:] if m not in k.MODULES: fn.evalX('import %s'%m,modules=k.MODULES) #print('getSchema(%s): load %s reader'%(schema,dct.get('reader'))) return fn.evalX(obj, modules=k.MODULES, _locals=dct)
def getSchema(k, schema, tango='', prop='', logger=None): if schema.startswith('#') and EXPERT_MODE: schema = schema.strip('#') print('%s available only in EXPERT_MODE' % schema) if schema in k.SCHEMAS: # Failed schemas should be also returned (to avoid unneeded retries) return k.SCHEMAS[schema] dct = { 'schema': schema, 'dbname': schema, 'match': clmatch, 'clmatch': clmatch } try: tango = fandango.tango.get_database(tango) props = prop or tango.get_property('PyTangoArchiving', schema)[schema] if fandango.isSequence(props): props = [map(str.strip, t.split('=', 1)) for t in props] dct.update(props) rd = dct.get('reader') if rd: m = rd.split('(')[0].rsplit('.', 1)[0] c = rd[len(m) + 1:] if m not in k.MODULES: fandango.evalX('import %s' % m, modules=k.MODULES) #print('getSchema(%s): load %s reader'%(schema,dct.get('reader'))) dct['logger'] = logger dct['reader'] = rd = fandango.evalX(dct.get('reader'), modules=k.MODULES, _locals=dct) if not hasattr(rd, 'is_attribute_archived'): rd.is_attribute_archived = lambda *a, **k: True if not hasattr(rd, 'get_attributes'): rd.get_attributes = lambda *a, **k: [] if not hasattr(rd, 'get_attribute_values'): if dct['method']: rd.get_attribute_values = getattr(rd, dct['method']) if not hasattr(rd, 'schema'): rd.schema = dct['schema'] except Exception, e: print('Reader.getSchema(%s): failed!' % schema) if logger: try: logger.debug(traceback.format_exc()) except: pass dct = None
def checkSchema(k, schema, attribute='', start=None, stop=None): schema = k.getSchema(schema) if not schema: return False f = schema.get('check') if not f: print('%s has no check function' % str(schema)) return True try: now = time.time() start = (str2time(start) if fn.isString(start) else fn.notNone(start,now-1)) stop = (str2time(stop) if fn.isString(stop) else fn.notNone(stop,now)) k.LOCALS.update({'attribute':attribute.lower(), 'match':clmatch,'clmatch':clmatch, 'overlap':overlap, 'time2str':time2str,'str2time':str2time, 't2s':time2str,'s2t':str2time, 'start':start,'stop':stop,'now':now, 'begin':start,'end':stop,'NOW':now, 'reader':schema.get('reader',schema.get('api')), 'schema':schema.get('schema'), 'dbname':schema.get('dbname',schema.get('schema','')), }) if 'reader' in f: k.getReader(schema) if 'api' in f: k.getApi(schema) #print('In reader.Schemas.checkSchema(%s,%s,%s,%s): %s' #% (schema,attribute,start,stop,f)) #print('(%s)%%(%s)'%(f,[t for t in k.LOCALS.items() if t[0] in f])) v =fn.evalX(f,k.LOCALS,k.MODULES) except: print('checkSchema(%s,%s) failed!' % (schema,attribute)) traceback.print_exc() v = False #print('checkSchema(%s): %s'%(schema,v)) return v
def checkSchema(k, schema, attribute='', start=None, stop=None): if not isinstance(schema, SchemaDict): schema = k.getSchema(schema) if not schema: return False f = schema.get('check') if not f: print('%s has no check function' % str(schema)) return True try: now = time.time() start = (str2time(start) if fn.isString(start) else fn.notNone( start, now - 1)) stop = (str2time(stop) if fn.isString(stop) else fn.notNone( stop, now)) xmatch = lambda e, a: clmatch(e, a, extend=True) k.LOCALS.update({ 'attr': attribute.lower(), 'attribute': attribute.lower(), 'device': attribute.lower().rsplit('/', 1)[0], 'match': lambda r: xmatch(r, attribute), 'clmatch': xmatch, 'overlap': overlap, 'time2str': time2str, 'str2time': str2time, 't2s': time2str, 's2t': str2time, 'start': start, 'stop': stop, 'now': now, 'begin': start, 'end': stop, 'NOW': now, 'reader': schema.get('reader', schema.get('api')), 'schema': schema.get('schema'), 'dbname': schema.get('dbname', schema.get('db_name', schema.get('schema', ''))), }) if 'reader' in f: k.getReader(schema.get('schema')) if 'api' in f: k.getApi(schema.get('schema')) #print('In reader.Schemas.checkSchema(%s,%s,%s,%s): %s' #% (schema,attribute,start,stop,f)) #print('(%s)%%(%s)'%(f,[t for t in k.LOCALS.items() if t[0] in f])) v = fn.evalX(f, k.LOCALS, k.MODULES) except: print('checkSchema(%s,%s) failed!' % (schema, attribute)) traceback.print_exc() v = False #print('checkSchema(%s): %s'%(schema,v)) return v
import os try: reload(panic.view) except: import panic.view domain = '|'.join(os.getenv('INSTANCES').split()) view = panic.view.AlarmView(domain=domain, verbose=True, filters='!ck') #filters={'tag':'A_*'}) import fandango as fn while 1: c = raw_input('command or exit?') if c == 'exit': break try: if c: print(fn.evalX(c, _locals=locals())) except Exception, e: print(e)