예제 #1
0
def test_AlarmDS(device=''):
  if not device:
    device = Fn.first((d for d,v in api.devices.items() if v.ping() is not None),None)
  Fn.log.info('Testing AlarmDS(%s)'%device)
  if device:
    device = api.devices.get(device)
    assert Fn.isSequence(device.get_active_alarms())
  return True
예제 #2
0
def test_AlarmDS(device=''):
    if not device:
        device = Fn.first(
            (d for d, v in api.devices.items() if v.ping() is not None), None)
    Fn.log.info('Testing AlarmDS(%s)' % device)
    if device:
        device = api.devices.get(device)
        assert Fn.isSequence(device.get_active_alarms())
    return True
예제 #3
0
def main():
    import sys
    import fandango

    try:
        server, classname, devicename = sys.argv[1:4]
        props = eval(fandango.first(sys.argv[4:]) or ['{}'])
    except:
        print __doc__
        sys.exit(1)

    fandango.tango.add_new_device(server, classname, devicename)
    if props:
        fandango.get_database().put_device_property

    db = Database()

    rateDS = 100
    nDS = 30
    first = 31

    def addTangoDev(server, _class, device):
        di = DbDevInfo()
        di.name, di._class, di.server = device, _class, server
        db.add_device(di)

    _class = 'PySignalSimulator'
    domain = 'sim'
    family = 'pysignalsimulator'

    print 'Creating ', str(rateDS * nDS), ' TangoTest device Servers ...'
    for m in range(first, nDS + first):
        server = '/'.join([_class, '%02d' % m])
        print 'Deleting server ', server
        try:
            db.delete_server(server)
        except:
            pass
        for n in range(1, rateDS + 1):
            server = '/'.join([_class, '%02d' % m])
            member = '%02d' % m + '-' + '%02d' % n
            device = '/'.join([domain, family, member])
            print 'Creating device ', device
            addTangoDev(server, _class, device)
            print 'Adding Properties to class/device = ', _class, '/', device
            db.put_class_property(
                _class,
                {'Description': ['device used to test the archiving system']})
            db.put_device_property(
                device, {'SimAttributes': ['A1=sin((t+random())/2.)']})
            db.put_device_property(
                device, {
                    'SimStates': [
                        'FAULT=square(t,period=10)', "ALARM=Attr('A1')<0",
                        'ON=1'
                    ]
                })
예제 #4
0
    def init(self, tag=''):

        if not hasattr(self, 'validator'):
            print('>#' * 40)
            self.UserValidator, self.validator = '', None
            log, p = '', str(sys.path)
            try:
                props = self.api.servers.db.get_class_property(
                    'PyAlarm', ['UserValidator', 'PanicAdminUsers'])
                self.UserValidator = fandango.first(props['UserValidator'], '')
                self.AdminUsers = filter(
                    bool, map(str.strip, props['PanicAdminUsers']))
                if self.UserValidator:
                    mod, klass = self.UserValidator.rsplit('.', 1)
                    mod = fandango.objects.loadModule(mod)
                    p = mod.__file__
                    klass = getattr(mod, klass)
                    self.validator = klass()
                    try:
                        log = (self.api.get_class_property(
                            'PyAlarm', 'PanicLogFile') or [''])[0]
                        if log: self.validator.setLogging(True, log)
                    except:
                        print('Unable to write log %s' % log)
                        traceback.print_exc()
            except:
                traceback.print_exc()
                print('iValidateWidget: %s module not found in %s' %
                      (self.UserValidator or 'PyAlarm.UserValidator', p))
                return -1

        if self.AdminUsers and not self.UserValidator:
            print(self.AdminUsers, self.UserValidator)
            raise Exception,\
                'iValidateWidget(PanicAdminUsers):'\
                    ' UserValidator property not defined'
            return -1
        if not self.AdminUsers and not self.UserValidator:
            #passwords not available
            return None
        users = sorted(self.api.get_admins_for_alarm(tag))
        if not users:
            #Not using passwords for this alarm
            self.last_users = None
            return None
        elif self.validator is None:
            #Failed to initialize
            return -1
        else:
            if users != getattr(self, 'last_users', []):
                self.last_valid = 0
            self.validator.setAllowedUsers(users)
            self.last_users = users
            return self.validator
예제 #5
0
    def __init__(self,schema,host=None,user='******',passwd='browser',
                 classes=[],LogLevel='WARNING',load=True,logger=None):
        """
        """
        self.log = logger or Logger('ArchivingAPI(%s)'%schema,format='%(levelname)-8s %(asctime)s %(name)s: %(message)s')
        self.log.setLogLevel(LogLevel)
        self.log.debug('Logger streams initialized (error,warning,info,debug)')

        self.tango = fn.get_database() #access to Tango database
        self.api = self #hook used by legacy packages
        self.servers = None
        self.schema = str(schema).lower()
        self.user,self.passwd = user,passwd
        
        if host is None:
            prop = self.tango.get_class_property('%sArchiver'%schema,['DbHost'])['DbHost']
            if not prop: 
                print('ERROR: %sArchiver.DbHost property not defined!'%schema)
                self.host = None
            else:
                self.host = prop[0]
            #if 'TANGO_HOST' in os.environ:
            #    self.host=os.environ['TANGO_HOST'].split(':')[0]
        else: self.host=host
        
        self.dbs={} #pointers to Archiving databases
        
        self.ArchivingClasses = classes or self.get_archiving_classes()
        self.ArchiverClass = fn.first((k for k in self.ArchivingClasses if 'Archiver' in k),'')
        self.ManagerClass = fn.first((k for k in self.ArchivingClasses if 'Manager' in k),'')
        self.ExtractorClass = fn.first((k for k in self.ArchivingClasses if 'Extractor' in k),'')
        try: self.WatcherClass = fn.first((k for k in self.ArchivingClasses if 'Watcher' in k),'')
        except: self.WatcherClass = None
        
        self.loads=CaselessDefaultDict(lambda k:0) #a dict with the archiving load for each device
        self.attributes=CaselessDict() #a dict of ArchivedAttribute objects        
        self.dedicated = CaselessDefaultDict(lambda k:set()) #Dictionary for keeping the attributes reserved for each archiver
        
        if load and self.host and self.ArchivingClasses: 
          self.load_servers()
예제 #6
0
 def main(*args):
     import fandango, fandango.qt, sys
     opts = fandango.linos.sysargs_to_dict(split=True)  #(args,opts)
     print('in QAlarmPanel.main(%s,%s)' % (args, opts))
     filters = fandango.first(args or opts[0] or ['*'])
     app = fandango.qt.getApplication()
     w = QAlarmPanel()
     if '-v' in args:
         import fandango.callbacks
         fandango.callbacks.EventSource.thread().setLogLevel('DEBUG')
         w.view.setLogLevel('DEBUG')
     w.setModel(filters, **opts[1])
     w.show()
     t = (app.activeWindow())
     if not t:
         print('No Active Window, launch QApplication.exec()')
         sys.exit(app.exec_())
예제 #7
0
def main():
  import sys
  import fandango

  try:
      server,classname,devicename = sys.argv[1:4]
      props = eval(fandango.first(sys.argv[4:]) or ['{}'])
  except:
      print __doc__
      sys.exit(1)

  fandango.tango.add_new_device(server,classname,devicename)
  if props:
      fandango.get_database().put_device_property

  db = Database()

  rateDS = 100
  nDS = 30
  first = 31

  def addTangoDev(server,_class,device):
          di = DbDevInfo()
          di.name,di._class,di.server = device,_class,server
          db.add_device(di)

  _class = 'PySignalSimulator'
  domain = 'sim'
  family = 'pysignalsimulator'

  print 'Creating ',str(rateDS*nDS) , ' TangoTest device Servers ...'
  for m in range(first,nDS+first):
          server = '/'.join([_class,'%02d'%m])
          print 'Deleting server ',server
          try: db.delete_server(server)
          except: pass
          for n in range(1,rateDS+1):
                  server = '/'.join([_class,'%02d'%m])
                  member = '%02d'%m+'-'+'%02d'%n
                  device = '/'.join([domain,family,member])
                  print 'Creating device ',device
                  addTangoDev(server,_class,device)
                  print 'Adding Properties to class/device = ',_class,'/',device
                  db.put_class_property(_class,{'Description':['device used to test the archiving system']})
                  db.put_device_property(device,{'SimAttributes':['A1=sin((t+random())/2.)']})
                  db.put_device_property(device,{'SimStates':['FAULT=square(t,period=10)',"ALARM=Attr('A1')<0",'ON=1']})
예제 #8
0
    def init(self,tag=''):
      
        if not hasattr(self,'validator'):
          self.UserValidator,self.validator = '',None
          try:
              props = self.api.servers.db.get_class_property('PyAlarm',['UserValidator','PanicAdminUsers'])
              self.UserValidator = fandango.first(props['UserValidator'],'')
              self.AdminUsers = list(props['PanicAdminUsers'])
              if self.UserValidator:
                mod,klass = self.UserValidator.rsplit('.',1)
                mod = fandango.objects.loadModule(mod)
                klass = getattr(mod,klass)
                self.validator = klass()
                log = (self.api.get_class_property('PyAlarm','PanicLogFile') or [''])[0]
                if log: self.validator.setLogging(True,log)
          except:
              print('iValidateWidget: %s module not found'%(self.UserValidator or 'PyAlarm.UserValidator'))
              return -1

        if not self.AdminUsers and not self.UserValidator:
          #passwords not available
          return None
        users = sorted(self.api.get_admins_for_alarm(tag))
        if not users: 
          #Not using passwords for this alarm
          self.last_users = None
          return None
        elif self.validator is None:
          #Failed to initialize
          return -1
        else:
          if users != getattr(self,'last_users',[]):
            self.last_valid = 0
          self.validator.setAllowedUsers(users)
          self.last_users = users
          return self.validator
예제 #9
0
This script uses fandango.servers.ServersDict class to start/stop devices on any point of the control system using Tango Starters.

  tango_starter.py [host] start|stop|restart|status [server_name_expression_list]

Examples:

  tango_starter.py status              # Will display status of devices in localhost
  tango_starter.py hostname.you.org stop "*hdb*"    # Will stop all *hdb* devices in hostname.you.org
  tango_starter.py restart "pyalarm/*"     # Will restart PyAlarm devices in ALL hosts
"""

actions = 'start stop restart status'.split()

try:
    host = sys.argv[1] if not sys.argv[1] in actions else ''
    action = fandango.first([a for a in sys.argv if a in actions] or 'status')
    targets = sys.argv[(2 if sys.argv[1] in actions else 3):]
except:
    print __doc__
    sys.exit(1)
    
action,targets = sys.argv[1],sys.argv[2:]
try:
    astor = fandango.Astor()
    if targets:
        for exp in targets:
            print 'Loading %s devices'%exp
            astor.load_by_name(exp)
    else:
        h = host or fandango.MyMachine().host
        print 'Loading %s devices'%h
예제 #10
0
#!/usr/bin/env python

__doc__ = """
Usage:
    tango_create Server/Instance Class DeviceName {properties as python dictionary}
"""

import sys
import fandango

try:
    server,classname,devicename = sys.argv[1:4]
    props = eval(fandango.first(sys.argv[4:]) or ['{}'])
except:
    print __doc__
    sys.exit(1)

fandango.tango.add_new_device(server,classname,devicename)
if props:
    fandango.get_database().put_device_property


from PyTango import *

db = Database()

rateDS = 100
nDS = 30
first = 31

def addTangoDev(server,_class,device):
예제 #11
0
__doc__ = doc.get_autodoc(__name__, vars())


def test(model, filters='', debug=False):

    if debug:
        taurus.setLogLevel(taurus.core.util.Logger.Debug)
        form.setWindowTitle(model)
    print 'loading synoptic: %s' % model
    form = VaccaSynoptic(delay=1000, designMode=False)
    #form = taurus.qt.qtgui.graphic.TaurusJDrawSynopticsView(designMode=False)
    #designMode=False,updateMode=VaccaSynoptic.NoViewportUpdate)
    form.show()
    form.setModel(model)
    form.setWindowTitle(model)
    print 'showing ...'
    return form


if __name__ == '__main__':
    #!/usr/bin/python
    assert len(sys.argv) > 1, '\n\nUsage:\n\t> python synoptic [jdw file]'

    app = Qt.QApplication([])  #sys.argv)

    model = sys.argv[1]
    filters = fandango.first(sys.argv[2:], '')
    form = test(model, filters)

    sys.exit(app.exec_())
예제 #12
0
 def get_attribute_ID(self, name):
     return fandango.first(self.get_attributes_IDs(name).values())