mirror of https://git.48k.eu/ogclient
Fix parseGetConf(...) configuration parsing
This patch also reformats the response to the /refresh command.more_events
parent
f86999da0c
commit
e96e187825
|
@ -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'):
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue