Skip to content
Snippets Groups Projects
Commit fdb8b193 authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-544: Wrap repeating check to swallow exceptions that indicate we...

L2SS-544: Wrap repeating check to swallow exceptions that indicate we stop/remove an attribute that is not being archived.
parent f384165b
No related branches found
No related tags found
1 merge request!199L2SS-544: Improve LibConfiguration parsing, and return a dict instead of list...
......@@ -55,6 +55,27 @@ def split_tango_name(tango_fqname:str, tango_type:str):
else:
raise ValueError(f"Invalid value: {tango_type}. Please provide 'device' or 'attribute'.")
def warn_if_attribute_not_found():
"""
Log a warning if an exception is thrown indicating access to an non-existing attribute
was requested, and swallow the exception.
"""
def inner(func):
@wraps(func)
def warn_wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except DevFailed as e:
if e.args[0].reason == 'Attribute not found':
logger.warning(f"Attribute {attribute_name} not found!")
else:
raise
return warn_wrapper
return inner
class Archiver():
"""
The Archiver class implements the basic operations to perform attributes archiving
......@@ -240,21 +261,17 @@ class Archiver():
raise Exception from e
else:
logger.warning(f"Attribute {attr_fullname} will not be archived because polling is set to FALSE!")
@warn_if_attribute_not_found()
def remove_attribute_from_archiver(self, attribute_name:str):
"""
Stops the data archiving of the attribute passed as input, and remove it from the subscriber's list.
"""
attribute_name = attribute_name_from_url(attribute_name)
try:
self.cm.AttributeStop(attribute_name)
self.cm.AttributeRemove(attribute_name)
logger.warning(f"Attribute {attribute_name} removed!")
except DevFailed as e:
if e.args[0].reason == 'Attribute not found':
logger.warning(f"Attribute {attribute_name} not found!")
else:
raise
self.cm.AttributeStop(attribute_name)
self.cm.AttributeRemove(attribute_name)
logger.warning(f"Attribute {attribute_name} removed!")
def remove_attributes_by_device(self,device_name:str,exclude:list=[]):
"""
......@@ -289,33 +306,25 @@ class Archiver():
attr_fullname = attribute_name_from_url(a)
self.remove_attribute_from_archiver(attr_fullname)
@warn_if_attribute_not_found()
def start_archiving_attribute(self, attribute_name:str):
"""
Starts the archiving of the attribute passed as input.
The attribute must be already present in the subscriber's list
"""
attribute_name = attribute_name_from_url(attribute_name)
try:
self.cm.AttributeStart(attribute_name)
except DevFailed as e:
if e.args[0].reason == "Attribute not found":
logger.warning(f"Attribute {attribute_name} not found!")
else:
raise
self.cm.AttributeStart(attribute_name)
@warn_if_attribute_not_found()
def stop_archiving_attribute(self, attribute_name:str):
"""
Stops the archiving of the attribute passed as input.
The attribute must be already present in the subscriber's list
"""
attribute_name = attribute_name_from_url(attribute_name)
try:
self.cm.AttributeStop(attribute_name)
except DevFailed as e:
if e.args[0].reason == "Attribute not found":
logger.warning(f"Attribute {attribute_name} not found!")
else:
raise
self.cm.AttributeStop(attribute_name)
def is_attribute_archived(self,attribute_name:str):
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment