From 680214317eef44f86d99d329f886e56743596def Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Wed, 5 Feb 2020 12:39:04 +0100 Subject: Fix /image/create execution and response --- src/linux/ogOperations.py | 12 ++++++++++-- src/ogRest.py | 7 ++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/linux/ogOperations.py b/src/linux/ogOperations.py index e941864..e9592ff 100644 --- a/src/linux/ogOperations.py +++ b/src/linux/ogOperations.py @@ -151,9 +151,15 @@ def image_create(path, request, ogRest): partition = request.getPartition() name = request.getName() repo = request.getRepo() + cmd_software = f'{OG_PATH}interfaceAdm/InventarioSoftware {disk} ' \ + f'{partition} {path}' + cmd_create_image = f'{OG_PATH}interfaceAdm/CrearImagen {disk} ' \ + f'{partition} {name} {repo}' try: - ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/InventarioSoftware', disk, partition, path], stdout=subprocess.PIPE, shell=True) + ogRest.proc = subprocess.Popen([cmd_software], + stdout=subprocess.PIPE, + shell=True) (output, error) = ogRest.proc.communicate() except: raise ValueError('Error: Incorrect command value') @@ -162,7 +168,9 @@ def image_create(path, request, ogRest): return try: - ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/CrearImagen', disk, partition, name, repo], stdout=subprocess.PIPE, shell=True) + ogRest.proc = subprocess.Popen([cmd_create_image], + stdout=subprocess.PIPE, + shell=True) ogRest.proc.communicate() except: raise ValueError('Error: Incorrect command value') diff --git a/src/ogRest.py b/src/ogRest.py index 7606d8b..0d51d6a 100644 --- a/src/ogRest.py +++ b/src/ogRest.py @@ -113,7 +113,6 @@ class ogThread(): return jsonResp = jsonResponse() - jsonResp.addElement('disk', request.getDisk()) jsonResp.addElement('partition', request.getPartition()) f = open(path, "r") @@ -180,10 +179,8 @@ class ogThread(): jsonResp.addElement('id', request.getId()) jsonResp.addElement('name', request.getName()) jsonResp.addElement('repository', request.getRepo()) - f = open(path, "r") - lines = f.readlines() - f.close() - jsonResp.addElement('software', lines[0]) + with open(path, 'r') as f: + jsonResp.addElement('software', f.read()) response = restResponse(ogResponses.OK, jsonResp) client.send(response.get()) -- cgit v1.2.3-18-g5258