Add error and warning functions and use camelcase for getConfig
This commit is contained in:
parent
021a7851cc
commit
1fbcec3931
|
@ -14,6 +14,13 @@ def log(data):
|
||||||
def debug(data):
|
def debug(data):
|
||||||
print("[DEBUG]", data)
|
print("[DEBUG]", data)
|
||||||
|
|
||||||
|
def warn(data):
|
||||||
|
print("[WARNING]", data)
|
||||||
|
|
||||||
|
def error(data):
|
||||||
|
print("[ERROR]", data)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
class Base(Protocol):
|
class Base(Protocol):
|
||||||
def __init__(self, addr):
|
def __init__(self, addr):
|
||||||
self.addr = addr
|
self.addr = addr
|
||||||
|
@ -38,9 +45,9 @@ class Base(Protocol):
|
||||||
if self.addr in connections.keys():
|
if self.addr in connections.keys():
|
||||||
del connections[self.addr]
|
del connections[self.addr]
|
||||||
else:
|
else:
|
||||||
debug("Tried to remove a non-existant connection.")
|
warn("Tried to remove a non-existant connection.")
|
||||||
else:
|
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):
|
class BaseFactory(Factory):
|
||||||
def buildProtocol(self, addr):
|
def buildProtocol(self, addr):
|
||||||
|
@ -57,21 +64,19 @@ class BaseFactory(Factory):
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
def getconfig():
|
def getConfig():
|
||||||
with open("config.json", "r") as f:
|
with open("config.json", "r") as f:
|
||||||
config = load(f)
|
config = load(f)
|
||||||
if set(["port", "bind", "usessl"]).issubset(set(config.keys())):
|
if set(["port", "bind", "usessl"]).issubset(set(config.keys())):
|
||||||
if config["usessl"] == True:
|
if config["usessl"] == True:
|
||||||
if not set(["cert", "key"]).issubset(set(config.keys())):
|
if not set(["cert", "key"]).issubset(set(config.keys())):
|
||||||
print("SSL is on but certificate or key is not defined")
|
error("SSL is on but certificate or key is not defined")
|
||||||
exit(1)
|
|
||||||
return config
|
return config
|
||||||
else:
|
else:
|
||||||
print("Mandatory values missing from config")
|
error("Mandatory values missing from config")
|
||||||
exit(1)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
config = getconfig()
|
config = getConfig()
|
||||||
|
|
||||||
listener = BaseFactory()
|
listener = BaseFactory()
|
||||||
if config["usessl"] == True:
|
if config["usessl"] == True:
|
||||||
|
|
Loading…
Reference in New Issue