fandango.tango module

Description

provides tango utilities for fandango, like database search methods and emulated Attribute Event/Value types

This module is a light-weight set of utilities for PyTango. Classes dedicated for device management will go to fandango.device Methods for Astor-like management will go to fandango.servers

Contents

.

Classes

fakeEvent

class fandango.tango.fakeEvent(device, attr_name, attr_value, err, errors)[source]

TangoEval

class fandango.tango.TangoEval(formula='', launch=True, timeout=1000, keeptime=100, trace=False, proxies=None, attributes=None, cache=0, use_events=False, event_hook=None, **kwargs)[source]

Class for Tango formula evaluation; used by Panic-like formulas

example:
  te = fandango.TangoEval(cache=3)
  te.eval('test/sim/test-00/A * test/sim/test-00/S.delta')
  Out: 2.6307095848792521 #A value multiplied by delta of S in its last 3 values

Attributes in the formulas may be (it is recommended to insert spaces between attribute names and operators): THIS REGULAR EXPRESSIONS DOES NOT MATCH THE HOST IN THE FORMULA!!!; IT IS TAKEN AS PART OF THE DEVICE NAME!!

dom/fam/memb/attrib >= V1 #Will evaluate the attribute value
d/f/m/a1 > V2 and d/f/m/a2 == V3 #Comparing 2 attributes
d/f/m.quality != QALARM #Using attribute quality
d/f/m/State == UNKNOWN #States can be compared directly
d/f/m/A.exception #True if exception occurred
d/f/m/A.time #Attribute value time
d/f/m/A.value #Explicit value
d/f/m/A.delta #Increase/decrease of the value since the first value in cache (if cache and cache_depth are set)
d/f/m/A.all #Instead of just value will return an AttributeValue object 

All tango-like variables are parsed. TangoEval.macros can be used to do regexp-based substitution. By default FIND(regexp) will be replaced by a list of matching attributes.

