From a2af8e21f85e06e48434999409d39f080298ffcc Mon Sep 17 00:00:00 2001
From: stedif <stefano.difrischia@inaf.it>
Date: Mon, 14 Mar 2022 12:55:36 +0100
Subject: [PATCH] L2SS-405: refine documentation and exception handling

---
 .../tangostationcontrol/toolkit/archiver.py         |  8 ++++++--
 .../toolkit/archiver_configurator.py                | 13 +++++++++----
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/tangostationcontrol/tangostationcontrol/toolkit/archiver.py b/tangostationcontrol/tangostationcontrol/toolkit/archiver.py
index 60595b3b7..dab6e15c6 100644
--- a/tangostationcontrol/tangostationcontrol/toolkit/archiver.py
+++ b/tangostationcontrol/tangostationcontrol/toolkit/archiver.py
@@ -154,9 +154,11 @@ class Archiver():
                 # Add the attribute to the archiver setting either specific or global parameters
                 self.add_attribute_to_archiver(att_fqname, dev_polling_time, archive_period or dev_archive_period, dev_strategy,
                                                                 abs_change or dev_archive_abs_change, rel_change or dev_archive_rel_change)
-        except Exception as e:
+        except DevFailed as e:
             if 'already subscribed' in str(e):
                 logger.warning(f"Multiple entries of Attribute {device}'/'{att} in config file")
+            else:
+                raise
     
     def configure_for_production(self, config_dict:dict, device:str):
         """
@@ -185,9 +187,11 @@ class Archiver():
             for att in exclude_att_list:
                 att_fqname = attribute_fqdn(f"{device}/{att}")
                 self.remove_attribute_from_archiver(att_fqname)
-        except Exception as e:
+        except DevFailed as e:
             if 'already subscribed' in str(e):
                 logger.warning(f"Multiple entries of Attribute {device}'/'{att} in config file")
+            else:
+                raise
 
     def add_event_subscriber(self, es_name:str=None):
         """
diff --git a/tangostationcontrol/tangostationcontrol/toolkit/archiver_configurator.py b/tangostationcontrol/tangostationcontrol/toolkit/archiver_configurator.py
index 739c53994..848d23641 100644
--- a/tangostationcontrol/tangostationcontrol/toolkit/archiver_configurator.py
+++ b/tangostationcontrol/tangostationcontrol/toolkit/archiver_configurator.py
@@ -2,7 +2,7 @@
 
 """
 
-Functions related to the managing of archiver configuration JSON file
+Functions related to the managing of the archiver configuration JSON file
 
 """
 import logging
@@ -11,7 +11,9 @@ from tangostationcontrol.toolkit.archiver_util import get_attributes_from_suffix
 logger = logging.getLogger()
 
 def _get_archiving_parameters(attribute:str):
-    """Helper function that returns four archiving parameters defined in a JSON file"""
+    """Helper function that returns the following archiving parameters defined in a JSON file:
+    archive period [ms], event period [ms], absolute change, relative change
+    """
     archive_period =    int(attribute['archive_period'])
     event_period =      int(attribute['event_period']) 
     abs_change =        attribute['abs_change'] and int(attribute['abs_change'])
@@ -20,7 +22,8 @@ def _get_archiving_parameters(attribute:str):
 
 def get_parameters_from_attribute(device_name:str, attribute_name:str, config_dict:dict, environment: str):
     """
-    Return the archiving parameters defined in the configuration file for a certain attribute
+    Return the archiving parameters  ( see ref.: '_get_archiving_parameters' )
+    defined in the configuration file for a certain attribute
     """
     if environment == 'development':
         # Search if the attribute parameters are listed inside the device configuration
@@ -64,7 +67,9 @@ def get_exclude_attribute_list(device:str, config_dict:dict):
     return exclude_att_list
 
 def get_global_env_parameters(config_dict:dict, environment:str):
-    """Return the archiving parameters defined in the 'global_variable' section of the JSON configuration file"""
+    """Return the following archiving parameters defined in the 'global_variable' section of the JSON configuration file:
+    polling time [ms], absolute change, relative change, archive period [ms], event period [ms] and strategy
+    """
     var_dict = config_dict['_global_variables']
     # Archiving parameters retrieved from JSON file
     polling_time = int(var_dict[environment]['polling_time'])
-- 
GitLab