From 8e6da8a16af760fee1909e92af1281c8b0f357fa Mon Sep 17 00:00:00 2001 From: Igor Chudov Date: Fri, 15 Nov 2019 16:35:27 +0400 Subject: [PATCH] Handle error of missing control --- gpoa/control/__init__.py | 15 +++++++++++++-- gpoa/main.py | 5 ++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/gpoa/control/__init__.py b/gpoa/control/__init__.py index 438ff38..028363a 100644 --- a/gpoa/control/__init__.py +++ b/gpoa/control/__init__.py @@ -6,6 +6,8 @@ class control: self.control_name = name self.control_value = value self.possible_values = self._query_control_values() + if self.possible_values == None: + raise Exception('Unable to query possible values') def _query_control_values(self): proc = subprocess.Popen(['sudo', 'control', self.control_name, 'list'], stdout=subprocess.PIPE) @@ -13,6 +15,10 @@ class control: values = line.split() return values + def _map_control_status(self, int_status): + str_status = self.possible_values[int_status].decode() + return str_status + def get_control_name(self): return self.control_name @@ -22,6 +28,11 @@ class control: return line.rstrip('\n\r') def set_control_status(self): - print('Setting control {} to {}'.format(self.control_name, self.control_value)) - proc = subprocess.Popen(['sudo', 'control', self.control_name, status], stdout=subprocess.PIPE) + status = self._map_control_status(self.control_value) + print('Setting control {} to {}'.format(self.control_name, status)) + + try: + proc = subprocess.Popen(['sudo', 'control', self.control_name, status], stdout=subprocess.PIPE) + except: + print('Unable to set {} to {}'.format(self.control_name, status)) diff --git a/gpoa/main.py b/gpoa/main.py index 6acc242..d35cf4f 100755 --- a/gpoa/main.py +++ b/gpoa/main.py @@ -242,7 +242,10 @@ class control_applier(applier_frontend): self.control_settings = self._get_controls(self.polparsers) self.controls = [] for setting in self.control_settings: - self.controls.append(control.control(setting.valuename, setting.data)) + try: + self.controls.append(control.control(setting.valuename, setting.data)) + except: + print('Unable to work with control: {}'.format(setting.valuename)) #for e in polfile.pol_file.entries: # print('{}:{}:{}:{}:{}'.format(e.type, e.data, e.valuename, e.keyname))