FIND([a-zA-Z0-9/].*) macro allows to get any attribute matching a regular expression Any variable in _locals is evaluated or explicitly replaced in the formula if matches $(); e.g. FIND($(VARNAME)//) T() < T(‘YYYY/MM/DD hh:mm’) allow to compare actual time with any time
Use_events:will manage events using the callbacks.EventSource object. It will redirect

all events to TangoEval.eventReceived method. If an event_hook callback is passed as argument, both TangoEval object and result of eval will be sent to it.

eval() will be triggered by events only if event_hook is True or a callable

add_macro(macro_name, macro_expression, macro_function)[source]

Add a new macro to be parsed by parse_formula. It will apply macro_function to the target found by macro_expression; the result will later replace macro_name%target

e.g: self.add_macro(‘FIND(%s)’,self.FIND_EXP,self.find_macro) #where FIND_EXP = ‘FIND(((?:[ ‘”])?[^)]*(?:[ ‘”])?))’

eval(formula=None, previous=None, _locals=None, _raise=None)[source]

Evaluates the given formula. Previous can be used to add extra local values, or predefined values for attributes ({‘a/b/c/d’:1} that would override its reading Any variable in locals is evaluated or explicitly replaced in the formula if appearing with brackets (e.g. FIND({VARNAME}//)) :param _raise: if attribute is empty or ‘State’ exceptions will be rethrown

eventReceived(src, type_, value)[source]

Method to implement the event notification Source will be an object, type a PyTango EventType, evt_value an AttrValue Regarding PANIC, the eventReceived hook must be in the PanicAPI, not here

find_macro(target)[source]

Gets a match of FIND_EXP and applies get_matching_attributes to the expresion found.

get_delta(target)[source]

target = (device+’/’+attribute).lower() ; returns difference between first and last cached value

parse_formula(formula, _locals=None)[source]

This method just removes comments and applies self.macros (e.g FIND()) searches in the formula; In this method there is no tango check, neither value replacement

parse_variables(formula, _locals=None, parsed=False)[source]

This method parses attributes declarated in formulas with the following formats: TAG1: dom/fam/memb/attrib >= V1 #A comment TAG2: d/f/m/a1 > V2 and d/f/m/a2 == V3 TAG3: d/f/m.quality != QALARM #Another comment TAG4: d/f/m/State ##A description?, Why not :return:

  • a None value if the alarm is not parsable
  • a list of (device,attribute,value/time/quality) tuples
read_attribute(device, attribute='', what='', _raise=True, timeout=None)[source]

Executes a read_attribute and returns the value requested :param _raise: if attribute is empty or ‘State’ exceptions will be rethrown

get_all_devices

class fandango.tango.get_all_devices(exported=False, keeptime=None, host='')[source]

fakeAttributeValue

class fandango.tango.fakeAttributeValue(name, value=None, time_=0.0, quality=PyTango._PyTango.AttrQuality.ATTR_VALID, dim_x=1, dim_y=1, parent=None, device='', error=False, keeptime=0)[source]

This class simulates a modifiable AttributeValue object (not available in PyTango) It is the class used to read values from Dev4Tango devices (valves, pseudos, composer, etc ...) It also has a read(cache) method to be used as a TaurusAttribute or AttributeProxy (but it returns self if cache is not used) The cache is controlled by keeptime variable (milliseconds) :param parent: Apart of common Attribute arguments, parent will be used to keep a proxy to the parent object (a DeviceProxy or DeviceImpl)

ProxiesDict

class fandango.tango.ProxiesDict(use_tau=False)[source]

Dictionary that stores PyTango.DeviceProxies It is like a normal dictionary but creates a new proxy each time that the “get” method is called An earlier version is used in PyTangoArchiving.utils module This class must be substituted by Tau.Core.TauManager().getFactory()()

get_admin(dev_name)[source]

Adds to the dictionary the admin device for a given device name and returns a proxy to it.

pop(dev_name)[source]

Removes a device from the dict

TangoCommand

class fandango.tango.TangoCommand(command, device=None, timeout=None, feedback=None, expected=None, wait=3.0, asynch=True, process=False)[source]

This class encapsulates a call to a Tango Command, it manages asynchronous commands in a background thread or process. It also allows to setup a “feedback” condition to validate that the command has been executed.

The usage would be like:

tc = TangoCommand('move',DeviceProxy('just/a/motor'),asynch=True,process=False)

#In this example the value of the command will be returned once the state will change
result = tc(args,feedback='state',expected=PyTango.DevState.MOVING,timeout=10000)

#In this other example, it will be the value of the state what will be returned
result = tc(args,feedback='state',timeout=10000)
Parameters:
  • command – the name of a tango command; or a callable
  • device – a device that can be an string, a DeviceProxy or a TaurusDevice
  • timeout – when using asynchronous commands default timeout can be overriden
  • feedback – attribute, command or callable to be executed
  • expected – if not None, value that feedback must have to consider the command successful
  • wait – time to wait for feedback (once command has been executed)
  • asynch – to perform the wait in a different thread instead of blocking
  • process – whether to use a different process to execute the command (if CPU intensive or trhead-blocking)

:

TangoedValue

class fandango.tango.TangoedValue[source]

Functions

get_distinct_devices

fandango.tango.get_distinct_devices(attrs)[source]

It returns a list with the distinct device names appearing in a list

get_domain

fandango.tango.get_domain(model)[source]

check_property_extensions

fandango.tango.check_property_extensions(prop, value, db=None, extensions={'@COPY:': <function _copy_extension at 0x7eff574f8de8>, '@FILE:': <function _file_extension at 0x7eff574f8e60>, '@ATTR:': <function _attr_extension at 0x7eff574f8ed8>}, filters=[])[source]

_file_extension

fandango.tango._file_extension(prop, row, db=None)[source]

get_attribute_time

fandango.tango.get_attribute_time(value)[source]

get_alias_dict

fandango.tango.get_alias_dict(exp='*')[source]

returns an {alias:device} dictionary with all matching alias from Tango DB :param exp:

get_matching_servers

fandango.tango.get_matching_servers(expressions, tango_host='', exported=False)[source]

Return all servers in the given tango tango_host matching the given expressions. :param exported: whether servers should be running or not

get_device_started

fandango.tango.get_device_started(target)[source]

Returns device started time

check_device

fandango.tango.check_device(dev, attribute=None, command=None, full=False, admin=False, bad_state=False)[source]

Command may be ‘StateDetailed’ for testing HdbArchivers It will return True for devices ok, False for devices not running and None for unresponsive devices.

read_internal_attribute

fandango.tango.read_internal_attribute(device, attribute)[source]
This method allows several things:
  • If a device object (Impl or Proxy) is given, it is used to read the attribute
  • If the attribute belongs to a device in the SAME SERVER, it accesses directly to the device object
  • If the attribute belongs to an external SERVER, use PyTango proxies to read it
  • It can manage dynamic attributes used within the same SERVER calling read_dyn_attr

device must be a DevImpl object or string, attribute must be an string if the device is not internal this method will connect to a PyTango Proxy the method will return a fakeAttributeValue object

get_device_help

fandango.tango.get_device_help(self, str_format='text')[source]

This command returns help text for this device class and its parents

export_commands_to_dict

fandango.tango.export_commands_to_dict(device, target='*')[source]

export all device commands config to a dictionary

get_internal_devices

fandango.tango.get_internal_devices()[source]

Gets all devices declared in the current Tango server

get_device_attributes

fandango.tango.get_device_attributes(dev, expressions='*')[source]

Given a device name it returns the attributes matching any of the given expressions

export_attribute_to_dict

fandango.tango.export_attribute_to_dict(model, attribute=None, value=None, keep=False, as_struct=False)[source]

get attribute config, format and value from Tango and return it as a dictionary:

Parameters:model – can be a full tango model, a device name or a device proxy
keys: min_alarm,name,data_type,format,max_alarm,ch_event,data_format,value,
label,writable,device,polling,alarms,arch_event,unit

check_host

fandango.tango.check_host(host)[source]

Pings a hostname, returns False if unreachable

attr2str

fandango.tango.attr2str(attr_value)[source]

find_attributes

fandango.tango.find_attributes(*args, **kwargs)[source]

get_matching_device_attribute_labels

fandango.tango.get_matching_device_attribute_labels(device, attribute)[source]

To get all gauge port labels: get_matching_device_attribute_labels(‘vgct‘,’p*’)

get_class_devices

fandango.tango.get_class_devices(klass, db=None)[source]

Returns all registered devices for a given class

get_distinct_members

fandango.tango.get_distinct_members(attrs)[source]

It returns a list with the distinc member names appearing in a list

get_server_property

fandango.tango.get_server_property(name, instance, prop)[source]

get_matching_devices

fandango.tango.get_matching_devices(expressions, limit=0, exported=False, fullname=False, trace=False)[source]

Searches for devices matching expressions, if exported is True only running devices are returned Tango host will be included in the matched name if fullname is True

parse_labels

fandango.tango.parse_labels(text)[source]

get_device

fandango.tango.get_device(dev, use_tau=False, keep=False)[source]

get_database

fandango.tango.get_database(host='', port='', use_tau=False)[source]

Method to get a singleton instance of the Tango Database host/port can be a host,port tuple; a ‘host:port’ string or a taurus model. @TODO: host/port is checked only at first creation, once initialized you can’t change HOST

put_class_property

fandango.tango.put_class_property(klass, property, value=None, db=None)[source]
Two syntax are possible:
  • put_class_property(class,{property:value})
  • put_class_property(class,property,value)

get_attribute_info

fandango.tango.get_attribute_info(device, attribute)[source]

This method returns attribute info in the attr_list format It parses values returned by PyTango.DeviceProxy(device).get_attribute_config(attribute) return format:

[[PyTango.DevString, PyTango.SPECTRUM, PyTango.READ_WRITE, 2], {

‘unit’:”mbar”, ‘format’:”%4d”,

}],

get_device_info

fandango.tango.get_device_info(dev, db=None)[source]

This method provides an alternative to DeviceProxy.info() for those devices that are not running

get_member

fandango.tango.get_member(model)[source]

set_device_labels

fandango.tango.set_device_labels(target, labels)[source]

Applies an {attr:label} dict for attributes of this device

get_all_models

fandango.tango.get_all_models(expressions, limit=1000)[source]

Customization of get_matching_attributes to be usable in Taurus widgets. It returns all the available Tango attributes (exported!) matching any of a list of regular expressions.

get_device_for_alias

fandango.tango.get_device_for_alias(alias)[source]

returns the device name for a given alias

get_attribute_label

fandango.tango.get_attribute_label(target, use_db=True)[source]

get_matching_device_properties

fandango.tango.get_matching_device_properties(devs, props, hosts=[], exclude='*dserver*', port=10000, trace=False)[source]

get_matching_device_properties enhanced with multi-host support @props: regexp are enabled! get_devices_properties(‘alarms‘,props,hosts=[get_bl_host(i) for i in bls]) @TODO: Compare performance of this method with get_devices_properties

get_device_property

fandango.tango.get_device_property(device, property, db=None)[source]

It returns device property value or just first item if value list has lenght==1

loadTaurus

fandango.tango.loadTaurus()[source]

get_extension_arg

fandango.tango.get_extension_arg(x)[source]

parse_tango_model

fandango.tango.parse_tango_model(name, use_tau=False, use_host=False)[source]

{‘attributename’: ‘state’, ‘attribute’: ‘state’, ‘devicename’: ‘bo01/vc/ipct-01’, #Always short name ‘device’: ‘cts:10000/bo01/vc/ipct-01’, #Will contain host if use_host or host!=TANGO_HOST ‘host’: ‘cts’, ‘port’: ‘10000’, ‘scheme’: ‘tango’}

get_distinct_attributes

fandango.tango.get_distinct_attributes(attrs)[source]

It returns a list with the distinc attribute names (excluding device) appearing in a list

get_model_name

fandango.tango.get_model_name(model)[source]

check_attribute

fandango.tango.check_attribute(attr, readable=False, timeout=0, brief=False, trace=False)[source]

checks if attribute is available. :param readable: Whether if it’s mandatory that the attribute returns a value or if it must simply exist. :param timeout: Checks if the attribute value have been effectively updated (check zombie processes). :param brief: return just .value instead of AttrValue object

get_device_host

fandango.tango.get_device_host(dev)[source]

Asks the Database device server about the host of this device

reduce_distinct

fandango.tango.reduce_distinct(group1, group2)[source]

It returns a list of (device,domain,family,member,attribute) keys that appear in group1 and not in group2

get_server_pid

fandango.tango.get_server_pid(server)[source]

get_database_device

fandango.tango.get_database_device(use_tau=False, db=None)[source]

export_properties_to_dict

fandango.tango.export_properties_to_dict(device, target='*')[source]

export device or class properties to dictionary

get_property_history

fandango.tango.get_property_history(dev, prop)[source]

get_family

fandango.tango.get_family(model)[source]

get_device_labels

fandango.tango.get_device_labels(target, filters='*', brief=True)[source]

Returns an {attr:label} dict for all attributes of this device Filters will be a regular expression to apply to attr or label. If brief is True (default) only those attributes with label are returned. This method works offline, does not need device to be running

get_tango_host

fandango.tango.get_tango_host(dev_name='', use_db=False)[source]

If device is a tango model, it will extract the host from the model URL If devicesis none, then environment variable or PyTango.Database are used to extract the host If TANGO_HOST is not defined it will always fallback to PyTango.Database()

get_attribute_config

fandango.tango.get_attribute_config(target)[source]

get_attribute_events

fandango.tango.get_attribute_events(target, polled=True, throw=False)[source]

__test_method__

fandango.tango.__test_method__(args=None)[source]

cast_tango_type

fandango.tango.cast_tango_type(value_type)[source]

Returns the python equivalent to a Tango type

find_devices

fandango.tango.find_devices(*args, **kwargs)[source]

check_starter

fandango.tango.check_starter(host)[source]

Checks host’s Starter server

get_devices_properties

fandango.tango.get_devices_properties('*alarms*',props,hosts=[get_bl_host(i) for i in bls])[source]

props must be an string as passed to Database.get_device_property(); regexp are not enabled! get_matching_device_properties enhanced with multi-host support @TODO: Compare performance of this method with get_matching_device_properties

set_attribute_label

fandango.tango.set_attribute_label(target, label='', unit='')[source]

property_undo

fandango.tango.property_undo(dev, prop, epoch)[source]

add_new_device

fandango.tango.add_new_device(server, klass, device)[source]

getTangoValue

fandango.tango.getTangoValue(obj, device=None)[source]

This method may be used to return objects from read_attribute or FIND() that are still computable and keep quality/time members try to avoid spectrums.; this method doesn’t work for numpy arrays so I have to convert them to less efficient lists.

get_proxy

fandango.tango.get_proxy(argin, use_tau=False, keep=False)[source]

Returns attribute or device proxy depending on argin syntax

check_device_list

fandango.tango.check_device_list(devices, attribute=None, command=None)[source]

This method will check a list of devices grouping them by host and server; minimizing the amount of pings to do.

parse_db_command_array

fandango.tango.parse_db_command_array(data, keys=1, depth=2)[source]

This command will parse data received from DbGetDeviceAttributeProperty2 command. DB device commands return data in this format: X XSize Y YSize Z ZSize ZValue W WSize WValue This corresponds to {X:{Y:{Z:[Zdata],W:[Wdata]}}} Depth of the array is 2 by default e.g.: label_of_dev_test_attribute = parse_db_command_array(dbd.DbGetDeviceAttributeProperty2([dev,attr]).,keys=1,depth=2)[dev][attr][‘label’][0]

read_attribute

fandango.tango.read_attribute(attr, timeout=0, full=False)[source]

Alias to check_attribute(attr,brief=True)

get_device_commands

fandango.tango.get_device_commands(dev)[source]

returns a list of device command names

_attr_extension

fandango.tango._attr_extension(prop, row, db=None)[source]

This extension will replace the line by an attribute forwarding formula ($Arg = Type(ATTR(‘arg’))

Syntax is @ATTR:[alias=]model [+formula]

get_distinct_domains

fandango.tango.get_distinct_domains(attrs)[source]

It returns a list with the distinc member names appearing in a list

get_distinct_families

fandango.tango.get_distinct_families(attrs)[source]

It returns a list with the distinc member names appearing in a list

get_full_name

fandango.tango.get_full_name(model)[source]

Returns full schema name as needed by HDB++ api

TGet

fandango.tango.TGet(*args)[source]

Universal fandango helper, it will return a matching Tango object depending on the arguments passed Objects are: database (), server (/), attribute ((:/)?*///), device ()

_copy_extension

fandango.tango._copy_extension(prop, row, db=None)[source]

get_real_name

fandango.tango.get_real_name(dev, attr=None)[source]

It translate any device/attribute string by name/alias/label

Parameters:
  • device – Expected format is [host:port/][device][/attribute]; where device can be either a/b/c or alias
  • attr – optional, when passed it will be regexp matched against attributes/labels

put_device_property

fandango.tango.put_device_property(device, property, value=None, db=None)[source]
Two syntax are possible:
  • put_device_property(device,{property:value})
  • put_device_property(device,property,value)

get_polled_attrs

fandango.tango.get_polled_attrs(device, others=None)[source]

@TODO: Tango8 has its own get_polled_attr method; check for incompatibilities if a device is passed, it returns the polled_attr property as a dictionary if a list of values is passed, it converts to dictionary others argument allows to get extra property values in a single DB call; e.g others = [‘polled_cmd’] would append the polled commands to the list

export_device_to_dict

fandango.tango.export_device_to_dict(device, commands=True, properties=True)[source]

This method can be used to export the current configuration of devices, attributes and properties to a file. The dictionary will get properties, class properties, attributes, commands, attribute config, event config, alarm config and pollings.

get_matching_attributes

fandango.tango.get_matching_attributes(expressions, limit=0, fullname=None, trace=False)[source]

Returns all matching device/attribute pairs. regexp only allowed in attribute names :param expressions: a list of expressions like [domain_wild/family_wild/member_wild/attribute_regexp]

get_alias_for_device

fandango.tango.get_alias_for_device(dev)[source]

return alias for this device

get_class_property

fandango.tango.get_class_property(klass, property, db=None)[source]

It returns class property value or just first item if value list has lenght==1


raw autodoc

class fandango.tango.ProxiesDict(use_tau=False)[source]

Bases: fandango.dicts.CaselessDefaultDict, fandango.objects.Object

Dictionary that stores PyTango.DeviceProxies It is like a normal dictionary but creates a new proxy each time that the “get” method is called An earlier version is used in PyTangoArchiving.utils module This class must be substituted by Tau.Core.TauManager().getFactory()()

get(dev_name)[source]
get_admin(dev_name)[source]

Adds to the dictionary the admin device for a given device name and returns a proxy to it.

pop(dev_name)[source]

Removes a device from the dict

fandango.tango.TGet(*args)[source]

Universal fandango helper, it will return a matching Tango object depending on the arguments passed Objects are: database (), server (/), attribute ((:/)?*///), device ()

class fandango.tango.TangoCommand(command, device=None, timeout=None, feedback=None, expected=None, wait=3.0, asynch=True, process=False)[source]

Bases: object

This class encapsulates a call to a Tango Command, it manages asynchronous commands in a background thread or process. It also allows to setup a “feedback” condition to validate that the command has been executed.

The usage would be like:

tc = TangoCommand('move',DeviceProxy('just/a/motor'),asynch=True,process=False)

#In this example the value of the command will be returned once the state will change
result = tc(args,feedback='state',expected=PyTango.DevState.MOVING,timeout=10000)

#In this other example, it will be the value of the state what will be returned
result = tc(args,feedback='state',timeout=10000)
Parameters:
  • command – the name of a tango command; or a callable
  • device – a device that can be an string, a DeviceProxy or a TaurusDevice
  • timeout – when using asynchronous commands default timeout can be overriden
  • feedback – attribute, command or callable to be executed
  • expected – if not None, value that feedback must have to consider the command successful
  • wait – time to wait for feedback (once command has been executed)
  • asynch – to perform the wait in a different thread instead of blocking
  • process – whether to use a different process to execute the command (if CPU intensive or trhead-blocking)

:

exception BadFeedback[source]

Bases: exceptions.Exception

exception TangoCommand.BadResult[source]

Bases: exceptions.Exception

exception TangoCommand.CommandException[source]

Bases: exceptions.Exception

exception TangoCommand.CommandTimeout[source]

Bases: exceptions.Exception

TangoCommand.Proxies = defaultdict(<bound method ProxiesDict.__default_factory__ of defaultdict(..., {})>, {})
TangoCommand.execute(args=None, timeout=None, feedback=None, expected=None, wait=None, asynch=None)[source]
TangoCommand.trace(msg, severity='DEBUG')[source]
class fandango.tango.TangoEval(formula='', launch=True, timeout=1000, keeptime=100, trace=False, proxies=None, attributes=None, cache=0, use_events=False, event_hook=None, **kwargs)[source]

Bases: object

Class for Tango formula evaluation; used by Panic-like formulas

example:
  te = fandango.TangoEval(cache=3)
  te.eval('test/sim/test-00/A * test/sim/test-00/S.delta')
  Out: 2.6307095848792521 #A value multiplied by delta of S in its last 3 values

Attributes in the formulas may be (it is recommended to insert spaces between attribute names and operators): THIS REGULAR EXPRESSIONS DOES NOT MATCH THE HOST IN THE FORMULA!!!; IT IS TAKEN AS PART OF THE DEVICE NAME!!

dom/fam/memb/attrib >= V1 #Will evaluate the attribute value
d/f/m/a1 > V2 and d/f/m/a2 == V3 #Comparing 2 attributes
d/f/m.quality != QALARM #Using attribute quality
d/f/m/State == UNKNOWN #States can be compared directly
d/f/m/A.exception #True if exception occurred
d/f/m/A.time #Attribute value time
d/f/m/A.value #Explicit value
d/f/m/A.delta #Increase/decrease of the value since the first value in cache (if cache and cache_depth are set)
d/f/m/A.all #Instead of just value will return an AttributeValue object 

All tango-like variables are parsed. TangoEval.macros can be used to do regexp-based substitution. By default FIND(regexp) will be replaced by a list of matching attributes.

FIND([a-zA-Z0-9/].*) macro allows to get any attribute matching a regular expression Any variable in _locals is evaluated or explicitly replaced in the formula if matches $(); e.g. FIND($(VARNAME)//) T() < T(‘YYYY/MM/DD hh:mm’) allow to compare actual time with any time
Use_events:will manage events using the callbacks.EventSource object. It will redirect

all events to TangoEval.eventReceived method. If an event_hook callback is passed as argument, both TangoEval object and result of eval will be sent to it.

eval() will be triggered by events only if event_hook is True or a callable

FIND_EXP = 'FIND\\(((?:[ \'"])?[^)]*(?:[ \'"])?)\\)'
add_macro(macro_name, macro_expression, macro_function)[source]

Add a new macro to be parsed by parse_formula. It will apply macro_function to the target found by macro_expression; the result will later replace macro_name%target

e.g: self.add_macro(‘FIND(%s)’,self.FIND_EXP,self.find_macro) #where FIND_EXP = ‘FIND(((?:[ ‘”])?[^)]*(?:[ ‘”])?))’

alnum = '[a-zA-Z0-9-_]+'
eval(formula=None, previous=None, _locals=None, _raise=None)[source]

Evaluates the given formula. Previous can be used to add extra local values, or predefined values for attributes ({‘a/b/c/d’:1} that would override its reading Any variable in locals is evaluated or explicitly replaced in the formula if appearing with brackets (e.g. FIND({VARNAME}//)) :param _raise: if attribute is empty or ‘State’ exceptions will be rethrown

eventReceived(src, type_, value)[source]

Method to implement the event notification Source will be an object, type a PyTango EventType, evt_value an AttrValue Regarding PANIC, the eventReceived hook must be in the PanicAPI, not here

find_macro(target)[source]

Gets a match of FIND_EXP and applies get_matching_attributes to the expresion found.

get_delta(target)[source]

target = (device+’/’+attribute).lower() ; returns difference between first and last cached value

no_alnum = '[^a-zA-Z0-9-_]'
no_quotes = '(?:^|$|[^\'"a-zA-Z0-9_\\./])'
parse_formula(formula, _locals=None)[source]

This method just removes comments and applies self.macros (e.g FIND()) searches in the formula; In this method there is no tango check, neither value replacement

parse_tag(target, wildcard='_')[source]
parse_variables(formula, _locals=None, parsed=False)[source]

This method parses attributes declarated in formulas with the following formats: TAG1: dom/fam/memb/attrib >= V1 #A comment TAG2: d/f/m/a1 > V2 and d/f/m/a2 == V3 TAG3: d/f/m.quality != QALARM #Another comment TAG4: d/f/m/State ##A description?, Why not :return:

  • a None value if the alarm is not parsable
  • a list of (device,attribute,value/time/quality) tuples
read_attribute(device, attribute='', what='', _raise=True, timeout=None)[source]

Executes a read_attribute and returns the value requested :param _raise: if attribute is empty or ‘State’ exceptions will be rethrown

reattr = '(?:/(?P<attribute>[a-zA-Z0-9-_]+)(?:(?:\\.)(?P<what>quality|time|value|exception|delta|all|hist))?)?'
redev = '(?P<device>(?:[a-zA-Z0-9-_]+:[0-9]+/{1,2})?(?:[a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+))'
regexp = '(?:^|$|[^\'"a-zA-Z0-9_\\./])(?P<device>(?:[a-zA-Z0-9-_]+:[0-9]+/{1,2})?(?:[a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+))(?:/(?P<attribute>[a-zA-Z0-9-_]+)(?:(?:\\.)(?P<what>quality|time|value|exception|delta|all|hist))?)?(?=^|$|[^\'"a-zA-Z0-9_/])'
retango = '(?P<device>(?:[a-zA-Z0-9-_]+:[0-9]+/{1,2})?(?:[a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+))(?:/(?P<attribute>[a-zA-Z0-9-_]+)(?:(?:\\.)(?P<what>quality|time|value|exception|delta|all|hist))?)?'
set_timeout(timeout)[source]
trace(msg)[source]
update_locals(dct=None)[source]
class fandango.tango.TangoedValue[source]

Bases: object

fandango.tango.add_new_device(server, klass, device)[source]
fandango.tango.attr2str(attr_value)[source]
fandango.tango.cast_tango_type(value_type)[source]

Returns the python equivalent to a Tango type

fandango.tango.check_attribute(attr, readable=False, timeout=0, brief=False, trace=False)[source]

checks if attribute is available. :param readable: Whether if it’s mandatory that the attribute returns a value or if it must simply exist. :param timeout: Checks if the attribute value have been effectively updated (check zombie processes). :param brief: return just .value instead of AttrValue object

fandango.tango.check_device(dev, attribute=None, command=None, full=False, admin=False, bad_state=False)[source]

Command may be ‘StateDetailed’ for testing HdbArchivers It will return True for devices ok, False for devices not running and None for unresponsive devices.

fandango.tango.check_device_list(devices, attribute=None, command=None)[source]

This method will check a list of devices grouping them by host and server; minimizing the amount of pings to do.

fandango.tango.check_host(host)[source]

Pings a hostname, returns False if unreachable

fandango.tango.check_property_extensions(prop, value, db=None, extensions={'@COPY:': <function _copy_extension at 0x7eff574f8de8>, '@FILE:': <function _file_extension at 0x7eff574f8e60>, '@ATTR:': <function _attr_extension at 0x7eff574f8ed8>}, filters=[])[source]
fandango.tango.check_starter(host)[source]

Checks host’s Starter server

fandango.tango.export_attribute_to_dict(model, attribute=None, value=None, keep=False, as_struct=False)[source]

get attribute config, format and value from Tango and return it as a dictionary:

Parameters:model – can be a full tango model, a device name or a device proxy
keys: min_alarm,name,data_type,format,max_alarm,ch_event,data_format,value,
label,writable,device,polling,alarms,arch_event,unit
fandango.tango.export_commands_to_dict(device, target='*')[source]

export all device commands config to a dictionary

fandango.tango.export_device_to_dict(device, commands=True, properties=True)[source]

This method can be used to export the current configuration of devices, attributes and properties to a file. The dictionary will get properties, class properties, attributes, commands, attribute config, event config, alarm config and pollings.

fandango.tango.export_properties_to_dict(device, target='*')[source]

export device or class properties to dictionary

class fandango.tango.fakeAttributeValue(name, value=None, time_=0.0, quality=PyTango._PyTango.AttrQuality.ATTR_VALID, dim_x=1, dim_y=1, parent=None, device='', error=False, keeptime=0)[source]

Bases: object

This class simulates a modifiable AttributeValue object (not available in PyTango) It is the class used to read values from Dev4Tango devices (valves, pseudos, composer, etc ...) It also has a read(cache) method to be used as a TaurusAttribute or AttributeProxy (but it returns self if cache is not used) The cache is controlled by keeptime variable (milliseconds) :param parent: Apart of common Attribute arguments, parent will be used to keep a proxy to the parent object (a DeviceProxy or DeviceImpl)

get_date()[source]
get_name()[source]
get_quality()[source]
get_time()[source]
get_value()[source]
get_write_value(data=None)[source]
read(cache=True)[source]
set_date(timestamp)[source]
set_quality(quality)[source]
set_value(value, dim_x=1, dim_y=1)[source]
set_value_date(value, date)[source]
set_value_date_quality(value, date, quality)[source]
set_write_value(value)[source]
throw_exception(msg='')[source]
class fandango.tango.fakeEvent(device, attr_name, attr_value, err, errors)[source]

Bases: object

fandango.tango.find_attributes(*args, **kwargs)[source]
fandango.tango.find_devices(*args, **kwargs)[source]
fandango.tango.getTangoValue(obj, device=None)[source]

This method may be used to return objects from read_attribute or FIND() that are still computable and keep quality/time members try to avoid spectrums.; this method doesn’t work for numpy arrays so I have to convert them to less efficient lists.

fandango.tango.get_alias_dict(exp='*')[source]

returns an {alias:device} dictionary with all matching alias from Tango DB :param exp:

fandango.tango.get_alias_for_device(dev)[source]

return alias for this device

class fandango.tango.get_all_devices(exported=False, keeptime=None, host='')[source]

Bases: fandango.objects.SingletonMap

get_all_devs()[source]
classmethod set_keeptime(klass, keeptime)[source]
fandango.tango.get_all_models(expressions, limit=1000)[source]

Customization of get_matching_attributes to be usable in Taurus widgets. It returns all the available Tango attributes (exported!) matching any of a list of regular expressions.

fandango.tango.get_attribute_config(target)[source]
fandango.tango.get_attribute_events(target, polled=True, throw=False)[source]
fandango.tango.get_attribute_info(device, attribute)[source]

This method returns attribute info in the attr_list format It parses values returned by PyTango.DeviceProxy(device).get_attribute_config(attribute) return format:

[[PyTango.DevString, PyTango.SPECTRUM, PyTango.READ_WRITE, 2], {

‘unit’:”mbar”, ‘format’:”%4d”,

}],

fandango.tango.get_attribute_label(target, use_db=True)[source]
fandango.tango.get_attribute_time(value)[source]
fandango.tango.get_class_devices(klass, db=None)[source]

Returns all registered devices for a given class

fandango.tango.get_class_property(klass, property, db=None)[source]

It returns class property value or just first item if value list has lenght==1

fandango.tango.get_database(host='', port='', use_tau=False)[source]

Method to get a singleton instance of the Tango Database host/port can be a host,port tuple; a ‘host:port’ string or a taurus model. @TODO: host/port is checked only at first creation, once initialized you can’t change HOST

fandango.tango.get_database_device(use_tau=False, db=None)[source]
fandango.tango.get_device(dev, use_tau=False, keep=False)[source]
fandango.tango.get_device_attributes(dev, expressions='*')[source]

Given a device name it returns the attributes matching any of the given expressions

fandango.tango.get_device_commands(dev)[source]

returns a list of device command names

fandango.tango.get_device_for_alias(alias)[source]

returns the device name for a given alias

fandango.tango.get_device_help(self, str_format='text')[source]

This command returns help text for this device class and its parents

fandango.tango.get_device_host(dev)[source]

Asks the Database device server about the host of this device

fandango.tango.get_device_info(dev, db=None)[source]

This method provides an alternative to DeviceProxy.info() for those devices that are not running

fandango.tango.get_device_labels(target, filters='*', brief=True)[source]

Returns an {attr:label} dict for all attributes of this device Filters will be a regular expression to apply to attr or label. If brief is True (default) only those attributes with label are returned. This method works offline, does not need device to be running

fandango.tango.get_device_property(device, property, db=None)[source]

It returns device property value or just first item if value list has lenght==1

fandango.tango.get_device_started(target)[source]

Returns device started time

fandango.tango.get_devices_properties('*alarms*',props,hosts=[get_bl_host(i) for i in bls])[source]

props must be an string as passed to Database.get_device_property(); regexp are not enabled! get_matching_device_properties enhanced with multi-host support @TODO: Compare performance of this method with get_matching_device_properties

fandango.tango.get_distinct_attributes(attrs)[source]

It returns a list with the distinc attribute names (excluding device) appearing in a list

fandango.tango.get_distinct_devices(attrs)[source]

It returns a list with the distinct device names appearing in a list

fandango.tango.get_distinct_domains(attrs)[source]

It returns a list with the distinc member names appearing in a list

fandango.tango.get_distinct_families(attrs)[source]

It returns a list with the distinc member names appearing in a list

fandango.tango.get_distinct_members(attrs)[source]

It returns a list with the distinc member names appearing in a list

fandango.tango.get_domain(model)[source]
fandango.tango.get_extension_arg(x)[source]
fandango.tango.get_family(model)[source]
fandango.tango.get_full_name(model)[source]

Returns full schema name as needed by HDB++ api

fandango.tango.get_internal_devices()[source]

Gets all devices declared in the current Tango server

fandango.tango.get_matching_attributes(expressions, limit=0, fullname=None, trace=False)[source]

Returns all matching device/attribute pairs. regexp only allowed in attribute names :param expressions: a list of expressions like [domain_wild/family_wild/member_wild/attribute_regexp]

fandango.tango.get_matching_device_attribute_labels(device, attribute)[source]

To get all gauge port labels: get_matching_device_attribute_labels(‘vgct‘,’p*’)

fandango.tango.get_matching_device_properties(devs, props, hosts=[], exclude='*dserver*', port=10000, trace=False)[source]

get_matching_device_properties enhanced with multi-host support @props: regexp are enabled! get_devices_properties(‘alarms‘,props,hosts=[get_bl_host(i) for i in bls]) @TODO: Compare performance of this method with get_devices_properties

fandango.tango.get_matching_devices(expressions, limit=0, exported=False, fullname=False, trace=False)[source]

Searches for devices matching expressions, if exported is True only running devices are returned Tango host will be included in the matched name if fullname is True

fandango.tango.get_matching_servers(expressions, tango_host='', exported=False)[source]

Return all servers in the given tango tango_host matching the given expressions. :param exported: whether servers should be running or not

fandango.tango.get_member(model)[source]
fandango.tango.get_model_name(model)[source]
fandango.tango.get_polled_attrs(device, others=None)[source]

@TODO: Tango8 has its own get_polled_attr method; check for incompatibilities if a device is passed, it returns the polled_attr property as a dictionary if a list of values is passed, it converts to dictionary others argument allows to get extra property values in a single DB call; e.g others = [‘polled_cmd’] would append the polled commands to the list

fandango.tango.get_property_history(dev, prop)[source]
fandango.tango.get_proxy(argin, use_tau=False, keep=False)[source]

Returns attribute or device proxy depending on argin syntax

fandango.tango.get_real_name(dev, attr=None)[source]

It translate any device/attribute string by name/alias/label

Parameters:
  • device – Expected format is [host:port/][device][/attribute]; where device can be either a/b/c or alias
  • attr – optional, when passed it will be regexp matched against attributes/labels
fandango.tango.get_server_pid(server)[source]
fandango.tango.get_server_property(name, instance, prop)[source]
fandango.tango.get_tango_host(dev_name='', use_db=False)[source]

If device is a tango model, it will extract the host from the model URL If devicesis none, then environment variable or PyTango.Database are used to extract the host If TANGO_HOST is not defined it will always fallback to PyTango.Database()

fandango.tango.loadTaurus()[source]
fandango.tango.parse_db_command_array(data, keys=1, depth=2)[source]

This command will parse data received from DbGetDeviceAttributeProperty2 command. DB device commands return data in this format: X XSize Y YSize Z ZSize ZValue W WSize WValue This corresponds to {X:{Y:{Z:[Zdata],W:[Wdata]}}} Depth of the array is 2 by default e.g.: label_of_dev_test_attribute = parse_db_command_array(dbd.DbGetDeviceAttributeProperty2([dev,attr]).,keys=1,depth=2)[dev][attr][‘label’][0]

fandango.tango.parse_labels(text)[source]
fandango.tango.parse_tango_model(name, use_tau=False, use_host=False)[source]

{‘attributename’: ‘state’, ‘attribute’: ‘state’, ‘devicename’: ‘bo01/vc/ipct-01’, #Always short name ‘device’: ‘cts:10000/bo01/vc/ipct-01’, #Will contain host if use_host or host!=TANGO_HOST ‘host’: ‘cts’, ‘port’: ‘10000’, ‘scheme’: ‘tango’}

fandango.tango.property_undo(dev, prop, epoch)[source]
fandango.tango.put_class_property(klass, property, value=None, db=None)[source]
Two syntax are possible:
  • put_class_property(class,{property:value})
  • put_class_property(class,property,value)
fandango.tango.put_device_property(device, property, value=None, db=None)[source]
Two syntax are possible:
  • put_device_property(device,{property:value})
  • put_device_property(device,property,value)
fandango.tango.read_attribute(attr, timeout=0, full=False)[source]

Alias to check_attribute(attr,brief=True)

fandango.tango.read_internal_attribute(device, attribute)[source]
This method allows several things:
  • If a device object (Impl or Proxy) is given, it is used to read the attribute
  • If the attribute belongs to a device in the SAME SERVER, it accesses directly to the device object
  • If the attribute belongs to an external SERVER, use PyTango proxies to read it
  • It can manage dynamic attributes used within the same SERVER calling read_dyn_attr

device must be a DevImpl object or string, attribute must be an string if the device is not internal this method will connect to a PyTango Proxy the method will return a fakeAttributeValue object

fandango.tango.reduce_distinct(group1, group2)[source]

It returns a list of (device,domain,family,member,attribute) keys that appear in group1 and not in group2

fandango.tango.set_attribute_label(target, label='', unit='')[source]
fandango.tango.set_device_labels(target, labels)[source]

Applies an {attr:label} dict for attributes of this device