[pytango] 375/483: Continuing implementation
Sandor Bodo-Merle
sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:15:01 UTC 2017
This is an automated email from the git hooks/post-receive script.
sbodomerle-guest pushed a commit to annotated tag bliss_8.10
in repository pytango.
commit d535eed497e9a89303a893aed7b4b5a4f126c80a
Author: tere29 <tere29 at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date: Thu Apr 17 08:39:59 2014 +0000
Continuing implementation
git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@25385 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
src/boost/python/databaseds/database.py | 591 +++++++++++++++--
src/boost/python/databaseds/db_access.py | 1070 +++++++++++++++++++++++++++++-
2 files changed, 1601 insertions(+), 60 deletions(-)
diff --git a/src/boost/python/databaseds/database.py b/src/boost/python/databaseds/database.py
index f0cb5a1..e362459 100644
--- a/src/boost/python/databaseds/database.py
+++ b/src/boost/python/databaseds/database.py
@@ -33,6 +33,9 @@ __docformat__ = 'restructuredtext'
import PyTango
import sys
# Add additional import
+
+import time
+
#----- PROTECTED REGION ID(DataBase.additionnal_import) ENABLED START -----#
import logging
@@ -99,6 +102,18 @@ def replace_wildcard(text):
text = text.replace("*", "%")
return text
+class TimeStructure:
+ def __init__(self):
+ self.average = 0
+ self.minimum = 0
+ self.maximum = 0
+ self.maximum = 0
+ self.total_elapsed = 0
+ self.calls = 0
+ self.index = ''
+
+
+cmd_list = ["DbImportDevice", "DbExportDevice", "DbGetHostServerList", "DbGetHostList","DbGetServerList", "DbGetDevicePropertyList", "DbGetClassPropertyList", "DbGetDeviceMemberList", "DbGetDeviceFamilyList", "DbGetDeviceDomainList", "DbGetDeviceProperty", "DbPutDeviceProperty", "DbDeleteDeviceProperty", "DbInfo", "DbGetDeviceClassList", "DbGetDeviceAttributeProperty", "DbPutDeviceAttributeProperty", "DbGetDeviceAttributeProperty2", "DbPutDeviceAttributeProperty2", "DbUnExportServer", " [...]
#----- PROTECTED REGION END -----# // DataBase.additionnal_import
@@ -111,6 +126,24 @@ def replace_wildcard(text):
class DataBase (PyTango.Device_4Impl):
#--------- Add you global variables here --------------------------
+
+ def update_timing_stats(self, time_before, time_after, cmd_name):
+ tmp_time = self.timing_maps[cmd_name]
+ time_elapsed = (time_after - time_before) * 1000.
+ tmp_time.total_elapsed = tmp_time.total_elapsed + time_elapsed
+ if time_elapsed > tmp_time.maximum:
+ tmp_time.maximum = time_elapsed
+ if time_elapsed < tmp_time.minimum or tmp_time.minimum == 0:
+ tmp_time.minimum = time_elapsed
+ tmp_time.calls = tmp_time.calls + 1
+ tmp_time.average = tmp_time.total_elapsed/tmp_time.calls
+
+ def init_timing_stats(self):
+ self.timing_maps = {}
+ for cmd in cmd_list:
+ self.timing_maps[cmd] = TimeStructure()
+ self.timing_maps[cmd].index = cmd
+
#----- PROTECTED REGION ID(DataBase.global_variables) ENABLED START -----#
def get_device_properties(self, device_klass):
@@ -147,10 +180,13 @@ class DataBase (PyTango.Device_4Impl):
self.attr_Timing_calls_read = [0.0]
self.attr_Timing_index_read = ['']
self.attr_Timing_info_read = ['']
+ self.init_timing_stats()
#----- PROTECTED REGION ID(DataBase.init_device) ENABLED START -----#
self.db = db_access.Tango_sqlite3()
+ self.set_state(PyTango.DevState.ON)
+
logging.info("Finished init_device")
#----- PROTECTED REGION END -----# // DataBase.init_device
@@ -186,6 +222,10 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".read_Timing_average()")
#----- PROTECTED REGION ID(DataBase.Timing_average_read) ENABLED START -----#
+ self.attr_Timing_average_read[:] = []
+ for tmp_name in cmd_list:
+ self.attr_Timing_average_read.append(self.timing_maps[tmp_name].average)
+
#----- PROTECTED REGION END -----# // DataBase.Timing_average_read
attr.set_value(self.attr_Timing_average_read)
@@ -196,6 +236,10 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".read_Timing_minimum()")
#----- PROTECTED REGION ID(DataBase.Timing_minimum_read) ENABLED START -----#
+ self.attr_Timing_minimum_read[:] = []
+ for tmp_name in cmd_list:
+ self.attr_Timing_minimum_read.append(self.timing_maps[tmp_name].minimum)
+
#----- PROTECTED REGION END -----# // DataBase.Timing_minimum_read
attr.set_value(self.attr_Timing_minimum_read)
@@ -206,6 +250,10 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".read_Timing_maximum()")
#----- PROTECTED REGION ID(DataBase.Timing_maximum_read) ENABLED START -----#
+ self.attr_Timing_maximum_read[:] = []
+ for tmp_name in cmd_list:
+ self.attr_Timing_maximum_read.append(self.timing_maps[tmp_name].maximum)
+
#----- PROTECTED REGION END -----# // DataBase.Timing_maximum_read
attr.set_value(self.attr_Timing_maximum_read)
@@ -216,6 +264,10 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".read_Timing_calls()")
#----- PROTECTED REGION ID(DataBase.Timing_calls_read) ENABLED START -----#
+ self.attr_Timing_calls_read[:] = []
+ for tmp_name in cmd_list:
+ self.attr_Timing_calls_read.append(self.timing_maps[tmp_name].calls)
+
#----- PROTECTED REGION END -----# // DataBase.Timing_calls_read
attr.set_value(self.attr_Timing_calls_read)
@@ -226,6 +278,9 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".read_Timing_index()")
#----- PROTECTED REGION ID(DataBase.Timing_index_read) ENABLED START -----#
+ for tmp_name in cmd_list:
+ self.attr_Timing_index_read.append(self.timing_maps[tmp_name].index)
+
#----- PROTECTED REGION END -----# // DataBase.Timing_index_read
attr.set_value(self.attr_Timing_index_read)
@@ -235,7 +290,17 @@ class DataBase (PyTango.Device_4Impl):
def read_Timing_info(self, attr):
self.debug_stream("In " + self.get_name() + ".read_Timing_info()")
#----- PROTECTED REGION ID(DataBase.Timing_info_read) ENABLED START -----#
-
+ self.attr_Timing_info_read[:] = []
+ util = PyTango.Util.instance()
+ self.attr_Timing_info_read.append("TANGO Database Timing info on host " + util.get_host_name())
+ self.attr_Timing_info_read.append(" ")
+ self.attr_Timing_info_read.append("command average minimum maximum calls")
+ self.attr_Timing_info_read.append(" ")
+
+
+ for tmp_name in cmd_list:
+ tmp_info = "%41s\t%6.3f\t%6.3f\t%6.3f\t%.0f"%(tmp_name, self.timing_maps[tmp_name].average, self.timing_maps[tmp_name].minimum, self.timing_maps[tmp_name].maximum, self.timing_maps[tmp_name].calls)
+ self.attr_Timing_info_read.append(tmp_info)
#----- PROTECTED REGION END -----# // DataBase.Timing_info_read
attr.set_value(self.attr_Timing_info_read)
@@ -318,8 +383,6 @@ class DataBase (PyTango.Device_4Impl):
"DataBase::AddServer()")
server_name = argin[0]
- db = self.db
- cursor = db.get_cursor()
for i in range((len(argin) - 1) / 2):
d_name, klass_name = argin[i * 2 + 1], argin[i * 2 + 2]
ret, dev_name, dfm = check_device_name(d_name)
@@ -327,10 +390,9 @@ class DataBase (PyTango.Device_4Impl):
th_exc(DB_IncorrectDeviceName,
"device name (" + d_name + ") syntax error (should be [tango:][//instance/]domain/family/member)",
"DataBase::AddServer()")
- db.add_device(server_name, (dev_name, dfm) , klass_name, cursor=cursor)
+ self.db.add_device(server_name, (dev_name, dfm) , klass_name)
+
- cursor.connection.commit()
- cursor.close()
#----- PROTECTED REGION END -----# // DataBase.DbAddServer
@@ -401,12 +463,8 @@ class DataBase (PyTango.Device_4Impl):
klass_name, attr_name = argin[:2]
- db = self.db
- cursor = db.get_cursor()
for prop_name in argin[2:]:
- db.delete_class_attribute_property(klass_name, attr_name, prop_name, cursor=cursor)
- cursor.connection.commit()
- cursor.close()
+ self.db.delete_class_attribute_property(klass_name, attr_name, prop_name)
#----- PROTECTED REGION END -----# // DataBase.DbDeleteClassAttributeProperty
@@ -427,12 +485,8 @@ class DataBase (PyTango.Device_4Impl):
klass_name = argin[0]
- db = self.db
- cursor = db.get_cursor()
for prop_name in argin[1:]:
- db.delete_class_property(prop_name, cursor=cursor)
- cursor.connection.commit()
- cursor.close()
+ self.db.delete_class_property(prop_name)
#----- PROTECTED REGION END -----# // DataBase.DbDeleteClassProperty
@@ -500,7 +554,7 @@ class DataBase (PyTango.Device_4Impl):
ret, dev_name, dfm = check_device_name(argin)
if not ret:
- self.warn_stream("DataBase::db_delete_device_attribute(): device name " + dev_name + " incorrect ")
+ self.warn_stream("DataBase::db_delete_device_attribute(): device name " + argin + " incorrect ")
th_exc(DB_IncorrectDeviceName,
"failed to delete device attribute, device name incorrect",
"DataBase::DeleteDeviceAttribute()")
@@ -535,17 +589,14 @@ class DataBase (PyTango.Device_4Impl):
ret, dev_name, dfm = check_device_name(argin)
if not ret:
- self.warn_stream("DataBase::db_delete_device_attribute_property(): device name " + dev_name + " incorrect ")
+ self.warn_stream("DataBase::db_delete_device_attribute_property(): device name " + argin + " incorrect ")
th_exc(DB_IncorrectDeviceName,
"failed to delete device attribute property, device name incorrect",
"DataBase::DeleteDeviceAttributeProperty()")
- db = self.db
- cursor = db.get_cursor()
+
for prop_name in argin[2:]:
- self.db.delete_device_attribute_property(dev_name, attr_name, prop_name, cursor=cursor)
- cursor.connection.commit()
- cursor.close()
+ self.db.delete_device_attribute_property(dev_name, attr_name, prop_name)
@@ -566,13 +617,14 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbDeleteDeviceProperty()")
#----- PROTECTED REGION ID(DataBase.DbDeleteDeviceProperty) ENABLED START -----#
+ time_before = time.time()
+
dev_name = argin[0]
- db = self.db
- cursor = db.get_cursor()
for prop_name in argin[1:]:
self.db.delete_device_property(dev_name, prop_name)
- cursor.connection.commit()
- cursor.close()
+
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbDeleteDeviceProperty")
#----- PROTECTED REGION END -----# // DataBase.DbDeleteDeviceProperty
@@ -591,13 +643,9 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbDeleteProperty()")
#----- PROTECTED REGION ID(DataBase.DbDeleteProperty) ENABLED START -----#
- obj_name = argin[0];
- db = self.db
- cursor = db.get_cursor()
+ obj_name = argin[0]
for prop_name in argin[1:]:
self.db.delete_property(obj_name, prop_name)
- cursor.connection.commit()
- cursor.close()
#----- PROTECTED REGION END -----# // DataBase.DbDeleteProperty
@@ -657,7 +705,7 @@ class DataBase (PyTango.Device_4Impl):
:rtype: PyTango.DevVoid """
self.debug_stream("In " + self.get_name() + ".DbExportDevice()")
#----- PROTECTED REGION ID(DataBase.DbExportDevice) ENABLED START -----#
-
+ time_before = time.time()
if len(argin) < 5:
self.warn_stream("DataBase::DbExportDevice(): insufficient export info for device ")
th_exc(DB_IncorrectArguments,
@@ -665,9 +713,12 @@ class DataBase (PyTango.Device_4Impl):
"DataBase::ExportDevice()")
dev_name, IOR, host, pid, version = argin[:5]
+ dev_name = dev_name.lower()
if pid.lower() == 'null':
pid = "-1"
self.db.export_device(dev_name, IOR, host, pid, version)
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbExportDevice")
#----- PROTECTED REGION END -----# // DataBase.DbExportDevice
@@ -688,6 +739,7 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbExportEvent()")
#----- PROTECTED REGION ID(DataBase.DbExportEvent) ENABLED START -----#
+ time_before = time.time()
if len(argin) < 5:
self.warn_stream("DataBase::db_export_event(): insufficient export info for event ")
th_exc(DB_IncorrectArguments,
@@ -697,6 +749,8 @@ class DataBase (PyTango.Device_4Impl):
event, IOR, host, pid, version = argin[:5]
event = replace_wildcard(event.lower())
self.db.export_event(event, IOR, host, pid, version)
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbExportEvent")
#----- PROTECTED REGION END -----# // DataBase.DbExportEvent
@@ -785,10 +839,7 @@ class DataBase (PyTango.Device_4Impl):
#----- PROTECTED REGION ID(DataBase.DbGetClassAttributeList) ENABLED START -----#
class_name = argin[0]
- if len(argin) > 1:
- wildcard = replace_wildcard(argin[1])
- else:
- wildcard = "%"
+ wildcard = replace_wildcard(argin[1])
argout = self.db.get_class_attribute_list(class_name, wildcard)
@@ -817,7 +868,7 @@ class DataBase (PyTango.Device_4Impl):
#----- PROTECTED REGION ID(DataBase.DbGetClassAttributeProperty) ENABLED START -----#
class_name = argin[0]
- argout = self.db.get_class_attribute_property(clas_name, argout[1:])
+ argout = self.db.get_class_attribute_property(class_name, argin[1:])
#----- PROTECTED REGION END -----# // DataBase.DbGetClassAttributeProperty
return argout
@@ -850,7 +901,7 @@ class DataBase (PyTango.Device_4Impl):
#----- PROTECTED REGION ID(DataBase.DbGetClassAttributeProperty2) ENABLED START -----#
class_name = argin[0]
- argout = self.db.get_class_attribute_property2(clas_name, argout[1:])
+ argout = self.db.get_class_attribute_property2(class_name, argin[1:])
#----- PROTECTED REGION END -----# // DataBase.DbGetClassAttributeProperty2
return argout
@@ -875,7 +926,10 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbGetClassAttributePropertyHist()")
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetClassAttributePropertyHist) ENABLED START -----#
-
+ class_name = argin[0]
+ attribute = replace_wildcard(argin[1])
+ prop_name = replace_wildcard(argin[2])
+ argout = self.db.get_class_attribute_property_hist(class_name, attribute, prop_name)
#----- PROTECTED REGION END -----# // DataBase.DbGetClassAttributePropertyHist
return argout
@@ -962,6 +1016,8 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetClassProperty) ENABLED START -----#
+ class_name = argin[0]
+ argout = self.db.get_class_property(class_name,argint[1:])
#----- PROTECTED REGION END -----# // DataBase.DbGetClassProperty
return argout
@@ -984,6 +1040,10 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetClassPropertyHist) ENABLED START -----#
+ class_name = argin[0]
+ prop_name = argin[1]
+ argout = self.db.get_class_property_hist(class_name, prop_name)
+
#----- PROTECTED REGION END -----# // DataBase.DbGetClassPropertyHist
return argout
@@ -1000,6 +1060,16 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbGetClassPropertyList()")
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetClassPropertyList) ENABLED START -----#
+ time_before = time.time()
+ if not argin:
+ argin = "%"
+ else:
+ argin = replace_wildcard(argin)
+
+ argout = self.db.get_class_property_list(argin)
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbDeleteDeviceProperty")
+
#----- PROTECTED REGION END -----# // DataBase.DbGetClassPropertyList
return argout
@@ -1018,6 +1088,15 @@ class DataBase (PyTango.Device_4Impl):
argout = ''
#----- PROTECTED REGION ID(DataBase.DbGetDeviceAlias) ENABLED START -----#
+ ret, dev_name, dfm = check_device_name(argin)
+ if not ret:
+ th_exc(DB_IncorrectDeviceName,
+ "device name (" + argin + ") syntax error (should be [tango:][//instance/]domain/family/member)",
+ "DataBase::DbGetDeviceAlias()")
+
+ argout = self.db.get_device_alias(dev_name)
+
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceAlias
return argout
@@ -1034,6 +1113,12 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbGetDeviceAliasList()")
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDeviceAliasList) ENABLED START -----#
+ if not argin:
+ argin = "%"
+ else:
+ argin = replace_wildcard(argin)
+
+ argout = self.db.get_device_alias_list(argin)
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceAliasList
return argout
@@ -1054,6 +1139,15 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDeviceAttributeList) ENABLED START -----#
+ dev_name = argin[0]
+ wildcard = argin[1]
+ if not wildcard:
+ wildcard = "%"
+ else:
+ wildcard = replace_wildcard(wildcard)
+
+ argout = self.db.get_device_attribute_list(dev_name, wildcard)
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceAttributeList
return argout
@@ -1077,6 +1171,11 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbGetDeviceAttributeProperty()")
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDeviceAttributeProperty) ENABLED START -----#
+ time_before = time.time()
+ dev_name = argin[0]
+ argout = self.db.get_device_attribute_property(class_name, argin[1:])
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbGetDeviceAttributeProperty")
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceAttributeProperty
return argout
@@ -1109,6 +1208,13 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDeviceAttributeProperty2) ENABLED START -----#
+ time_before = time.time()
+
+ dev_name = argin[0]
+ argout = self.db.get_device_attribute_property2(class_name, argin[1:])
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbGetDeviceAttributeProperty2")
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceAttributeProperty2
return argout
@@ -1133,6 +1239,11 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDeviceAttributePropertyHist) ENABLED START -----#
+ dev_name = argin[0]
+ attribute = replace_wildcard(argin[1])
+ prop_name = replace_wildcard(argin[2])
+ argout = self.db.get_device_attribute_property_hist(dev_name, attribute, prop_name)
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceAttributePropertyHist
return argout
@@ -1153,6 +1264,12 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDeviceClassList) ENABLED START -----#
+ time_before = time.time()
+
+ argout = self.db.get_device_class_list(argin)
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbGetDeviceClassList")
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceClassList
return argout
@@ -1170,6 +1287,12 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDeviceDomainList) ENABLED START -----#
+ time_before = time.time()
+ argin = replace_wildcard(argin)
+ argout = self.db.get_device_domain_list(argin)
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbGetDeviceDomainList")
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceDomainList
return argout
@@ -1187,6 +1310,14 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDeviceExportedList) ENABLED START -----#
+ time_before = time.time()
+
+ argin = replace_wildcard(argin)
+ argout = self.db.get_device_exported_list(argin)
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbGetDeviceExportedList")
+
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceExportedList
return argout
@@ -1205,6 +1336,13 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDeviceFamilyList) ENABLED START -----#
+ time_before = time.time()
+
+ argin = replace_wildcard(argin)
+ argout = self.db.get_device_family_list(argin)
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbGetDeviceFamilyList")
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceFamilyList
return argout
@@ -1230,8 +1368,16 @@ class DataBase (PyTango.Device_4Impl):
:rtype: PyTango.DevVarLongStringArray """
self.debug_stream("In " + self.get_name() + ".DbGetDeviceInfo()")
argout = [0], ['']
+
#----- PROTECTED REGION ID(DataBase.DbGetDeviceInfo) ENABLED START -----#
+ ret, dev_name, dfm = check_device_name(argin)
+ if not ret:
+ th_exc(DB_IncorrectDeviceName,
+ "device name (" + argin + ") syntax error (should be [tango:][//instance/]domain/family/member)",
+ "DataBase::DbGetDeviceAlias()")
+ argout = self.db.get_device_info(dev_name)
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceInfo
return argout
@@ -1249,7 +1395,10 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbGetDeviceList()")
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDeviceList) ENABLED START -----#
-
+ server_name = replace_wildcard(argin[0])
+ class_name = replace_wildcard(argin[1])
+ argout = self.db.get_device_list(server_name, class_name)
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceList
return argout
@@ -1266,7 +1415,10 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbGetDeviceWideList()")
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDeviceWideList) ENABLED START -----#
-
+
+ argin = replace_wildcard(argin)
+ argout = self.db.get_device_wide_list(argin)
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceWideList
return argout
@@ -1285,6 +1437,13 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDeviceMemberList) ENABLED START -----#
+ time_before = time.time()
+
+ argin = replace_wildcard(argin)
+ argout = self.db.get_device_member_list(argin)
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbGetDeviceMemberList")
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceMemberList
return argout
@@ -1313,6 +1472,13 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDeviceProperty) ENABLED START -----#
+ time_before = time.time()
+
+ device_name = argin[0]
+ argout = self.db.get_device_property(device_name, argin[1:])
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbGetDeviceProperty")
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceProperty
return argout
@@ -1323,7 +1489,7 @@ class DataBase (PyTango.Device_4Impl):
""" Retrieve device property history
:param argin: Str[0] = Device name
- Str[2] = Property name
+ Str[1] = Property name
:type: PyTango.DevVarStringArray
:return: Str[0] = Property name
Str[1] = date
@@ -1335,6 +1501,11 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDevicePropertyHist) ENABLED START -----#
+ device_name = argin[0]
+ prop_name = argin[1]
+ argout = self.db.get_device_property_hist(device_name, prop_name)
+
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDevicePropertyHist
return argout
@@ -1354,6 +1525,17 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDevicePropertyList) ENABLED START -----#
+ time_before = time.time()
+
+ device_name = argin[0]
+ prop_filter = argin[1]
+
+ prop_filter = replace_wildcard(prop_filter)
+
+ argout = self.db.get_device_property_list(device_name, prop_filter)
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbGetDevicePropertyList")
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDevicePropertyList
return argout
@@ -1370,6 +1552,10 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbGetDeviceServerClassList()")
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDeviceServerClassList) ENABLED START -----#
+
+ argin = replace_wildcard(argin)
+
+ argout = self.db.get_server_class_list(argin)
#----- PROTECTED REGION END -----# // DataBase.DbGetDeviceServerClassList
return argout
@@ -1387,6 +1573,10 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbGetExportdDeviceListForClass()")
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetExportdDeviceListForClass) ENABLED START -----#
+
+ argin = replace_wildcard(argin)
+
+ argout = self.db.get_exported_device_list_for_class(argin)
#----- PROTECTED REGION END -----# // DataBase.DbGetExportdDeviceListForClass
return argout
@@ -1405,6 +1595,14 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetHostList) ENABLED START -----#
+ time_before = time.time()
+
+ argin = replace_wildcard(argin)
+ argout = self.db.get_host_list(argin)
+
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbGetHostList")
+
#----- PROTECTED REGION END -----# // DataBase.DbGetHostList
return argout
@@ -1423,6 +1621,15 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetHostServerList) ENABLED START -----#
+ time_before = time.time()
+
+ argin = replace_wildcard(argin)
+ argout = self.db.get_host_server_list(argin)
+
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbGetHostServerList")
+
+
#----- PROTECTED REGION END -----# // DataBase.DbGetHostServerList
return argout
@@ -1439,6 +1646,10 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbGetHostServersInfo()")
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetHostServersInfo) ENABLED START -----#
+
+ argin = replace_wildcard(argin)
+
+ argout = self.db.get_host_servers_info(argin)
#----- PROTECTED REGION END -----# // DataBase.DbGetHostServersInfo
return argout
@@ -1456,7 +1667,9 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbGetInstanceNameList()")
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetInstanceNameList) ENABLED START -----#
-
+
+ argout = self.db.get_instance_name_list(argin)
+
#----- PROTECTED REGION END -----# // DataBase.DbGetInstanceNameList
return argout
@@ -1474,7 +1687,10 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbGetObjectList()")
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetObjectList) ENABLED START -----#
-
+
+ argin = replace_wildcard(argin)
+ argout = self.db.get_object_list(argin)
+
#----- PROTECTED REGION END -----# // DataBase.DbGetObjectList
return argout
@@ -1503,6 +1719,9 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetProperty) ENABLED START -----#
+ object_name = argin[0]
+ argout = self.db.get_property(object_name, argin[1:])
+
#----- PROTECTED REGION END -----# // DataBase.DbGetProperty
return argout
@@ -1525,6 +1744,10 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetPropertyHist) ENABLED START -----#
+ object_name = argin[0]
+ prop_name = argin[1]
+ argout = self.db.get_property_hist(object_name, prop_name)
+
#----- PROTECTED REGION END -----# // DataBase.DbGetPropertyHist
return argout
@@ -1544,6 +1767,11 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetPropertyList) ENABLED START -----#
+ object_name = argin[0]
+ wildcard = replace_wildcard(argin[1])
+
+ argout = self.db.get_property_list(object_name, wildcard)
+
#----- PROTECTED REGION END -----# // DataBase.DbGetPropertyList
return argout
@@ -1560,6 +1788,8 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbGetServerInfo()")
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetServerInfo) ENABLED START -----#
+
+ argout = self.db.get_server_info(argin)
#----- PROTECTED REGION END -----# // DataBase.DbGetServerInfo
return argout
@@ -1579,6 +1809,14 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetServerList) ENABLED START -----#
+ time_before = time.time()
+
+ argin = replace_wildcard(argin)
+ argout = self.db.get_server_list(argin)
+
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbGetServerList")
+
#----- PROTECTED REGION END -----# // DataBase.DbGetServerList
return argout
@@ -1595,7 +1833,10 @@ class DataBase (PyTango.Device_4Impl):
:rtype: PyTango.DevVarStringArray """
self.debug_stream("In " + self.get_name() + ".DbGetServerNameList()")
argout = ['']
- #----- PROTECTED REGION ID(DataBase.DbGetServerNameList) ENABLED START -----#
+ #----- PROTECTED REGION ID(DataBase.DbGetServerNameList) ENABLED START ----
+
+ argin = replace_wildcard(argin)
+ argout = self.db.get_server_name_list(argin)
#----- PROTECTED REGION END -----# // DataBase.DbGetServerNameList
return argout
@@ -1622,6 +1863,13 @@ class DataBase (PyTango.Device_4Impl):
argout = [0], ['']
#----- PROTECTED REGION ID(DataBase.DbImportDevice) ENABLED START -----#
+ time_before = time.time()
+
+ argout = self.db.import_device(argin.lower())
+
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbImportDevice")
+
#----- PROTECTED REGION END -----# // DataBase.DbImportDevice
return argout
@@ -1639,6 +1887,16 @@ class DataBase (PyTango.Device_4Impl):
argout = [0], ['']
#----- PROTECTED REGION ID(DataBase.DbImportEvent) ENABLED START -----#
+ time_before = time.time()
+
+ argin = replace_wildcard(argin.lower())
+
+ argout = self.db.import_event(argin)
+
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbImportEvent")
+
+
#----- PROTECTED REGION END -----# // DataBase.DbImportEvent
return argout
@@ -1666,6 +1924,13 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbInfo) ENABLED START -----#
+ time_before = time.time()
+
+ argout = self.db.info()
+
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbInfo")
+
#----- PROTECTED REGION END -----# // DataBase.DbInfo
return argout
@@ -1683,6 +1948,16 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbPutAttributeAlias()")
#----- PROTECTED REGION ID(DataBase.DbPutAttributeAlias) ENABLED START -----#
+ if len(argin) < 2:
+ self.warn_stream("DataBase::DbPutAttributeAlias(): insufficient number of arguments ")
+ th_exc(DB_IncorrectArguments,
+ "insufficient number of arguments to put attribute alias",
+ "DataBase::DbPutAttributeAlias()")
+
+ attribute_name = argin[0]
+ attribute_alias = argin[1]
+ self.db.put_attribute_alias(attribute_name, attribute_alias)
+
#----- PROTECTED REGION END -----# // DataBase.DbPutAttributeAlias
#------------------------------------------------------------------
@@ -1703,7 +1978,16 @@ class DataBase (PyTango.Device_4Impl):
:rtype: PyTango.DevVoid """
self.debug_stream("In " + self.get_name() + ".DbPutClassAttributeProperty()")
#----- PROTECTED REGION ID(DataBase.DbPutClassAttributeProperty) ENABLED START -----#
-
+
+ class_name = argin[0]
+ nb_attributes = int(argin[1])
+
+
+ self.info_stream("DataBase::DbPutClassAttributeProperty(): put " + str(nb_attributes) + " attributes for class " + class_name)
+
+ self.db.put_class_attribute_property(class_name, nb_attributes, argin[2:])
+
+
#----- PROTECTED REGION END -----# // DataBase.DbPutClassAttributeProperty
#------------------------------------------------------------------
@@ -1727,7 +2011,13 @@ class DataBase (PyTango.Device_4Impl):
:rtype: PyTango.DevVoid """
self.debug_stream("In " + self.get_name() + ".DbPutClassAttributeProperty2()")
#----- PROTECTED REGION ID(DataBase.DbPutClassAttributeProperty2) ENABLED START -----#
-
+ class_name = argin[0]
+ nb_attributes = int(argin[1])
+
+ self.info_stream("DataBase::DbPutClassAttributeProperty2(): put " + str(nb_attributes) + " attributes for class " + class_name)
+
+ self.db.put_class_attribute_property2(class_name, nb_attributes, argin[2:])
+
#----- PROTECTED REGION END -----# // DataBase.DbPutClassAttributeProperty2
#------------------------------------------------------------------
@@ -1749,6 +2039,19 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbPutClassProperty()")
#----- PROTECTED REGION ID(DataBase.DbPutClassProperty) ENABLED START -----#
+ time_before = time.time()
+
+ class_name = argin[0]
+ nb_properties = int(argin[1])
+
+ self.info_stream("DataBase::DbPutClassProperty(): put " + str(nb_properties) + " attributes for class " + class_name)
+
+ self.db.put_class_property(class_name, properties, argin[2:])
+
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbPutClassProperty")
+
+
#----- PROTECTED REGION END -----# // DataBase.DbPutClassProperty
#------------------------------------------------------------------
@@ -1765,6 +2068,18 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbPutDeviceAlias()")
#----- PROTECTED REGION ID(DataBase.DbPutDeviceAlias) ENABLED START -----#
+ if len(argin) < 2:
+ self.warn_stream("DataBase::DbPutDeviceAlias(): insufficient number of arguments ")
+ th_exc(DB_IncorrectArguments,
+ "insufficient number of arguments to put device alias",
+ "DataBase::DbPutDeviceAlias()")
+
+ device_name = argin[0]
+ device_alias = argin[1]
+ self.db.put_device_alias(device_name, device_alias)
+
+
+
#----- PROTECTED REGION END -----# // DataBase.DbPutDeviceAlias
#------------------------------------------------------------------
@@ -1786,6 +2101,18 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbPutDeviceAttributeProperty()")
#----- PROTECTED REGION ID(DataBase.DbPutDeviceAttributeProperty) ENABLED START -----#
+ time_before = time.time()
+
+ device_name = argin[0]
+ nb_attributes = int(argin[1])
+
+ self.info_stream("DataBase::DbPutDeviceAttributeProperty(): put " + str(nb_attributes) + " attributes for device " + device_name)
+
+ self.db.put_device_attribute_property(device_name, nb_attributes, argin[2:])
+
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbPutDeviceAttributeProperty")
+
#----- PROTECTED REGION END -----# // DataBase.DbPutDeviceAttributeProperty
#------------------------------------------------------------------
@@ -1811,6 +2138,19 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbPutDeviceAttributeProperty2()")
#----- PROTECTED REGION ID(DataBase.DbPutDeviceAttributeProperty2) ENABLED START -----#
+ time_before = time.time()
+
+ device_name = argin[0]
+ nb_attributes = int(argin[1])
+
+ self.info_stream("DataBase::DbPutDeviceAttributeProperty2(): put " + str(nb_attributes) + " attributes for device " + device_name)
+
+ self.db.put_device_attribute_property2(device_name, nb_attributes, argin[2:])
+
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbPutDeviceAttributeProperty2")
+
+
#----- PROTECTED REGION END -----# // DataBase.DbPutDeviceAttributeProperty2
#------------------------------------------------------------------
@@ -1832,6 +2172,18 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbPutDeviceProperty()")
#----- PROTECTED REGION ID(DataBase.DbPutDeviceProperty) ENABLED START -----#
+ time_before = time.time()
+
+ device_name = argin[0]
+ nb_properties = int(argin[1])
+
+ self.info_stream("DataBase::DbPutDeviceProperty(): put " + str(nb_properties) + " attributes for device " + device_name)
+
+ self.db.put_device_property(device_name, properties, argin[2:])
+
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbPutDeviceProperty")
+
#----- PROTECTED REGION END -----# // DataBase.DbPutDeviceProperty
#------------------------------------------------------------------
@@ -1853,6 +2205,13 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbPutProperty()")
#----- PROTECTED REGION ID(DataBase.DbPutProperty) ENABLED START -----#
+ object_name = argin[0]
+ nb_properties = int(argin[1])
+
+ self.info_stream("DataBase::DbPutProperty(): put " + str(nb_properties) + " attributes for object " + object_name)
+
+ self.db.put_property(object_name, properties, argin[2:])
+
#----- PROTECTED REGION END -----# // DataBase.DbPutProperty
#------------------------------------------------------------------
@@ -1868,6 +2227,25 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbPutServerInfo()")
#----- PROTECTED REGION ID(DataBase.DbPutServerInfo) ENABLED START -----#
+ if len(argin) < 4:
+ self.warn_stream("DataBase::DbPutServerInfo(): insufficient number of arguments ")
+ th_exc(DB_IncorrectArguments,
+ "insufficient server info",
+ "DataBase::DbPutServerInfo()")
+
+ tmp_server = argin[0].lower()
+ tmp_host = argin[1]
+ tmp_mode = argin[2]
+ tmp_level = argin[3]
+ tmp_extra = []
+ if len(argin) > 4:
+ tmp_extra = argin[4:]
+
+ tmp_len = len(argin) - 1
+ self.info_stream("DataBase::DbPutServerInfo(): put " + tmp_len + " export info for device " + tmp_server)
+
+ self.db.put_server_info(tmp_server, tmp_host, tmp_mode, tmp_level, tmp_extra)
+
#----- PROTECTED REGION END -----# // DataBase.DbPutServerInfo
#------------------------------------------------------------------
@@ -1883,6 +2261,10 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbUnExportDevice()")
#----- PROTECTED REGION ID(DataBase.DbUnExportDevice) ENABLED START -----#
+ dev_name = argin[0].lower()
+
+ self.db.unexport_device(dev_name)
+
#----- PROTECTED REGION END -----# // DataBase.DbUnExportDevice
#------------------------------------------------------------------
@@ -1898,6 +2280,10 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbUnExportEvent()")
#----- PROTECTED REGION ID(DataBase.DbUnExportEvent) ENABLED START -----#
+ event_name = argin[0].lower()
+
+ self.db.unexport_event(event_name)
+
#----- PROTECTED REGION END -----# // DataBase.DbUnExportEvent
#------------------------------------------------------------------
@@ -1914,6 +2300,15 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbUnExportServer()")
#----- PROTECTED REGION ID(DataBase.DbUnExportServer) ENABLED START -----#
+ time_before = time.time()
+
+ server_name = argin[0].lower()
+
+ self.db.unexport_server(server_name)
+
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbUnExportServer")
+
#----- PROTECTED REGION END -----# // DataBase.DbUnExportServer
#------------------------------------------------------------------
@@ -1928,6 +2323,12 @@ class DataBase (PyTango.Device_4Impl):
:rtype: PyTango.DevVoid """
self.debug_stream("In " + self.get_name() + ".ResetTimingValues()")
#----- PROTECTED REGION ID(DataBase.ResetTimingValues) ENABLED START -----#
+ for tmp_timing in timing_maps.itervalues():
+ tmp_timing.average = 0.
+ tmp_timing.minimum = 0.
+ tmp_timing.maximum = 0.
+ tmp_timing.total_elapsed = 0.
+ tmp_timing.calls = 0.
#----- PROTECTED REGION END -----# // DataBase.ResetTimingValues
@@ -1947,6 +2348,13 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetDataForServerCache) ENABLED START -----#
+ time_before = time.time()
+
+ ## TODO
+
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbDbGetDataForServerCache")
+
#----- PROTECTED REGION END -----# // DataBase.DbGetDataForServerCache
return argout
@@ -1964,6 +2372,23 @@ class DataBase (PyTango.Device_4Impl):
self.debug_stream("In " + self.get_name() + ".DbDeleteAllDeviceAttributeProperty()")
#----- PROTECTED REGION ID(DataBase.DbDeleteAllDeviceAttributeProperty) ENABLED START -----#
+ if len(argin) < 2:
+ self.warn_stream("DataBase::DbDeleteAllDeviceAttributeProperty(): insufficient number of arguments ")
+ th_exc(DB_IncorrectArguments,
+ "insufficient number of arguments to delete all device attribute(s) property",
+ "DataBase::DbDeleteAllDeviceAttributeProperty()")
+
+ dev_name = argin[0]
+
+ ret, d_name, dfm = check_device_name(dev_name)
+
+ if not ret:
+ th_exc(DB_IncorrectDeviceName,
+ "device name (" + argin + ") syntax error (should be [tango:][//instance/]domain/family/member)",
+ "DataBase::DbDeleteAllDeviceAttributeProperty()")
+
+ self.db.delete_all_device_attribute_property(dev_name, argin[1:])
+
#----- PROTECTED REGION END -----# // DataBase.DbDeleteAllDeviceAttributeProperty
#------------------------------------------------------------------
@@ -1984,6 +2409,30 @@ class DataBase (PyTango.Device_4Impl):
argout = [0], ['']
#----- PROTECTED REGION ID(DataBase.DbMySqlSelect) ENABLED START -----#
+ time_before = time.time()
+
+ tmp_argin = argin.lower()
+
+ # Check if SELECT key is alread inside command
+
+ cmd = argin
+ tmp_argin = argin.lower()
+ pos = tmp_argin.find('select')
+ if pos == -1:
+ cmd = "SELECT " + cmd
+
+ pos = tmp_argin.find(';')
+ if pos != -1 and len(tmp_argin) > (pos + 1):
+ th_exc(DB_IncorrectArguments,
+ "SQL command not valid: " + argin,
+ "DataBase::ExportDevice()")
+ logging.info("DataBase::db_my_sql_select(): \n %s" % cmd)
+
+ argout = self.db.my_sql_select(cmd)
+
+ time_after = time.time()
+ self.update_timing_stats(time_before, time_after, "DbMySqlSelect")
+
#----- PROTECTED REGION END -----# // DataBase.DbMySqlSelect
return argout
@@ -2001,6 +2450,8 @@ class DataBase (PyTango.Device_4Impl):
argout = ['']
#----- PROTECTED REGION ID(DataBase.DbGetCSDbServerList) ENABLED START -----#
+ argout = self.db.get_csdb_server_list()
+
#----- PROTECTED REGION END -----# // DataBase.DbGetCSDbServerList
return argout
@@ -2019,6 +2470,9 @@ class DataBase (PyTango.Device_4Impl):
argout = ''
#----- PROTECTED REGION ID(DataBase.DbGetAttributeAlias2) ENABLED START -----#
+ attr_name = argin[0]
+ argout = self.db.get_attribute_alias2(attr_name)
+
#----- PROTECTED REGION END -----# // DataBase.DbGetAttributeAlias2
return argout
@@ -2037,9 +2491,47 @@ class DataBase (PyTango.Device_4Impl):
argout = ''
#----- PROTECTED REGION ID(DataBase.DbGetAliasAttribute) ENABLED START -----#
+ alias_name = argin[0]
+ argout = self.db.get_alias_attribute(alias_name)
+
#----- PROTECTED REGION END -----# // DataBase.DbGetAliasAttribute
return argout
+#------------------------------------------------------------------
+# DbRenameServer command:
+#------------------------------------------------------------------
+ def DbRenameServer(self, argin):
+ """ Rename a device server process
+
+ :param argin: str[0] = old device server name (exec/instance)
+ str[1] = new device server name (exec/instance)
+ :type: PyTango.DevVarStringArray
+ :return:
+ :rtype: PyTango.DevVoid """
+ self.debug_stream("In " + self.get_name() + ".DbRenameServer()")
+ #----- PROTECTED REGION ID(DataBase.DbRenameServer) ENABLED START -----#
+
+ if len(argin) < 2:
+ self.warn_stream("DataBase::DbRenameServer(): insufficient number of arguments ")
+ th_exc(DB_IncorrectArguments,
+ "insufficient number of arguments (two required: old name and new name",
+ "DataBase::DbRenameServer")
+
+
+ old_name = argin[0]
+ new_name = argin[1]
+
+ if ('/' not in argin[0]) or ('/' not in argin[1]):
+ self.warn_stream("DataBase::DbRenameServer(): wrong syntax in command args ")
+ th_exc(DB_IncorrectArguments,
+ "Wrong syntax in command args (ds_exec_name/inst_name)",
+ "DataBase::DbRenameServer")
+
+ self.db.rename_server(old_name, new_name)
+
+
+
+ #----- PROTECTED REGION END -----# // DataBase.DbRenameServer
#==================================================================
#
@@ -2306,6 +2798,9 @@ class DataBaseClass(PyTango.DeviceClass):
'DbGetAliasAttribute':
[[PyTango.DevString, "The attribute alias"],
[PyTango.DevString, "The attribute name (dev_name/att_name)"]],
+ 'DbRenameServer':
+ [[PyTango.DevVoid, "none"],
+ [PyTango.DevVarStringArray, "s[0] = old device server name (exec/instance)\ns[1] = new device server name (exec/instance)"]],
}
diff --git a/src/boost/python/databaseds/db_access.py b/src/boost/python/databaseds/db_access.py
index 6faa291..9a3f1bf 100644
--- a/src/boost/python/databaseds/db_access.py
+++ b/src/boost/python/databaseds/db_access.py
@@ -166,6 +166,17 @@ class Tango_dbapi2(object):
else:
return row[0]
+
+ def send_starter_cmd(self, starter_dev_names):
+ for name in starter_dev_names:
+ pos = name.find('.')
+ if pos != -1:
+ name = name[0:pos]
+ dev = PyTango.DeviceProxy(name)
+ dev.UpdateServersInfo()
+
+
+
# TANGO API
def get_stored_procedure_release(self):
@@ -224,7 +235,7 @@ class Tango_dbapi2(object):
'DELETE FROM property_attribute_class WHERE class = ? AND ' \
'attribute = ? and name = ?', (klass_name, attr_name, prop_name))
# mark this property as deleted
- hist_id = self.get_id('class_attibute', cursor=cursor)
+ hist_id = self.get_id('class_attribute', cursor=cursor)
cursor.execute(\
'INSERT INTO property_attribute_class_hist (class, attribute, ' \
'name, id, count, value) VALUES ' \
@@ -363,7 +374,7 @@ class Tango_dbapi2(object):
# Update host's starter to update controlled servers list
if self.fire_to_starter and previous_host:
- # TODO send to starter
+ self.send_starter_cmd(previous_host)
pass
@use_cursor
@@ -377,9 +388,17 @@ class Tango_dbapi2(object):
cursor = self.cursor
do_fire = False
previous_host = None
+
if self.fire_to_starter:
- # TODO send to starter
- pass
+ if dev_name[0:8] == "dserver/":
+ # Get database server name
+ tango_util = PyTango.Util.instance()
+ db_serv = tango_util.get_ds_name()
+ adm_dev_name = "dserver/" + db_serv.lower()
+ if dev_name != adm_dev_name and dev_name[0:16] != "dserver/starter/":
+ do_fire = True
+ previous_host = self.get_device_host(dev_name)
+
cursor.execute('SELECT server FROM device WHERE name LIKE ?', (dev_name,))
row = cursor.fetchone()
if row is None:
@@ -398,7 +417,11 @@ class Tango_dbapi2(object):
cursor.execute('UPDATE server SET host=? WHERE name LIKE ?', (host, server))
if do_fire:
- # TODO send to starter
+ hosts = []
+ hosts.append(host)
+ if previous_host != "" and previous_host != "nada" and previous_host != host:
+ hosts.append(previous_host)
+ self.send_starter_cmd(hosts)
pass
@use_cursor
@@ -448,7 +471,7 @@ class Tango_dbapi2(object):
return [ row[0] for row in cursor.fetchall() ]
@use_cursor
- def get_class_attribute_property(self, clas_name, attributes):
+ def get_class_attribute_property(self, class_name, attributes):
cursor = self.cursor
stmt = 'SELECT name,value FROM property_attribute_class WHERE class=? AND attribute LIKE ?'
result = [class_name, str(len(attributes))]
@@ -463,19 +486,79 @@ class Tango_dbapi2(object):
return result
@use_cursor
- def get_class_attribute_property2(self, clas_name, attributes):
+ def get_class_attribute_property2(self, class_name, attributes):
cursor = self.cursor
stmt = 'SELECT name,value FROM property_attribute_class WHERE class=? AND attribute LIKE ? ORDER BY name,count'
result = [class_name, str(len(attributes))]
- # TODO: NOT DONE YET!
for attribute in attributes:
cursor.execute(stmt, (class_name, attribute))
rows = cursor.fetchall()
- result.append(attribute)
- result.append(str(len(rows)))
+ result.append(attribute)
+ j = 0
+ new_prop = True
+ nb_props = 0
+ prop_size = 0
+ prop_names = []
+ prop_sizes = []
+ prop_values = []
for row in rows:
- result.append(row[0])
- result.append(row[1])
+ prop_values.append(row[1])
+ if j == 0:
+ old_name = row[0]
+ else:
+ name = row[0]
+ if name != old_name:
+ new_prop = True
+ old_name = name
+ else:
+ new_prop = False
+ j = j + 1
+ if new_prop == True:
+ nb_props = nb_props + 1
+ prop_names.append(row[0])
+ if prop_size != 0:
+ prop_sizes.append(prop_size)
+ prop_size = 1
+ else:
+ prop_size = prop_size + 1
+
+ result.append(str(nb_props))
+ j = 0
+ k = 0
+ for name in prop_names:
+ result.append(name)
+ result.append(prop_sizes[j])
+ for i in range(0, prop_sizes[j]):
+ result.append(prop_values[k])
+ k = k + 1
+ j = j + 1
+ return result
+
+ @use_cursor
+ def get_class_attribute_property_hist(self, class_name, attribute, prop_name):
+ cursor = self.cursor
+ stmt = 'SELECT DISTINCT id FROM property_attribute_class_hist WHERE class=? AND attribute LIKE ? AND name LIKE ? ORDER by date ASC'
+
+ result = []
+
+ cursor.execute(stmt, (class_name, attribute, prop_name))
+
+ for row in cursor.fetchall():
+ idr = row[0]
+
+ stmt = 'SELECT DATE_FORMAT(date,\'%Y-%m-%d %H:%i:%s\'),value,attribute,name,count FROM property_attribute_class_hist WHERE id =? AND class =?'
+
+ cursor.execute(stmt, (idr, class_name))
+
+ rows = cursor.fetchall()
+
+ result.append(rows[2])
+ result.append(rows[3])
+ result.append(rows[0])
+ result.append(str(rows[4]))
+ for value in rows[1]:
+ result.append(value)
+
return result
@use_cursor
@@ -502,7 +585,970 @@ class Tango_dbapi2(object):
return [ row[0] for row in cursor.fetchall() ]
+ @use_cursor
+ def get_class_property(self, class_name, properties):
+ cursor = self.cursor
+ stmt = 'SELECT count,value FROM property_class WHERE class=? AND name LIKE ? ORDER BY count'
+ result.append(class_name)
+ result.append(len(properties))
+ for prop_name in properties:
+ cursor.execute(stmt, (class_name, prop_name))
+ rows = cursor.fetchall()
+ result.append(prop_name)
+ result.append(str(len(rows)))
+ for row in rows:
+ result.append(row[1])
+ return result
+
+ @use_cursor
+ def get_class_property_hist(self, class_name, prop_name):
+ cursor = self.cursor
+ stmt = 'SELECT DISTINCT id FROM property_class_hist WHERE class=? AND AND name LIKE ? ORDER by date ASC'
+
+ result = []
+
+ cursor.execute(stmt, (class_name, prop_name))
+
+ for row in cursor.fetchall():
+ idr = row[0]
+
+ stmt = 'SELECT DATE_FORMAT(date,\'%Y-%m-%d %H:%i:%s\'),value,name,count FROM property_class_hist WHERE id =? AND class =?'
+
+ cursor.execute(stmt, (idr, class_name))
+
+ rows = cursor.fetchall()
+
+ result.append(rows[2])
+ result.append(rows[0])
+ result.append(str(rows[3]))
+ for value in rows[1]:
+ result.append(value)
+
+ return result
+
+ @use_cursor
+ def get_class_property_list(self, class_name):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT name FROM property_class WHERE class LIKE ? order by NAME',
+ (class_name,))
+ return [ row[0] for row in cursor.fetchall() ]
+
+ @use_cursor
+ def get_device_alias(self, dev_name):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT alias FROM device WHERE name LIKE ?',
+ (dev_name,))
+ row = cursor.fetchone()
+ if row is None:
+ th_exc(DB_DeviceNotDefined,
+ "No alias found for device '" + dev_name + "'",
+ "DataBase::GetDeviceAlias()")
+ return row[0]
+
+ @use_cursor
+ def get_device_alias_list(self, alias):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT alias FROM device WHERE alias LIKE ? ORDER BY alias',
+ (alias,))
+ return [ row[0] for row in cursor.fetchall() ]
+
+ @use_cursor
+ def get_device_attribute_list(self, dev_name, attribute):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT attribute FROM property_attribute_device WHERE device=? AND attribute LIKE ? ORDER BY attribute',
+ (dev_name, attribute,))
+ return [ row[0] for row in cursor.fetchall() ]
+
+
+ @use_cursor
+ def get_device_attribute_property(self, dev_name, attributes):
+ cursor = self.cursor
+ stmt = 'SELECT name,value FROM property_attribute_device WHERE device=? AND attribute LIKE ?'
+ result = [dev_name, str(len(attributes))]
+ for attribute in attributes:
+ cursor.execute(stmt, (dev_name, attribute))
+ rows = cursor.fetchall()
+ result.append(attribute)
+ result.append(str(len(rows)))
+ for row in rows:
+ result.append(row[0])
+ result.append(row[1])
+ return result
+
+ @use_cursor
+ def get_device_attribute_property2(self, dev_name, attributes):
+ cursor = self.cursor
+ stmt = 'SELECT name,value FROM property_attribute_device WHERE device=? AND attribute LIKE ? ORDER BY name,count'
+ result = [dev_name, str(len(attributes))]
+ for attribute in attributes:
+ cursor.execute(stmt, (dev_name, attribute))
+ rows = cursor.fetchall()
+ result.append(attribute)
+ j = 0
+ new_prop = True
+ nb_props = 0
+ prop_size = 0
+ prop_names = []
+ prop_sizes = []
+ prop_values = []
+ for row in rows:
+ prop_values.append(row[1])
+ if j == 0:
+ old_name = row[0]
+ else:
+ name = row[0]
+ if name != old_name:
+ new_prop = True
+ old_name = name
+ else:
+ new_prop = False
+ j = j + 1
+ if new_prop == True:
+ nb_props = nb_props + 1
+ prop_names.append(row[0])
+ if prop_size != 0:
+ prop_sizes.append(prop_size)
+ prop_size = 1
+ else:
+ prop_size = prop_size + 1
+
+ result.append(str(nb_props))
+ j = 0
+ k = 0
+ for name in prop_names:
+ result.append(name)
+ result.append(prop_sizes[j])
+ for i in range(0, prop_sizes[j]):
+ result.append(prop_values[k])
+ k = k + 1
+ j = j + 1
+ return result
+
+ @use_cursor
+ def get_device_attribute_property_hist(self, dev_name, attribute, prop_name):
+ cursor = self.cursor
+ stmt = 'SELECT DISTINCT id FROM property_attribute_device_hist WHERE device=? AND attribute LIKE ? AND name LIKE ? ORDER by date ASC'
+
+ result = []
+
+ cursor.execute(stmt, (dev_name, attribute, prop_name))
+
+ for row in cursor.fetchall():
+ idr = row[0]
+
+ stmt = 'SELECT DATE_FORMAT(date,\'%Y-%m-%d %H:%i:%s\'),value,attribute,name,count FROM property_attribute_device_hist WHERE id =? AND device =? ORDER BY count ASC'
+
+ cursor.execute(stmt, (idr, class_name))
+
+ rows = cursor.fetchall()
+
+ result.append(rows[2])
+ result.append(rows[3])
+ result.append(rows[0])
+ result.append(str(rows[4]))
+ for value in rows[1]:
+ result.append(value)
+
+ return result
+
+
+ @use_cursor
+ def get_device_class_list(self, server_name):
+ cursor = self.cursor
+ result = []
+ cursor.execute('SELECT name,class FROM device WHERE server =? ORDER BY name',
+ (server_name,))
+ for row in cursor.fetchall():
+ result.append(row[0])
+ result.append(row[1])
+
+ return result
+
+ @use_cursor
+ def get_device_domain_list(self, wildcard):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT domain FROM device WHERE name LIKE ? OR alias LIKE ? ORDER BY domain',
+ (wildcard,wildcard))
+ return [ row[0] for row in cursor.fetchall() ]
+
+
+ @use_cursor
+ def get_device_exported_list(self, wildcard):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT name FROM device WHERE (name LIKE ? OR alias LIKE ?) AND exported=1 ORDER BY name',
+ (wildcard,wildcard))
+ return [ row[0] for row in cursor.fetchall() ]
+
+ @use_cursor
+ def get_device_family_list(self, wildcard):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT family FROM device WHERE name LIKE ? OR alias LIKE ? ORDER BY family',
+ (wildcard,wildcard))
+ return [ row[0] for row in cursor.fetchall() ]
+
+ @use_cursor
+ def get_device_info(self, dev_name):
+ cursor = self.cursor
+ cursor.execute('SELECT exported,ior,version,pid,server,host,started,stopped,class FROM device WHERE name =? or alias =?',
+ (dev_name,dev_name))
+ result_long = []
+ result_str = []
+ for row in cursor.fetchall():
+ if ((row[4] == None) or (row[5] == None)):
+ th_exc(DB_SQLError,
+ "Wrong info in database for device '" + dev_name + "'",
+ "DataBase::GetDeviceInfo()")
+ result_str.append(dev_name)
+ if raw[1] != None:
+ result_str.append(str(raw[1]))
+ else:
+ result_str.append("")
+ result_str.append(str(raw[2]))
+ result_str.append(str(raw[4]))
+ result_str.append(str(raw[5]))
+
+ for i in range(0,2):
+ cursor.execute('SELECT DATE_FORMAT(?,\'%D-%M-%Y at %H:%i:%s\')', raw[6 + i])
+ tmp_date = cursor.fetchone()
+ if tmp_date == None:
+ result_str.append("?")
+ else:
+ result_str.append(str(tmp_date))
+
+ for i in range(0,2):
+ if raw[i] != None:
+ result_long.append(raw[i])
+
+ result = (result_long, result_str)
+ return result
+
+ @use_cursor
+ def get_device_list(self,server_name, class_name ):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT name FROM device WHERE server LIKE ? AND class LIKE ? ORDER BY name',
+ (server_name, class_name))
+ return [ row[0] for row in cursor.fetchall() ]
+
+ @use_cursor
+ def get_device_wide_list(self, wildcard):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT name FROM device WHERE name LIKE ? ORDER BY name',
+ (wildcard))
+ return [ row[0] for row in cursor.fetchall() ]
+
+ @use_cursor
+ def get_device_member_list(self, wildcard):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT member FROM device WHERE name LIKE ? ORDER BY member',
+ (wildcard))
+ return [ row[0] for row in cursor.fetchall() ]
+
+
+ @use_cursor
+ def get_device_property(self, dev_name, properties):
+ cursor = self.cursor
+ stmt = 'SELECT count,value,name FROM property_device WHERE device = ? AND name LIKE ? ORDER BY count'
+ result = []
+ result.append(dev_name)
+ result.append(str(len(properties)))
+ for prop in properties:
+ result.append(prop)
+ tmp_name = replace_wildcard(prop)
+ cursor.execute(stmt, (dev_name, tmp_name))
+ rows = cursor.fetchall()
+ result.append(attribute)
+ result.append(str(len(rows)))
+ for row in rows:
+ result.append(row[1])
+ return result
+
+ @use_cursor
+ def get_device_property_hist(self, device_name, prop_name):
+ cursor = self.cursor
+ stmt = 'SELECT DISTINCT id FROM property_device_hist WHERE device=? AND name LIKE ? ORDER by date ASC'
+
+ result = []
+
+ tmp_name = replace_wildcard(prop_name);
+
+ cursor.execute(stmt, (class_name, device_name, tmp_name))
+
+ stmt = 'SELECT DATE_FORMAT(date,\'%Y-%m-%d %H:%i:%s\'),value,name,count FROM property_device_hist WHERE id =? AND device =? ORDER BY count ASC'
+
+ for row in cursor.fetchall():
+ idr = row[0]
+ cursor.execute(stmt, (idr, device_name))
+ rows = cursor.fetchall()
+ result.append(rows[2])
+ result.append(rows[0])
+ result.append(str(rows[3]))
+ for value in rows[1]:
+ result.append(value)
+
+ return result
+
+ @use_cursor
+ def get_device_server_class_list(self, server_name):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT class FROM device WHERE server LIKE ? ORDER BY class',
+ (sever_name,))
+ return [ row[0] for row in cursor.fetchall() ]
+
+ @use_cursor
+ def get_exported_device_list_for_class(self, class_name):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT name FROM device WHERE class LIKE ? AND exported=1 ORDER BY name',
+ (class_name,))
+ return [ row[0] for row in cursor.fetchall() ]
+
+ @use_cursor
+ def get_host_list(self, host_name):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT host FROM device WHERE host LIKE ? ORDER BY host',
+ (host_name,))
+ return [ row[0] for row in cursor.fetchall() ]
+
+ @use_cursor
+ def get_host_server_list(self, host_name):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT server FROM device WHERE host LIKE ? ORDER BY server',
+ (host_name,))
+ return [ row[0] for row in cursor.fetchall() ]
+
+
+ def get_host_servers_info(self, host_name):
+ servers = self.get_host_server_list(host_name)
+ result = []
+ for server in servers:
+ result.append(server)
+ info = self.get_server_info(server)
+ result.append(info[2])
+ result.append(info[3])
+ return result
+
+
+ def get_instance_name_list(self, server_name):
+ server_name = server_name + "\*"
+ server_list = self.get_server_list(server_name)
+ result = []
+ for server in server_list:
+ names = server.split("/")
+ result.append(names[1])
+ return result
+ @use_cursor
+ def get_object_list(self, name):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT object FROM property WHERE object LIKE ? ORDER BY object',
+ (name,))
+ return [ row[0] for row in cursor.fetchall() ]
+
+ @use_cursor
+ def get_property(self, object_name, properties):
+ cursor = self.cursor
+ result = []
+ result.append(object_name)
+ result.append(str(len(properties)))
+ stmt = 'SELECT count,value,name FROM property WHERE object LIKE ? AND name LIKE ? ORDER BY count'
+ for prop_name in properties:
+ result.append(prop_name)
+ prop_name = replace_wildcard(prop_name)
+ cursor.execute(stmt, (object_name,prop_name))
+ rows = cursor.fetchall()
+ n_rows = len(rows)
+ result.append(n_rows)
+ if n_rows:
+ for row in rows:
+ result.append(row[1])
+ else:
+ result.append(" ")
+ return result
+
+
+ @use_cursor
+ def get_property_hist(self, object_name, prop_name):
+ cursor = self.cursor
+ result = []
+
+ stmt = 'SELECT DISTINCT id FROM property_hist WHERE object=? AND name LIKE ? ORDER by date'
+ prop_name = replace_wildcard(prop_name)
+ cursor.execute(stmt, (object_name, prop_name))
+
+ stmt = 'SELECT DATE_FORMAT(date,\'%Y-%m-%d %H:%i:%s\'),value,name,count FROM property_hist WHERE id =? AND object =?'
+ for row in cursor.fetchall():
+ idr = row[0]
+
+ cursor.execute(stmt, (idr, object_name))
+ rows = cursor.fetchall()
+ count = len(rows)
+ if rows[3] == 0:
+ count = 0
+ result.append(rows[2])
+ result.append(rows[0])
+ result.append(str(count))
+ for tmp_row in rows:
+ result.append(tmp_row[1])
+
+ return result
+
+ @use_cursor
+ def get_property_list(self, object_name, wildcard):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT name FROM property WHERE object LIKE ? AND name LIKE ? ORDER BY name',
+ (object_name,wildcard))
+ return [ row[0] for row in cursor.fetchall() ]
+
+ @use_cursor
+ def get_server_info(self, server_name):
+ cursor = self.cursor
+ cursor.execute('SELECT host,mode,level FROM server WHERE name =?',
+ (server_name,))
+ result = []
+ result.append(server_name)
+ row = cursor.fetchone()
+ if row is None:
+ result.append(" ")
+ result.append(" ")
+ result.append(" ")
+ else:
+ result.append(row[0])
+ result.append(row[1])
+ result.append(row[2])
+
+ return result
+
+ @use_cursor
+ def get_server_list(self, wildcard):
+ cursor = self.cursor
+ cursor.execute('SELECT DISTINCT server FROM device WHERE server LIKE ? ORDER BY server',
+ (wildcard,))
+ return [ row[0] for row in cursor.fetchall() ]
+
+ def get_server_list(self, wildcard):
+ result = []
+ server_list = self.get_server_list(wildcard)
+ for server in server_list:
+ found = 0
+ server_name = server.split("/")[0]
+ for res in result:
+ if server_name.lower() == res.lower():
+ found = 1
+ if not found:
+ result.append(server_name)
+ return result
+
+ @use_cursor
+ def import_device(self, dev_name):
+ cursor = self.cursor
+ result_long = []
+ result_str = []
+ # Search first by server name and if nothing found by alias
+ # Using OR takes much more time
+ cursor.execute('"SELECT exported,ior,version,pid,server,host,class FROM device WHERE name =?',
+ (dev_name,))
+ rows = cursor.fetchall()
+ if len(rows) == 0:
+ cursor.execute('"SELECT exported,ior,version,pid,server,host,class FROM device WHERE alias =?',
+ (dev_name,))
+ rows = cursor.fetchall()
+ if len(rows) == 0:
+ th_exc(DB_DeviceNotDefined,
+ "device " + dev_name + " not defined in the database !",
+ "DataBase::ImportDevice()")
+ for row in rows:
+ result_str.append(dev_name)
+ result_str.append(row[2])
+ result_str.append(row[4])
+ result_str.append(row[5])
+ result_str.append(row[6])
+ if row[1] != None:
+ result_str.append(row[1])
+ else:
+ result_str.append("")
+ result_long.append(row[0])
+ result_long.append(row[3])
+ result = (result_long, result_str)
+ return result
+
+ @use_cursor
+ def import_event(self, event_name):
+ cursor = self.cursor
+ result_long = []
+ result_str = []
+ cursor.execute('"SELECT exported,ior,version,pid,host FROM event WHERE name =?',
+ (event_name,))
+ rows = cursor.fetchall()
+ if len(rows) == 0:
+ th_exc(DB_DeviceNotDefined,
+ "event " + event_name + " not defined in the database !",
+ "DataBase::ImportEvent()")
+ for row in rows:
+ result_str.append(event_name)
+ result_str.append(row[1])
+ result_str.append(row[2])
+ result_str.append(row[4])
+ exported = -1
+ if row[0] != None:
+ exported = row[0]
+ result_long.append(exported)
+ result_long.append(row[3])
+ result = (result_long, result_str)
+ return result
+
+
+ @use_cursor
+ def info(self):
+ cursor = self.cursor
+ result = []
+ # db name
+ info_str = "TANGO Database " + self.db_name
+ result.append(info_str)
+ # new line
+ result.append("")
+ # get start time of database
+ cursor.execute('SELECT started FROM device WHERE name =?',
+ (self.db_name,))
+ row = cursor.fetchone()
+ info_str = "Running since ..." + str(row[0])
+ result.append(info_str)
+ # new line
+ result.append("")
+ # get number of devices defined
+ cursor.execute('SELECT COUNT(*) FROM device')
+ row = cursor.fetchone()
+ info_str = "Devices defined = " + str(row[0])
+ result.append(info_str)
+ # get number of devices exported
+ cursor.execute('SELECT COUNT(*) FROM device WHERE exported = 1')
+ row = cursor.fetchone()
+ info_str = "Devices exported = " + str(row[0])
+ result.append(info_str)
+ # get number of device servers defined
+ cursor.execute('SELECT COUNT(*) FROM device WHERE class = \"DServer\" ')
+ row = cursor.fetchone()
+ info_str = "Device servers defined = " + str(row[0])
+ result.append(info_str)
+ # get number of device servers exported
+ cursor.execute('SELECT COUNT(*) FROM device WHERE class = \"DServer\" AND exported = 1')
+ row = cursor.fetchone()
+ info_str = "Device servers exported = " + str(row[0])
+ result.append(info_str)
+ # new line
+ result.append("")
+ # get number of device properties
+ cursor.execute('SELECT COUNT(*) FROM property_device')
+ row = cursor.fetchone()
+ info_str = "Device properties defineed = " + str(row[0])
+ cursor.execute('SELECT COUNT(*) FROM property_device_hist')
+ row = cursor.fetchone()
+ info_str = info_str + " [History lgth = " + str(row[0]) + "]"
+ result.append(info_str)
+ # get number of class properties
+ cursor.execute('SELECT COUNT(*) FROM property_class')
+ row = cursor.fetchone()
+ info_str = "Class properties defined = " + str(row[0])
+ cursor.execute('SELECT COUNT(*) FROM property_class_hist')
+ row = cursor.fetchone()
+ info_str = info_str + " [History lgth = " + str(row[0]) + "]"
+ result.append(info_str)
+ # get number of device attribute properties
+ cursor.execute('SELECT COUNT(*) FROM property_attribute_device')
+ row = cursor.fetchone()
+ info_str = "Device attribute properties defined = " + str(row[0])
+ cursor.execute('SELECT COUNT(*) FROM property_attribute_device_hist')
+ row = cursor.fetchone()
+ info_str = info_str + " [History lgth = " + str(row[0]) + "]"
+ result.append(info_str)
+ # get number of class attribute properties
+ cursor.execute('SELECT COUNT(*) FROM property_attribute_class')
+ row = cursor.fetchone()
+ info_str = "Class attribute properties defined = " + str(row[0])
+ cursor.execute('SELECT COUNT(*) FROM property_attribute_class_hist')
+ row = cursor.fetchone()
+ info_str = info_str + " [History lgth = " + str(row[0]) + "]"
+ result.append(info_str)
+ # get number of object properties
+ cursor.execute('SELECT COUNT(*) FROM property')
+ row = cursor.fetchone()
+ info_str = "Object properties defined = " + str(row[0])
+ cursor.execute('SELECT COUNT(*) FROM property_hist')
+ row = cursor.fetchone()
+ info_str = info_str + " [History lgth = " + str(row[0]) + "]"
+ result.append(info_str)
+
+ return result
+
+ @use_cursor
+ def put_attribute_alias(self, attribute_name, attribute_alias):
+ cursor = self.cursor
+ attribute_name = attribute_name.lower()
+ # first check if this alias exists
+ cursor.execute('SELECT alias from attribute_alias WHERE alias=? AND name <> ? ',
+ (attribute_alias,attribute_name))
+ rows = cursor.fetchall()
+ if len(rows) > 0:
+ self.warn_stream("DataBase::DbPutAttributeAlias(): this alias exists already ")
+ th_exc(DB_SQLError,
+ "alias " + attribute_alias + " already exists !",
+ "DataBase::DbPutAttributeAlias()")
+ tmp_names = attribute_name.split("/")
+ if len(tmp_names) != 4:
+ self.warn_stream("DataBase::DbPutAttributeAlias(): attribute name has bad syntax, must have 3 / in it")
+ th_exc(DB_SQLError,
+ "attribute name " + attribute_name + " has bad syntax, must have 3 / in it",
+ "DataBase::DbPutAttributeAlias()")
+ # first delete the current entry (if any)
+ cursor.execute('DELETE FROM attribute_alias WHERE name=?',
+ (attribute_name,))
+ # update the new value for this tuple
+ tmp_device = tmp_names[0] + "/" + tmp_names[1] + "/" + tmp_names[2]
+ tmp_attribute = tmp_names[3]
+ cursor.execute('INSERT attribute_alias SET alias=? ,name=?, device=?,updated=NOW()',
+ (attribute_alias, tmp_device, tmp_attribute))
+
+
+ @use_cursor
+ def put_class_attribute_property(self, class_name, nb_attributes, attr_prop_list):
+ cursor = self.cursor
+ k = 0
+ for i in range(0,nb_attributes):
+ tmp_attribute = attr_prop_list[k]
+ nb_properties = int(attr_prop_list[k+1])
+ for j in range(k+2,k+nb_properties*2+2,2):
+ tmp_name = attr_prop_list[j]
+ tmp_value = attr_prop_list[j+1]
+ # first delete the tuple (device,name,count) from the property table
+ cursor.execute('DELETE FROM property_attribute_class WHERE class LIKE ? AND attribute LIKE ? AND name LIKE ?', (class_name, tmp_attribute, tmp_name))
+ # then insert the new value for this tuple
+ cursor.execute('INSERT INTO property_attribute_class SET class=? ,attribute=?,name=?,count=\'1\',value=?,updated=NULL,accessed=NULL', (class_name, tmp_attribute, tmp_name, tmp_value))
+ # then insert the new value into the history table
+ hist_id = self.get_id("class_attribute", cursor=cursor)
+ cursor.execute('INSERT INTO property_attribute_class_hist SET class=?,attribute=?,name=?,id=?,count=\'1\',value=?', (class_name, tmp_attribute, tmp_name,hist_id,tmp_value))
+
+ self.purge_att_property("property_attribute_class_hist", "class",
+ class_name, tmp_attribute, tmp_name, cursor=cursor)
+ k = k + nb_properties*2+2
+
+ @use_cursor
+ def put_class_attribute_property2(self, class_name, nb_attributes, attr_prop_list):
+ cursor = self.cursor
+ k = 0
+ for i in range(0,nb_attributes):
+ tmp_attribute = attr_prop_list[k]
+ nb_properties = int(attr_prop_list[k+1])
+ for jj in range(0,nb_properties,1):
+ j = k + 2
+ tmp_name = attr_prop_list[j]
+ # first delete the tuple (device,name,count) from the property table
+ cursor.execute('DELETE FROM property_attribute_class WHERE class LIKE ? AND attribute LIKE ? AND name LIKE ?', (class_name, tmp_attribute, tmp_name))
+ n_rows = attr_prop_list[j+1]
+ tmp_count = 0
+ for l in range(j+1,j+n_rows+1,1):
+ tmp_value = attr_prop_list[l+1]
+ tmp_count = tmp_count + 1
+ # then insert the new value for this tuple
+ cursor.execute('INSERT INTO property_attribute_class SET class=? ,attribute=?,name=?,count=?,value=?,updated=NULL,accessed=NULL', (class_name, tmp_attribute, tmp_name, str(tmp_count), tmp_value))
+ # then insert the new value into the history table
+ hist_id = self.get_id("class_attribute", cursor=cursor)
+ cursor.execute('INSERT INTO property_attribute_class_hist SET class=?,attribute=?,name=?,id=?,count=?,value=?', (class_name, tmp_attribute, tmp_name,hist_id, str(tmp_count),tmp_value))
+
+ self.purge_att_property("property_attribute_class_hist", "class",
+ class_name, tmp_attribute, tmp_name, cursor=cursor)
+ k = k + n_rows + 2
+ k = k + 2
+
+ @use_cursor
+ def put_class_property(self, class_name, nb_properties, attr_prop_list):
+ cursor = self.cursor
+ k = 0
+ for i in range(0,nb_properties):
+ tmp_count = 0
+ tmp_name = attr_prop_list[k]
+ n_rows = attr_prop_list[k+1]
+ # first delete all tuples (device,name) from the property table
+ cursor.execute('DELETE FROM property_class WHERE class LIKE ? AND name LIKE ?', (class_name, tmp_name))
+
+ for j in range(k+2,k+n_rows+2,1):
+ tmp_value = attr_prop_list[j]
+ tmp_count = tmp_count+1
+ # then insert the new value for this tuple
+ cursor.execute('INSERT INTO property_class SET class=? ,name=?,count=?,value=?,updated=NULL,accessed=NULL', (class_name, tmp_name, str(tmp_count), tmp_value))
+ # then insert the new value into the history table
+ hist_id = self.get_id("class", cursor=cursor)
+ cursor.execute('INSERT INTO property_class_hist SET class=?,name=?,id=?,count=?,value=?', (class_name, tmp_name,hist_id, str(tmp_count),tmp_value))
+ self.purge_att_property("property_class_hist", "class",
+ class_name, tmp_name, cursor=cursor)
+ k = k + n_rows + 2
+
+ @use_cursor
+ def put_device_alias(self, device_name, device_alias):
+ cursor = self.cursor
+ device_name = device_name.lower()
+ # first check if this alias exists
+ cursor.execute('SELECT alias from device WHERE alias=? AND name <>?',
+ (device_alias, device_name))
+ rows = cursor.fetchall()
+ if len(rows) > 0:
+ self.warn_stream("DataBase::DbPutDeviceAlias(): this alias exists already ")
+ th_exc(DB_SQLError,
+ "alias " + device_alias + " already exists !",
+ "DataBase::DbPutDeviceAlias()")
+ # update the new value for this tuple
+ cursor.execute('UPDATE device SET alias=? ,started=NOW() where name LIKE ?',
+ (device_alias, device_name))
+
+ @use_cursor
+ def put_device_attribute_property(self, device_name, nb_attributes, attr_prop_list):
+ cursor = self.cursor
+ k = 0
+ for i in range(0,nb_attributes):
+ tmp_attribute = attr_prop_list[k]
+ nb_properties = int(attr_prop_list[k+1])
+ for j in range(k+2,k+nb_properties*2+2,2):
+ tmp_name = attr_prop_list[j]
+ tmp_value = attr_prop_list[j+1]
+ # first delete the tuple (device,name,count) from the property table
+ cursor.execute('DELETE FROM property_attribute_device WHERE device LIKE ? AND attribute LIKE ? AND name LIKE ?', (device_name, tmp_attribute, tmp_name))
+ # then insert the new value for this tuple
+ cursor.execute('INSERT INTO property_attribute_device SET device=? ,attribute=?,name=?,count=\'1\',value=?,updated=NULL,accessed=NULL', (device_name, tmp_attribute, tmp_name, tmp_value))
+ # then insert the new value into the history table
+ hist_id = self.get_id("device_attribute", cursor=cursor)
+ cursor.execute('INSERT INTO property_attribute_device_hist SET device=?,attribute=?,name=?,id=?,count=\'1\',value=?', (device_name, tmp_attribute, tmp_name,hist_id,tmp_value))
+
+ self.purge_att_property("property_attribute_device_hist", "device",
+ device_name, tmp_attribute, tmp_name, cursor=cursor)
+ k = k + nb_properties*2+2
+
+
+ @use_cursor
+ def put_device_attribute_property2(self, device_name, nb_attributes, attr_prop_list):
+ cursor = self.cursor
+ k = 0
+ for i in range(0,nb_attributes):
+ tmp_attribute = attr_prop_list[k]
+ nb_properties = int(attr_prop_list[k+1])
+ for jj in range(0,nb_properties,1):
+ j = k + 2
+ tmp_name = attr_prop_list[j]
+ # first delete the tuple (device,name,count) from the property table
+ cursor.execute('DELETE FROM property_attribute_device WHERE device LIKE ? AND attribute LIKE ? AND name LIKE ?', (device_name, tmp_attribute, tmp_name))
+ n_rows = attr_prop_list[j+1]
+ tmp_count = 0
+ for l in range(j+1,j+n_rows+1,1):
+ tmp_value = attr_prop_list[l+1]
+ tmp_count = tmp_count + 1
+ # then insert the new value for this tuple
+ cursor.execute('INSERT INTO property_attribute_device SET device=? ,attribute=?,name=?,count=?,value=?,updated=NULL,accessed=NULL', (device_name, tmp_attribute, tmp_name, str(tmp_count), tmp_value))
+ # then insert the new value into the history table
+ hist_id = self.get_id("device_attribute", cursor=cursor)
+ cursor.execute('INSERT INTO property_attribute_device_hist SET device=?,attribute=?,name=?,id=?,count=?,value=?', (device_name, tmp_attribute, tmp_name,hist_id, str(tmp_count),tmp_value))
+
+ self.purge_att_property("property_attribute_device_hist", "device",
+ device_name, tmp_attribute, tmp_name, cursor=cursor)
+ k = k + n_rows + 2
+ k = k + 2
+
+ @use_cursor
+ def put_device_property(self, device_name, nb_properties, attr_prop_list):
+ cursor = self.cursor
+ k = 0
+ hist_id = self.get_id("device", cursor=cursor)
+ for i in range(0,nb_properties):
+ tmp_count = 0
+ tmp_name = attr_prop_list[k]
+ n_rows = attr_prop_list[k+1]
+ # first delete all tuples (device,name) from the property table
+ cursor.execute('DELETE FROM property_device WHERE device LIKE ? AND name LIKE ?', (device_name, tmp_name))
+
+ for j in range(k+2,k+n_rows+2,1):
+ tmp_value = attr_prop_list[j]
+ tmp_count = tmp_count+1
+ # then insert the new value for this tuple
+ cursor.execute('INSERT INTO property_device SET device=? ,name=?,count=?,value=?,updated=NULL,accessed=NULL', (device_name, tmp_name, str(tmp_count), tmp_value))
+ # then insert the new value into the history table
+ cursor.execute('INSERT INTO property_device_hist SET device=?,name=?,id=?,count=?,value=?', (device_name, tmp_name,hist_id, str(tmp_count),tmp_value))
+ self.purge_att_property("property_device_hist", "device",
+ device_name, tmp_name, cursor=cursor)
+ k = k + n_rows + 2
+
+ @use_cursor
+ def put_property(self, object_name, nb_properties, attr_prop_list):
+ cursor = self.cursor
+ k = 0
+ hist_id = self.get_id("object", cursor=cursor)
+ for i in range(0,nb_properties):
+ tmp_count = 0
+ tmp_name = attr_prop_list[k]
+ n_rows = attr_prop_list[k+1]
+ # first delete the property from the property table
+ cursor.execute('DELETE FROM property WHERE object =? AND name =?', (object_name, tmp_name))
+
+ for j in range(k+2,k+n_rows+2,1):
+ tmp_value = attr_prop_list[j]
+ tmp_count = tmp_count+1
+ # then insert the new value for this tuple
+ cursor.execute('INSERT INTO property SET object=? ,name=?,count=?,value=?,updated=NULL,accessed=NULL', (object_name, tmp_name, str(tmp_count), tmp_value))
+ # then insert the new value into the history table
+ cursor.execute('INSERT INTO property_hist SET object=?,name=?,id=?,count=?,value=?', (object_name, tmp_name,hist_id, str(tmp_count),tmp_value))
+ self.purge_att_property("property_hist", "object",
+ object_name, tmp_name, cursor=cursor)
+ k = k + n_rows + 2
+
+ @use_cursor
+ def put_server_info(self, tmp_server, tmp_host, tmp_mode, tmp_level, tmp_extra):
+ cursor = self.cursor
+ # If it is an empty host name -> get previous host where running
+ previous_host = ""
+ if self.fire_to_starter:
+ if tmp_host == "":
+ adm_dev_name = "dserver/" + tmp_server
+ previous_host = self.get_device_host(adm_dev_name)
+ # first delete the server from the server table
+ cursor.execute('DELETE FROM server WHERE name=?', (tmp_server,))
+ # insert the new info for this server
+ cursor.execute('INSERT INTO server SET name=? ,host=? ,mode=? ,level=?', ( tmp_server, tmp_host, tmp_mode, tmp_level))
+ # Update host's starter to update controlled servers list
+ if self.fire_to_starter:
+ hosts = []
+ if previous_host == "":
+ hosts.append(tmp_host)
+ else:
+ hosts.append(previous_host)
+ self.send_starter_cmd(hosts)
+
+ @use_cursor
+ def uexport_device(self, dev_name):
+ cursor = self.cursor
+ self._info("un-export device(dev_name=%s)", dev_name)
+ cursor.execute('UPDATE device SET exported=0,stopped=NOW() WHERE name LIKE ?', (dev_name,))
+
+ @use_cursor
+ def uexport_event(self, event_name):
+ cursor = self.cursor
+ self._info("un-export event (event_name=%s)", event_name)
+ cursor.execute('UPDATE event SET exported=0,stopped=NOW() WHERE name LIKE ?', (event_name,))
+
+ @use_cursor
+ def uexport_server(self, server_name):
+ cursor = self.cursor
+ self._info("un-export all devices from server ", server_name)
+ cursor.execute('UPDATE device SET exported=0,stopped=NOW() WHERE server LIKE ?', (server_name,))
+
+ @use_cursor
+ def delete_all_device_attribute_property(self, dev_name, attr_list):
+ cursor = self.cursor
+ for attr_name in attr_list:
+ self._info("_delete_all_device_attribute_property(): delete device %s attribute %s property(ies) from database", dev_name, attr_name)
+ #Is there something to delete ?
+ cursor.execute('SELECT DISTINCT name FROM property_attribute_device WHERE device =? AND attribute = ?', (dev_name,attr_name))
+ rows = cursor.fetchall()
+ if len(rows) != 0:
+ cursor.execute('DELETE FROM property_attribute_device WHERE device = ? AND attribute = ?', (dev_name,attr_name))
+ # Mark this property as deleted
+ for row in rows:
+ hist_id = self.get_id('device_attribute', cursor=cursor)
+ cursor.execute('INSERT INTO property_attribute_device_hist SET device=?,attribute=?,name=?,id=?,count=\'0\',value=\'DELETED\'', (dev_name,attr_name,row[0], hist_id))
+ self.purge_att_property("property_attribute_device_hist", "device",
+ dev_name, attr_name, row[0], cursor=cursor)
+
+ @use_cursor
+ def my_sql_select(self, cmd):
+ cursor = self.cursor
+ cursor.execute(cmd)
+ result_long = []
+ result_str = []
+ rows = cursor.fetchall()
+ nb_fields = 0
+ for row in rows:
+ if row == None:
+ result_str.append("")
+ result_long.append(0)
+ else:
+ for field in row:
+ nb_fields = nb_fields + 1
+ if field != None:
+ result_str.append(str(field))
+ result_long.append(1)
+ else:
+ result_str.append("")
+ result_long.append(0)
+ result_long.append(len(rows))
+ result_long.append(nb_fields)
+
+ result = (result_long, result_str)
+ return result
+
+
+
+ @use_cursor
+ def get_csdb_server_list(self):
+ cursor = self.cursor
+
+ cursor.execute('SELECT DISTINCT ior FROM device WHERE exported=1 AND domain=\'sys\' AND family=\'database\'')
+ return [ row[0] for row in cursor.fetchall() ]
+
+ @use_cursor
+ def get_attribute_alias2(self, attr_name):
+ cursor = self.cursor
+ cursor.execute('SELECT alias from attribute_alias WHERE name LIKE ? ',(attr_name,))
+ return [ row[0] for row in cursor.fetchall() ]
+
+ @use_cursor
+ def get_alias_attribute(self, alias_name):
+ cursor = self.cursor
+ cursor.execute('SELECT name from attribute_alias WHERE alias LIKE ? ',(alias_name,))
+ return [ row[0] for row in cursor.fetchall() ]
+
+ @use_cursor
+ def rename_server(self, old_name, new_name):
+ cursor = self.cursor
+ # Check that the new name is not already used
+ new_adm_name = "dserver/" + new_name
+ cursor.execute('SELECT name from device WHERE name = ? ',(new_adm_name,))
+ rows = cursor.fetchall()
+ if len(rows) != 0:
+ th_exc(DB_SQLError,
+ "Device server process name " + attribute_alias + "is already used !",
+ "DataBase::DbRenameServer()")
+
+ # get host where running
+ previous_host = ""
+ if self.fire_to_starter:
+ try:
+ adm_dev = "dserver/" + old_name
+ previous_host = self.get_device_host(adm_dev)
+ except:
+ th_exc(DB_IncorrectServerName,
+ "Server " + old_name + "not defined in database!",
+ "DataBase::DbRenameServer()")
+ # Change ds exec name. This means
+ # 1 - Update the device's server column
+ # 2 - Change the ds admin device name
+ # 3 - Change admin device property (if any)
+ # 4 - Change admin device attribute property (if any)
+
+ old_adm_name = "dserver/" + old_name
+ tmp_new = new_name.split('/')
+ new_exec = tmp_new[0]
+ new_inst = tmp_new[1]
+ new_adm_name = "dserver/" + new_name
+
+ cursor.execute('UPDATE device SET name =?, family =?, mamber =? WHERE name =?', (new_adm_name, new_exec, new_inst, old_adm_name))
+
+ cursor.execute('UPDATE property_device set device=? WHERE device=?', (new_adm_name, old_adm_name))
+
+ cursor.execute('UPDATE property_attribute_device set device=? WHERE device=?', (new_adm_name, old_adm_name))
+
+ # Update host's starter to update controlled servers list
+ if self.fire_to_starter:
+ hosts = []
+ if previous_host == "":
+ hosts.append(tmp_host)
+ else:
+ hosts.append(previous_host)
+ self.send_starter_cmd(hosts)
+
+
class Tango_sqlite3(Tango_dbapi2):
DB_API_NAME = 'sqlite3'
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/pytango.git
More information about the debian-science-commits
mailing list