summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2020-01-31 13:17:24 +0100
committerAlvaro Neira Ayuso <aneira@soleta.eu>2020-02-03 10:15:49 +0100
commite96e187825ad4e03904b23697215a1bb58bfe3f0 (patch)
tree34e00beec791ce297d3f57b692c0a60a3148c311 /src
parentf86999da0c150d2a6976ba69a352164b55c52639 (diff)
Fix parseGetConf(...) configuration parsing
This patch also reformats the response to the /refresh command.
Diffstat (limited to 'src')
-rw-r--r--src/linux/ogOperations.py43
-rw-r--r--src/ogRest.py11
-rw-r--r--src/restRequest.py2
3 files changed, 29 insertions, 27 deletions
diff --git a/src/linux/ogOperations.py b/src/linux/ogOperations.py
index e41bb86..73eb5e1 100644
--- a/src/linux/ogOperations.py
+++ b/src/linux/ogOperations.py
@@ -12,28 +12,29 @@ import subprocess
OG_PATH = '/opt/opengnsys/'
def parseGetConf(out):
- listConfigs = []
- disk = -1;
-
+ parsed = {'serial_number': '',
+ 'disk_setup': '',
+ 'partition_setup': list()}
configs = out.split('\n')
- configs = filter(None, configs)
- for item in configs:
- i = 0
- json = {}
- val = item.rstrip().split('\t')
- while i < len(val):
- val[i] = val[i].split('=')[1]
- i += 1
-
- json['partition'] = val[1]
- json['code'] = val[4]
- json['filesystem'] = val[2]
- json['size'] = val[5]
- json['format'] = val[6]
- disk = val[0]
- listConfigs.append(json)
-
- return [disk, listConfigs]
+ for line in configs[:-1]:
+ if 'ser=' in line:
+ parsed['serial_number'] = line.partition('ser=')[2]
+ else:
+ part_setup = {}
+ params = dict(param.split('=') for param in line.split('\t'))
+ # Parse partition configuration.
+ part_setup['disk'] = params['disk']
+ part_setup['partition'] = params['par']
+ part_setup['code'] = params['cpt']
+ part_setup['filesystem'] = params['fsi']
+ part_setup['os'] = params['soi']
+ part_setup['size'] = params['tam']
+ part_setup['used_size'] = params['uso']
+ if part_setup['partition'] == '0':
+ parsed['disk_setup'] = part_setup
+ else:
+ parsed['partition_setup'].append(part_setup)
+ return parsed
def poweroff():
if os.path.exists('/scripts/oginit'):
diff --git a/src/ogRest.py b/src/ogRest.py
index f9913c8..6fb0dc0 100644
--- a/src/ogRest.py
+++ b/src/ogRest.py
@@ -22,8 +22,11 @@ if platform.system() == 'Linux':
from src.linux import ogOperations
class jsonResponse():
- def __init__(self):
- self.jsontree = {}
+ def __init__(self, dictionary=None):
+ if dictionary:
+ self.jsontree = dictionary
+ else:
+ self.jsontree = {}
def addElement(self, key, value):
self.jsontree[key] = value
@@ -199,9 +202,7 @@ class ogThread():
client.send(response.get())
return
- jsonResp = jsonResponse()
- jsonResp.addElement('disk', out[0])
- jsonResp.addElement('partition_setup', out[1])
+ jsonResp = jsonResponse(out)
response = restResponse(ogResponses.OK, jsonResp)
client.send(response.get())
diff --git a/src/restRequest.py b/src/restRequest.py
index c9d4881..9b26cb2 100644
--- a/src/restRequest.py
+++ b/src/restRequest.py
@@ -98,7 +98,7 @@ class restRequest:
if "id" in body:
self.id = json_param["id"]
- if "code" in body:
+ if "code" in json_param:
self.code = json_param["code"]
def getHeaderLine(self):