Commit eae9d81f authored by Klaus-Uwe Mitterer's avatar Klaus-Uwe Mitterer

Return None when getSetting() fails

parent 780df5ab
Pipeline #171 skipped
......@@ -4,12 +4,14 @@ import setuptools, servertools, socketserver, syslog, threading
if __name__ == "__main__":
socketserver.TCPServer.allow_reuse_address = True
bind = setuptools.getSetting("Server", "bind") or "0.0.0.0"
port = int(setuptools.getSetting("Server", "port")) or 5747
try:
server = servertools.TCPServer((setuptools.getSetting("Server", "bind"), int(setuptools.getSetting("Server", "port"))), servertools.TCPHandler)
server = servertools.TCPServer((bind, port), servertools.TCPHandler)
except:
servertools.logger("Unable to bind on %s:%s. Make sure the port is not in use or use a different port." % (setuptools.getSetting("Server", "bind"), setuptools.getSetting("Server", "port")))
servertools.logger("Unable to bind on %s:%i. Make sure the port is not in use or use a different port." % (bind, port))
servertools.shutdown(status=1)
servertools.logger("Kumi Status server running on %s:%s." % (setuptools.getSetting("Server", "bind"), setuptools.getSetting("Server", "port")))
servertools.logger("Kumi Status server running on %s:%i." % (bind, port))
try:
thread = threading.Thread(target=server.serve_forever(), daemon=True)
......
......@@ -6,13 +6,20 @@ class SetupException(Exception):
def __str__(self):
return "Seems like config.cfg has not been created yet. Run setup.py to do so."
def getSetting(section, setting):
config = configparser.RawConfigParser()
config.read(conffile)
return config.get(section, setting)
def getSetting(section, setting, exception = False):
try:
config = configparser.RawConfigParser()
config.read(conffile)
return config.get(section, setting)
except:
if exception:
raise SetupException()
return None
def getListSetting(section, setting):
def getListSetting(section, setting, exception = False):
config = configparser.RawConfigParser()
config.read(conffile)
lit = config.get(section, setting)
if lit == None and exception:
raise SetupException()
return ast.literal_eval(lit)
import setuptools, tweepy
def cke():
try:
return setuptools.getSetting("Twitter", "cke")
except:
raise setuptools.SetupException()
return setuptools.getSetting("Twitter", "cke", True)
def cse():
try:
return setuptools.getSetting("Twitter", "cse")
except:
raise setuptools.SetupException()
return setuptools.getSetting("Twitter", "cse", True)
def ato():
try:
return setuptools.getSetting("Twitter", "ato")
except:
raise setuptools.SetupException()
return setuptools.getSetting("Twitter", "ato", True)
def ase():
try:
return setuptools.getSetting("Twitter", "ase")
except:
raise setuptools.SetupException()
return setuptools.getSetting("Twitter", "ase", True)
def user():
return twObject().whoami()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment