Exemple #1
0
 def init_device(self):
     print "In ", self.get_name(), "::init_device()"
     try:
         DynamicDS.init_device(self)  #New in Fandango 11.1
     except:
         self.get_DynDS_properties()  #LogLevel is already set here
     try:
         [
             sys.path.insert(0, p) for p in self.PYTHONPATH
             if p not in sys.path
         ]
     except:
         traceback.print_exc()
     for m in self.ExtraModules:
         try:
             m, k = m.split(' as ') if (' as ' in m) else (m, '')
             m = m.strip().split('.')
             if not m: continue
             k = k or m[-1]
             if k in self._locals: continue
             if m[0] in ('sys', 'os'):
                 raise Exception('%s not allowed' % str(m))
             print '%s.init_device(): loading %s as %s' % (self.get_name(),
                                                           m, k)
             l = imp.load_module(m[0], *imp.find_module(m[0]))
             if len(m) == 1:
                 self._locals[k or m[0]] = l
             elif m[1] == '*':
                 self._locals.update(get_module_dict(l))
             else:
                 self._locals[k or m[1]] = l.__dict__[m[1]]
         except:
             traceback.print_exc()
     self.set_state(PyTango.DevState.ON)
     print "Out of ", self.get_name(), "::init_device()"
Exemple #2
0
 def __init__(self, cl, name):
     ##Loading special methods to be available in formulas
     _locals = {}
     DynamicDS.__init__(self, cl, name, _locals=_locals, useDynStates=True)
     FolderDS.init_device(self)
     self.worker = fn.threads.WorkerThread()
     self.worker.start()
     self.worker.put('1')
Exemple #3
0
    def init_device(self):
        print "In ", self.get_name(), "::init_device{}(%s)"%self.get_init_count()
        try: 
            DynamicDS.init_device(self) #New in Fandango 11.1
        except:
            self.get_DynDS_properties() #LogLevel is already set here
        try:[sys.path.insert(0,p) for p in self.PYTHONPATH if p not in sys.path]
        except: traceback.print_exc()
        self.setLogLevel('INFO')
        default_props = dict((k,v[-1]) for k,v in WorkerDSClass.device_property_list.items())
        all_props = (tango.get_matching_device_properties(self.get_name(),'*'))

        missing = [k for k,v in default_props.items() if v and k.lower() not in map(str.lower,all_props)]
        if missing:
          print('Updating default property values')
          print default_props.keys()
          print all_props.keys()
          print missing
          self.get_db().put_device_property(self.get_name(),dict((k,default_props[k]) for k in missing))
        
        #TASKS IS NOT CASELESS TO KEEP THE ORIGINAL NAME OF THE TASK
        self.tasks = dict((k,v) for k,v in all_props.items() if k.lower() not in map(str.lower,default_props))
        self.sends = CaselessDefaultDict(int)
        self.dones = CaselessDefaultDict(int)
        self.conditions = self.get_task_conditions()
        self.TStarted = time.time()
        self.StaticAttributes = ['%s = str(TASK("%s") or "")'%(t,t) for t in self.tasks]
        self.StaticAttributes += ['LastCheck = self.last_check']
        self.parseStaticAttributes()
        self.info('Loaded %d tasks: %s'%(len(self.tasks),self.tasks.keys()))

        for m in self.ExtraModules:
            self.extra_modules = {}
            try: 
              self.info('Loading ExtraModules(%s)'%m)
              m,k = m.split(' as ') if (' as ' in m) else (m,'')
              m = m.strip().split('.')
              if not m: continue
              k = k or m[-1]
              if k not in self._locals: 
                if m[0] in ('sys','os'): 
                  raise Exception('%s not allowed'%str(m))
                print '%s.init_device(): loading %s as %s' % (self.get_name(),m,k)
                l = imp.load_module(m[0],*imp.find_module(m[0]))
                if len(m)==1:
                  self._locals[k or m[0]] = l
                elif m[1]=='*':
                  self._locals.update(get_module_dict(l))
                else:
                  self._locals[k or m[1]] = l.__dict__[m[1]]
              self.extra_modules[k] = self._locals[k]
            except: traceback.print_exc()
            
        self.set_state(PyTango.DevState.INIT)
        self.Start()
        print "Out of ", self.get_name(), "::init_device()"
Exemple #4
0
 def __init__(self, cl, name):
     #PyTango.LatestDeviceImpl.__init__(self,cl,name)
     print 'IN PYATTRIBUTEPROCESSOR.__INIT__'
     _locals = {}
     [_locals.update(get_module_dict(m)) for m in self.LIBS if m]
     _locals.update((k.__name__, k) for k in self.NAMES if k)
     _locals.update(self.OTHERS)
     #print '_locals are:\n%s' % _locals
     DynamicDS.__init__(self, cl, name, _locals=_locals, useDynStates=True)
     PyAttributeProcessor.init_device(self)
Exemple #5
0
 def __init__(self,cl, name):
     #PyTango.Device_4Impl.__init__(self,cl,name)
     print 'IN WorkerDS.__INIT__'
     _locals = {}
     [_locals.update(get_module_dict(m)) for m in self.LIBS]
     _locals.update((k.__name__,k) for k in self.NAMES)
     _locals.update(self.OTHERS)
     _locals['TASK'] = lambda t,s=self:s.worker.locals(t+'_result') if t in s.tasks else None
     #print '_locals are:\n%s' % _locals
     DynamicDS.__init__(self,cl,name,_locals=_locals,useDynStates=True)
     WorkerDS.init_device(self)
Exemple #6
0
 def always_executed_hook(self):
     #print "In ", self.get_name(), "::always_excuted_hook()"
     try:
       self.update_locals()
       DynamicDS.always_executed_hook(self)
       if self.last_check < (time.time()-1.5*self.PollingSeconds):
         self.set_state(PyTango.DevState.FAULT)
       else:
         self.set_state(self._state)
       self.set_status(self._status)
     except:
       self.warning(traceback.format_exc())
Exemple #7
0
 def init_device(self):
     print "In ", self.get_name(), "::init_device()"
     try:
         DynamicDS.init_device(self)  #New in Fandango 11.1
     except:
         self.get_DynDS_properties()  #LogLevel is already set here
     if PyTangoArchiving and 'archiving' in str(
             self.DynamicAttributes):  #+str(self.DynamicCommands):
         print 'Adding PyTangoArchiving support ...'
         self._locals['archiving'] = PyTangoArchiving.Reader()
     self.set_state(PyTango.DevState.ON)
     print "Out of ", self.get_name(), "::init_device()"
Exemple #8
0
 def __init__(self, cl, name):
     #PyTango.Device_4Impl.__init__(self,cl,name)
     print 'IN SimulatorDS.__INIT__'
     _locals = {}
     [_locals.update(get_module_dict(m)) for m in self.LIBS]
     _locals.update(
         (k.__name__, k) for k in self.NAMES if hasattr(k, '__name__'))
     _locals.update(self.OTHERS)
     #_locals.update(locals())
     #_locals.update(globals())
     DynamicDS.__init__(self, cl, name, _locals=_locals, useDynStates=True)
     SimulatorDS.init_device(self)
Exemple #9
0
 def always_executed_hook(self):
     #print "In ", self.get_name(), "::always_excuted_hook()"
     try:
         self.update_locals()
         DynamicDS.always_executed_hook(self)
         if self.last_check < (time.time() - 1.5 * self.PollingSeconds):
             self.set_state(PyTango.DevState.FAULT)
         else:
             self.set_state(self._state)
         self.set_status(self._status)
     except:
         self.warning(traceback.format_exc())
Exemple #10
0
 def __init__(self, cl, name):
     #PyTango.LatestDeviceImpl.__init__(self,cl,name)
     #print 'IN WorkerDS.__INIT__'
     _locals = {}
     [_locals.update(get_module_dict(m)) for m in self.LIBS]
     _locals.update((k.__name__, k) for k in self.NAMES)
     _locals.update(self.OTHERS)
     _locals['TASK'] = lambda t, s=self: s.worker.locals(
         t + '_result') if t in s.tasks else None
     #print '_locals are:\n%s' % _locals
     DynamicDS.__init__(self, cl, name, _locals=_locals, useDynStates=True)
     WorkerDS.init_device(self)
Exemple #11
0
 def __init__(self,cl, name):
     #PyTango.Device_4Impl.__init__(self,cl,name)
     print 'IN SimulatorDS.__INIT__'
     
     ##Loading special methods to be available in formulas
     _locals = {}
     from re import match,search,findall
     _locals.update({'match':match,'search':search,'findall':findall})
     import re,math,random
     _locals.update((k,v) for m in (re,math,random) for k,v in  m.__dict__.items()  if not k.startswith('_'))
     try:
         import Signals
         _locals.update((k,v) for k,v in  Signals.__dict__.items() if not k.startswith('_'))
     except: print 'Unable to import custom Signals module'
     
     DynamicDS.__init__(self,cl,name,_locals=_locals,useDynStates=True)
     SimulatorDS.init_device(self)
Exemple #12
0
 def __init__(self, cl, name):
     U = PyTango.Util.instance()
     import gc, resource
     try:
         import guppy
         heapy = guppy.hpy()
     except:
         guppy, heapy = None, None
     DynamicDS.__init__(self,
                        cl,
                        name,
                        _locals={
                            'Util': U,
                            'PyUtil': U,
                            'self': self,
                            'fandango': fandango,
                            'resource': resource,
                            'gc': gc,
                            'guppy': guppy,
                            'heapy': heapy
                        },
                        useDynStates=False)
     DDebug.init_device(self)
Exemple #13
0
 def always_executed_hook(self):
     #print "In "+self.get_name()+ "::always_excuted_hook()"
     DynamicDS.always_executed_hook(self)
Exemple #14
0
 def init_device(self):
     print "In ", self.get_name(), "::init_device()"
     DynamicDS.init_device(self)
     if self.DynamicStates: self.set_state(PyTango.DevState.UNKNOWN)
     print "Out of ", self.get_name(), "::init_device()"
Exemple #15
0
    def init_device(self):
        print "In ", self.get_name(
        ), "::init_device{}(%s)" % self.get_init_count()
        try:
            DynamicDS.init_device(self)  #New in Fandango 11.1
        except:
            self.get_DynDS_properties()  #LogLevel is already set here
        try:
            [
                sys.path.insert(0, p) for p in self.PYTHONPATH
                if p not in sys.path
            ]
        except:
            traceback.print_exc()
        self.setLogLevel('INFO')
        default_props = dict(
            (k, v[-1]) for k, v in WorkerDSClass.device_property_list.items())
        all_props = (tango.get_matching_device_properties(
            self.get_name(), '*'))

        missing = [
            k for k, v in default_props.items()
            if v and k.lower() not in map(str.lower, all_props)
        ]
        if missing:
            print('Updating default property values')
            print default_props.keys()
            print all_props.keys()
            print missing
            self.get_db().put_device_property(
                self.get_name(), dict((k, default_props[k]) for k in missing))

        self.sends = CaselessDefaultDict(int)
        self.dones = CaselessDefaultDict(int)
        self.conditions = self.get_task_conditions()

        #TASKS IS NOT CASELESS TO KEEP THE ORIGINAL NAME OF THE TASK
        self.tasks = dict((k, v) for k, v in all_props.items()
                          if k.lower() in self.conditions
                          #k.lower() not in map(str.lower,default_props)
                          )

        self.TStarted = time.time()
        self.StaticAttributes = [
            '%s = str(TASK("%s") or "")' % (t, t) for t in self.tasks
        ]
        self.StaticAttributes += ['LastCheck = self.last_check']
        self.parseStaticAttributes()
        self.info('Loaded %d tasks: %s' % (len(self.tasks), self.tasks.keys()))

        for m in self.ExtraModules:
            self.extra_modules = {}
            try:
                self.info('Loading ExtraModules(%s)' % m)
                m, k = m.split(' as ') if (' as ' in m) else (m, '')
                m = m.strip().split('.')
                if not m: continue
                k = k or m[-1]
                if k not in self._locals:
                    if m[0] in ('sys', 'os'):
                        raise Exception('%s not allowed' % str(m))
                    print '%s.init_device(): loading %s as %s' % (
                        self.get_name(), m, k)
                    l = imp.load_module(m[0], *imp.find_module(m[0]))
                    if len(m) == 1:
                        self._locals[k or m[0]] = l
                    elif m[1] == '*':
                        self._locals.update(get_module_dict(l))
                    else:
                        self._locals[k or m[1]] = l.__dict__[m[1]]
                self.extra_modules[k] = self._locals[k]
            except:
                traceback.print_exc()

        self.set_state(PyTango.DevState.INIT)
        self.Start()
        print "Out of ", self.get_name(), "::init_device()"
Exemple #16
0
 def always_executed_hook(self):
     print "In ", self.get_name(), "::always_excuted_hook()"
     DynamicDS.always_executed_hook(self)