From 2e3d47b7b8db69edb5d550ccc4a46fd6512fc031 Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Fri, 17 Apr 2020 16:59:48 +0200 Subject: Avoid writting /software output to a file --- src/linux/ogOperations.py | 5 ++++- src/ogRest.py | 9 ++++----- src/virtual/ogOperations.py | 6 +----- 3 files changed, 9 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/linux/ogOperations.py b/src/linux/ogOperations.py index fcbcc69..d0bbeeb 100644 --- a/src/linux/ogOperations.py +++ b/src/linux/ogOperations.py @@ -117,7 +117,10 @@ class OgLinuxOperations: except: raise ValueError('Error: Incorrect command value') - return output.decode('utf-8') + software = '' + with open(path, 'r') as f: + software = f.read() + return software def hardware(self, path, ogRest): try: diff --git a/src/ogRest.py b/src/ogRest.py index 24c8a70..4fb2bba 100644 --- a/src/ogRest.py +++ b/src/ogRest.py @@ -119,7 +119,7 @@ class ogThread(): def software(client, request, path, ogRest): try: - ogRest.operations.software(request, path, ogRest) + software = ogRest.operations.software(request, path, ogRest) except ValueError as err: response = restResponse(ogResponses.INTERNAL_ERR) client.send(response.get()) @@ -128,8 +128,7 @@ class ogThread(): json_body = jsonBody() json_body.add_element('partition', request.getPartition()) - with open(path, 'r') as f: - json_body.add_element('software', f.read()) + json_body.add_element('software', software) response = restResponse(ogResponses.OK, json_body) client.send(response.get()) @@ -188,6 +187,7 @@ class ogThread(): def image_create(client, path, request, ogRest): try: ogRest.operations.image_create(path, request, ogRest) + software = ogRest.operations.software(request, path, ogRest) except ValueError as err: response = restResponse(ogResponses.INTERNAL_ERR) client.send(response.get()) @@ -201,8 +201,7 @@ class ogThread(): json_body.add_element('id', request.getId()) json_body.add_element('name', request.getName()) json_body.add_element('repository', request.getRepo()) - with open(path, 'r') as f: - json_body.add_element('software', f.read()) + json_body.add_element('software', software) response = restResponse(ogResponses.OK, json_body) client.send(response.get()) diff --git a/src/virtual/ogOperations.py b/src/virtual/ogOperations.py index a9cf06b..bc18dd4 100644 --- a/src/virtual/ogOperations.py +++ b/src/virtual/ogOperations.py @@ -358,11 +358,7 @@ class OgVirtualOperations: software += [h.node_name(x) for x in h.node_children(key)] os.remove('win_reg') - with open(path, 'w+') as f: - f.seek(0) - for program in software: - f.write(f'{program}\n') - f.truncate() + return '\n'.join(software) def parse_pci(self, path='/usr/share/misc/pci.ids'): data = {} -- cgit v1.2.3-18-g5258