Add error and warning functions and use camelcase for getConfig

pull/1/head
Mark Veidemanis 7 years ago
parent 021a7851cc
commit 1fbcec3931

@ -14,6 +14,13 @@ def log(data):
def debug(data):
print("[DEBUG]", data)
def warn(data):
print("[WARNING]", data)
def error(data):
print("[ERROR]", data)
exit(1)
class Base(Protocol):
def __init__(self, addr):
self.addr = addr
@ -38,9 +45,9 @@ class Base(Protocol):
if self.addr in connections.keys():
del connections[self.addr]
else:
debug("Tried to remove a non-existant connection.")
warn("Tried to remove a non-existant connection.")
else:
debug("Tried to remove a connection from a listener that wasn't running.")
warn("Tried to remove a connection from a listener that wasn't running.")
class BaseFactory(Factory):
def buildProtocol(self, addr):
@ -57,21 +64,19 @@ class BaseFactory(Factory):
else:
return
def getconfig():
def getConfig():
with open("config.json", "r") as f:
config = load(f)
if set(["port", "bind", "usessl"]).issubset(set(config.keys())):
if config["usessl"] == True:
if not set(["cert", "key"]).issubset(set(config.keys())):
print("SSL is on but certificate or key is not defined")
exit(1)
error("SSL is on but certificate or key is not defined")
return config
else:
print("Mandatory values missing from config")
exit(1)
error("Mandatory values missing from config")
if __name__ == "__main__":
config = getconfig()
config = getConfig()
listener = BaseFactory()
if config["usessl"] == True:

Loading…
Cancel
Save