Example #1
0
def get_panic_devices(api=None, devfilter='*', exported=False):
    api = api or panic.api()
    devs = [d.lower() for d in api.devices if clmatch(devfilter, d)]
    if exported:
        alldevs = fd.get_all_devices(exported=True)
        devs = [d for d in devs if d in alldevs]
    return devs
Example #2
0
def attribute_name_check(attribute):
    dev,attr = a.rsplit('/',1)
    all_devs = fandango.get_all_devices()
    if dev not in all_devs: 
        return False #Device does not exist
    elif not fandango.check_device(dev): 
        return True #If we can't check the attribute we assume that exists.
    elif attr.lower() in map(str.lower,PyTango.DeviceProxy(dev).get_attribute_list()):
        return True
    else:
        return False
def get_servers_status(regexp='*', exclude=['bpms', 'test', 'sr_vc_']):
    servers = fandango.Astor()
    servers.load_by_name('PyAlarm/*%s*' % regexp)
    servers.load_by_name('Panic*/*%s*' % regexp)
    print('%d servers loaded' % len(servers))
    states = servers.states()
    [states.pop(k) for k in states.keys() if any(e in k for e in exclude)]
    exported = fandango.get_all_devices(exported=True)
    exported = [s for s in states if 'dserver/' + s in exported]
    zombies = sorted(d for d, s in states.items()
                     if d in exported and s is None)
    off = sorted(d for d, s in states.items()
                 if d not in zombies and s is None)
    on = sorted(s for s in states if states[s] is not None)

    print('\n')
    for s in off:
        print('%s : %s : OFF' % (servers[s].host, s))
    for s in zombies:
        print('%s : %s : ZOMBIE!' % (servers[s].host, s))
    print('\n')

    failed = []
    for s in on:
        for d in sorted(servers[s].get_device_list()):
            if not fandango.matchCl('(sys|dserver)/*', d):
                ss = fandango.check_device(d)
                p = fandango.tango.get_device_property(d, 'pollingperiod')
                if not p: print('%s has no polling defined' % d)
                elif float(p) > 1000:
                    print('%s has a wrong polling! %s' % (d, p))
                if str(ss) not in ('ALARM', 'ON'):
                    failed.append(s)
                    print('%s : %s : %s : %s' %
                          (servers[s].host, s, d, str(ss)))

    print('\n%d servers have failed devices' % len(failed))
    restart = sorted(set(d for l in (off, zombies, failed) for d in l))
    print('%d servers should be restarted' % len(restart))
    print('')

    return {
        'off': off,
        'on': on,
        'zombies': zombies,
        'failed': failed,
        'restart': restart
    }
Example #4
0
    def updateStates(self):
        try:
            self.debug('On VaccaTree.updateStates()')
            if not hasattr(self, '_statecount'): self._statecount = 0
            if not self._statecount:
                self._nodes2update = self.tree.getAllNodes().keys()
                self._allexported = fandango.get_all_devices(exported=True)

            if len(self._nodes2update) > 32:
                if getattr(self, '_coloured', True):
                    self._coloured = False
                    whites = dict((k, 'CLOSE') for k in self._nodes2update)
                    self.tree.setIcons(whites, regexps=False)
                    self.warning('too many tree nodes (%s) to update!' %
                                 (len(self._nodes2update)))
                else:
                    pass  #Not trivial
            else:
                t0, dct = time.time(), {}
                while time.time() < t0 + 2e-3:
                    if self._statecount >= len(self._nodes2update):
                        self._statecount = 0
                    k = self._nodes2update[self._statecount]
                    self._statecount += 1  #< must be here
                    try:
                        if k.count('/') == k.count(':') + 2:
                            x = k in self._allexported
                            self.debug('On VaccaTree.updateStates(%s,%s,%s)' %
                                       (self._statecount, k, x))
                            if not x:
                                self.debug('\t%s not exported!' % k)
                                dct[k] = 'UNKNOWN'
                            else:
                                dct[k] = str(
                                    taurus.Attribute(k +
                                                     '/State').read().value)
                    except:
                        self.info('updateStates(%s) failed!: %s' %
                                  (k, traceback.format_exc()))
                if dct:
                    self.tree.setIcons(dct, regexps=False)

        except:
            self.warning('On VaccaTree.updateStates(): %s' %
                         traceback.format_exc())
Example #5
0
#A method that does transformation on signals sent to other widgets.
JDRAW_HOOK = None #lambda s: apply_transform(get_coordinates(s)) 
# Enable multiple selection of objects in Synoptic
#from taurus.qt.qtgui.graphic import TaurusGraphicsScene
#TaurusGraphicsScene.ANY_ATTRIBUTE_SELECTS_DEVICE = True

###############################################################################
# Setup of the tree

#Domain/Target used to generate grids/trees ; domain may be regexp, target should not
DOMAIN = '*test*'
TARGET = DOMAIN
USE_DEVICE_TREE = True

#Devices not in JDraw or regular expression to be added to the tree
DEVICES = [d for d in get_all_devices() if not matchCl('^(tango|dserver)/*',d)]#map(bool,set(['%s/VC/ALL'%TARGET,'%s/CT/ALARMS'%TARGET,DEVICE,COMPOSER]))
EXTRA_DEVICES = []

#Custom tree branches are built using nested dictionaries and regular expressions (if empty a jive-like tree is built).
CUSTOM_TREE = {} 

# {'CT':'BL*(CT|ALARMS|PLC)$',
#  'FE':'FE*/VC/*',
#  'Valves': {'.OH':'*OH/PNV*',
#             'EH01':'*EH01/PNV*',},
#  'BAKEOUTS':'BL*(BAKE|BK)*',}

###############################################################################
# Device Panel setup

#PyStateComposer to get Vacuum Profile curves
Example #6
0
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)
Example #7
0
JDRAW_HOOK = None  #lambda s: apply_transform(get_coordinates(s))
# Enable multiple selection of objects in Synoptic
#from taurus.qt.qtgui.graphic import TaurusGraphicsScene
#TaurusGraphicsScene.ANY_ATTRIBUTE_SELECTS_DEVICE = True

###############################################################################
# Setup of the tree

#Domain/Target used to generate grids/trees ; domain may be regexp, target should not
DOMAIN = '*test*'
TARGET = DOMAIN
USE_DEVICE_TREE = True

#Devices not in JDraw or regular expression to be added to the tree
DEVICES = [
    d for d in get_all_devices() if not matchCl('^(tango|dserver)/*', d)
]  #map(bool,set(['%s/VC/ALL'%TARGET,'%s/CT/ALARMS'%TARGET,DEVICE,COMPOSER]))
EXTRA_DEVICES = []

#Custom tree branches are built using nested dictionaries and regular expressions (if empty a jive-like tree is built).
CUSTOM_TREE = {}

# {'CT':'BL*(CT|ALARMS|PLC)$',
#  'FE':'FE*/VC/*',
#  'Valves': {'.OH':'*OH/PNV*',
#             'EH01':'*EH01/PNV*',},
#  'BAKEOUTS':'BL*(BAKE|BK)*',}

###############################################################################
# Device Panel setup
Example #8
0
def create_simulators(filein,
                      instance='',
                      path='',
                      domains={},
                      tango_host='controls02',
                      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)))
    ## THIS CHECK IS MANDATORY, YOU SHOULD EXPORT AND THEN LAUNCH IN DIFFERENT CALLS
    assert tango_host in str(
        fandango.tango.get_tango_host()), 'Use Controls02 for tests!!!'
    devs, org = {}, pickle.load(
        open(filein if '/' in filein else path + filein))
    done = []
    all_devs = fandango.get_all_devices()

    print('>' * 80)

    if not filters:
        print('%d devices in %s: %s' % (len(org), filein, sorted(org.keys())))
        filters = raw_input('Do you want to filter devices? [*/*/*]').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 fandango.matchCl(filters, d) or fandango.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?'
                                 ).lower().startswith('y')
        else:
            override = False

    if not instance:
        instance = raw_input(
            'Enter your instance name for the simulated DynamicServer (use "instance-" to use multiple instances):'
        )

    print('>' * 80)

    for d, t in sorted(devs.items()):
        t.dev_class = t.dev_class or d.split('/')[-1]
        klass = 'PyStateComposer' if t.dev_class == 'PyStateComposer' else 'SimulatorDS'
        server = 'DynamicDS'
        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))
            fandango.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
                    fandango.tango.put_device_property(d, p, v)
            #Overriding Dynamic* properties
            try:
                fandango.tango.put_device_property(
                    d, 'LoadFromFile',
                    path + '%s_attributes.txt' % t.dev_class)
                fandango.tango.put_device_property(
                    d, 'DynamicAttributes',
                    filter(
                        bool,
                        map(
                            str.strip,
                            open(path + '%s_attributes.txt' %
                                 t.dev_class).readlines())))
                fandango.tango.put_device_property(
                    d, 'DynamicCommands',
                    filter(
                        bool,
                        map(
                            str.strip,
                            open(path + '%s_commands.txt' %
                                 t.dev_class).readlines())))
                fandango.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()

        fandango.tango.put_device_property(d, 'OFFSET',
                                           random.randint(0, len(devs)))
        done.append(d)

    exported = fandango.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 fandango.check_device(d):
            print('Updating %s ...' % d)
            try:
                fandango.get_device(d).updateDynamicAttributes()
            except Exception, e:
                print(e)
        else:
            print('%s failed!' % d)
        time.sleep(.2)