Avoid writting /software output to a file

more_events
Roberto Hueso Gómez 2020-04-17 16:59:48 +02:00
parent 7ccc498014
commit 2e3d47b7b8
3 changed files with 9 additions and 11 deletions

View File

@ -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:

View File

@ -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())

View File

@ -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 = {}