From 5743e0769281e3c998507d6407908f9664eb5d94 Mon Sep 17 00:00:00 2001 From: thijs snijder <snijder@astron.nl> Date: Thu, 21 Apr 2022 11:53:34 +0200 Subject: [PATCH] began processing review --- .../tangostationcontrol/clients/snmp_client.py | 14 ++++---------- .../tangostationcontrol/devices/snmp_device.py | 7 +++---- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/tangostationcontrol/tangostationcontrol/clients/snmp_client.py b/tangostationcontrol/tangostationcontrol/clients/snmp_client.py index 1aa527e91..012864645 100644 --- a/tangostationcontrol/tangostationcontrol/clients/snmp_client.py +++ b/tangostationcontrol/tangostationcontrol/clients/snmp_client.py @@ -52,13 +52,7 @@ class SNMP_client(CommClient): self.connected = True - def _setup_annotation(self, annotation): - """ - The SNMP client uses a dict and takes the following keys: - mib: the mib name - name: name of the value to read - index (optional) the index if the value thats being read from is a table. - """ + def _process_annotation(self, annotation): # check if the 'mib' and 'name' keys are present if 'mib' in annotation and 'name' in annotation: @@ -94,7 +88,7 @@ class SNMP_client(CommClient): """ # process the annotation - mib, name, idx = self._setup_annotation(annotation) + mib, name, idx = self._process_annotation(annotation) # get all the necessary data to set up the read/write functions from the attribute_wrapper dim_x, dim_y, dtype = self.setup_value_conversion(attribute) @@ -236,10 +230,9 @@ class snmp_attribute: class mib_loader: - def __init__(self): + def __init__(self, mib_dir :str): self.mibBuilder = builder.MibBuilder() - def set_pymib_dir(self, mib_dir : str): abs_path = str(Path().absolute()).replace("\\", "/") if mib_dir[0] != "/": @@ -250,6 +243,7 @@ class mib_loader: mib_source = builder.DirMibSource(dir_path) self.mibBuilder.addMibSources(mib_source) + def load_pymib(self, mib_name): self.mibBuilder.loadModule(mib_name) diff --git a/tangostationcontrol/tangostationcontrol/devices/snmp_device.py b/tangostationcontrol/tangostationcontrol/devices/snmp_device.py index 15ff0ca5e..b8d16945a 100644 --- a/tangostationcontrol/tangostationcontrol/devices/snmp_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/snmp_device.py @@ -109,8 +109,7 @@ class SNMP(lofar_device): def init_device(self): super().init_device() - # create the mib_loader - loader = mib_loader() + # if the string doesn't start with '/' it is a relative directory and we need to prepend the full path + '/' if self.SNMP_rel_mib_dir[0] != "/": @@ -119,8 +118,8 @@ class SNMP(lofar_device): # if the string does start with mib_path = self.SNMP_rel_mib_dir - # set the directory with the compiled mib files. - loader.set_pymib_dir(mib_path) + # create the mib_loader and set the mib path + loader = mib_loader(mib_path) for i in self.attr_list(): try: -- GitLab