The following script runs through all attributes of a TangoDB and identifies those that have the %6.2f format in their configuration. It changes this format to %g.
#!/usr/bin/env python
""" attrConfig.py changes the attribute configuration from '%6.2f' to '%g' """
import sys
import PyTango
import HasyUtils
from optparse import OptionParser
usage = "%prog [-x] [-c]\n" + \
" Changes the attribute configuration from '%6.2f' to '%g'"
parser = OptionParser(usage=usage)
parser.add_option( "-c", action="store_true", dest="classlist",
default = False, help="display classlist (harmless)")
parser.add_option( "-d", action="store_true", dest="dryrun",
default = False, help="dry run (harmless)")
parser.add_option( "-x", action="store_true", dest="execute",
default = False, help="really execute (not harmless)")
(options, args) = parser.parse_args()
#
# 'dry-run' and 'execute', both cannot by True
#
if options.dryrun and options.execute:
parser.print_help()
sys.exit(255)
#
# nothing specified, print help and exit
#
if not options.classlist and not options.dryrun and not options.execute:
parser.print_help()
sys.exit(255)
#
# get all classes
#
classList = HasyUtils.getClassList()
#
# the class list is printed as an array [ 'Motor', 'OmsVme58', ...]
#
if options.classlist:
print( "Classes on", HasyUtils.getHostList())
print( classList)
sys.exit(0)
#
# you may wish to find all classes with './attrConfig.py -c' and
# then limit the action to selected classes, like
#
# classList = [ 'GalilDMCSlit', 'Motor', 'OmsVme58', 'PseudoAxes', 'PseudoAxis', 'TangoMotor','VmExecutor']
#
for clss in classList:
print( clss)
if options.classlist:
continue
devs = HasyUtils.getDeviceNamesByClass( clss)
for dev in devs:
print( " %s" % str(dev))
try:
proxy = PyTango.DeviceProxy( dev)
attrs = proxy.get_attribute_list()
except:
continue
for attr in attrs:
attrInfo = proxy.get_attribute_config( attr)
if attrInfo.format == "%6.2f":
print( " %s " % attrInfo.name, attrInfo.format)
if options.execute is True:
print( " from '%6.2f' to '%g'")
attrInfo.format = "%g"
proxy.set_attribute_config( attrInfo)
elif options.dryrun is True:
print( " would change '%6.2f' to '%g'")