pep-0008 cleanup

From pep-0008: Method Names and Instance Variables

Use the function naming rules: lowercase with words separated by underscores as
necessary to improve readability.
more_events
OpenGnSys Support Team 2020-02-21 11:51:43 +01:00 committed by Alvaro Neira Ayuso
parent 54c0ebf098
commit 3917c3675f
3 changed files with 46 additions and 46 deletions

View File

@ -13,12 +13,12 @@ from signal import signal, SIGPIPE, SIG_DFL
def main():
signal(SIGPIPE, SIG_DFL)
ogconfig = ogConfig()
if (not ogconfig.parserFile('cfg/ogagent.cfg')):
if (not ogconfig.parser_file('cfg/ogagent.cfg')):
print ('Error: Parsing configuration file')
return 0
ip = ogconfig.getValueSection('opengnsys', 'ip')
port = ogconfig.getValueSection('opengnsys', 'port')
ip = ogconfig.get_value_section('opengnsys', 'ip')
port = ogconfig.get_value_section('opengnsys', 'port')
client = ogClient(ip, int(port))
client.connect()

View File

@ -12,21 +12,21 @@ class ogConfig:
def __init__(self):
self.parser = configparser.ConfigParser()
def parserFile(self, path):
def parser_file(self, path):
self.parser.read(path)
if len(self.parser.sections()) == 0:
return False
return True
def getSections(self):
def get_sections(self):
return self.parser.sections()
def getContainsSection(self, section):
def get_contains_section(self, section):
return section in self.parser
def getValueSection(self, section, key):
if (not self.getContainsSection(section)):
def get_value_section(self, section, key):
if (not self.get_contains_section(section)):
return ''
return self.parser[section][key]

View File

@ -21,21 +21,21 @@ from src.restRequest import *
if platform.system() == 'Linux':
from src.linux import ogOperations
class jsonResponse():
class jsonBody():
def __init__(self, dictionary=None):
if dictionary:
self.jsontree = dictionary
else:
self.jsontree = {}
def addElement(self, key, value):
def add_element(self, key, value):
self.jsontree[key] = value
def dumpMsg(self):
def dump(self):
return json.dumps(self.jsontree)
class restResponse():
def __init__(self, response, jsonResp=None):
def __init__(self, response, json_body=None):
self.msg = ''
if response == ogResponses.BAD_REQUEST:
self.msg = 'HTTP/1.0 400 Bad Request'
@ -52,10 +52,10 @@ class restResponse():
self.msg += '\r\n'
if jsonResp:
self.msg += 'Content-Length: ' + str(len(jsonResp.dumpMsg()))
if json_body:
self.msg += 'Content-Length: ' + str(len(json_body.dump()))
self.msg += '\r\nContent-Type: application/json'
self.msg += '\r\n\r\n' + jsonResp.dumpMsg()
self.msg += '\r\n\r\n' + json_body.dump()
else:
self.msg += '\r\n'
@ -78,9 +78,9 @@ class ogThread():
return
if request.getEcho():
jsonResp = jsonResponse()
jsonResp.addElement('out', shellout)
response = restResponse(ogResponses.OK, jsonResp)
json_body = jsonBody()
json_body.add_element('out', shellout)
response = restResponse(ogResponses.OK, json_body)
client.send(response.get())
else:
response = restResponse(ogResponses.OK)
@ -112,12 +112,12 @@ class ogThread():
client.send(response.get())
return
jsonResp = jsonResponse()
jsonResp.addElement('partition', request.getPartition())
json_body = jsonBody()
json_body.add_element('partition', request.getPartition())
with open(path, 'r') as f:
jsonResp.addElement('software', f.read())
json_body.add_element('software', f.read())
response = restResponse(ogResponses.OK, jsonResp)
response = restResponse(ogResponses.OK, json_body)
client.send(response.get())
def hardware(client, path, ogRest):
@ -128,11 +128,11 @@ class ogThread():
client.send(response.get())
return
jsonResp = jsonResponse()
json_body = jsonBody()
with open(path, 'r') as f:
jsonResp.addElement('hardware', f.read())
json_body.add_element('hardware', f.read())
response = restResponse(ogResponses.OK, jsonResp)
response = restResponse(ogResponses.OK, json_body)
client.send(response.get())
def setup(client, request, ogRest):
@ -143,9 +143,9 @@ class ogThread():
client.send(response.get())
return
jsonResp = jsonResponse(out)
json_body = jsonBody(out)
response = restResponse(ogResponses.OK, jsonResp)
response = restResponse(ogResponses.OK, json_body)
client.send(response.get())
def image_restore(client, request, ogRest):
@ -156,12 +156,12 @@ class ogThread():
client.send(response.get())
return
jsonResp = jsonResponse()
jsonResp.addElement('disk', request.getDisk())
jsonResp.addElement('partition', request.getPartition())
jsonResp.addElement('image_id', request.getId())
json_body = jsonBody()
json_body.add_element('disk', request.getDisk())
json_body.add_element('partition', request.getPartition())
json_body.add_element('image_id', request.getId())
response = restResponse(ogResponses.OK, jsonResp)
response = restResponse(ogResponses.OK, json_body)
client.send(response.get())
def image_create(client, path, request, ogRest):
@ -172,17 +172,17 @@ class ogThread():
client.send(response.get())
return
jsonResp = jsonResponse()
jsonResp.addElement('disk', request.getDisk())
jsonResp.addElement('partition', request.getPartition())
jsonResp.addElement('code', request.getCode())
jsonResp.addElement('id', request.getId())
jsonResp.addElement('name', request.getName())
jsonResp.addElement('repository', request.getRepo())
json_body = jsonBody()
json_body.add_element('disk', request.getDisk())
json_body.add_element('partition', request.getPartition())
json_body.add_element('code', request.getCode())
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:
jsonResp.addElement('software', f.read())
json_body.add_element('software', f.read())
response = restResponse(ogResponses.OK, jsonResp)
response = restResponse(ogResponses.OK, json_body)
client.send(response.get())
def refresh(client, ogRest):
@ -193,9 +193,9 @@ class ogThread():
client.send(response.get())
return
jsonResp = jsonResponse(out)
json_body = jsonBody(out)
response = restResponse(ogResponses.OK, jsonResp)
response = restResponse(ogResponses.OK, json_body)
client.send(response.get())
class ogResponses(Enum):
@ -274,10 +274,10 @@ class ogRest():
threading.Thread(target=ogThread.poweroff).start()
def process_probe(self, client):
jsonResp = jsonResponse()
jsonResp.addElement('status', 'OPG')
json_body = jsonBody()
json_body.add_element('status', 'OPG')
response = restResponse(ogResponses.OK, jsonResp)
response = restResponse(ogResponses.OK, json_body)
client.send(response.get())
def process_shellrun(self, client, request):