mirror of
https://github.com/bspeice/elektricity
synced 2024-12-21 23:48:08 -05:00
Move the exception handling to the code that needs it
This commit is contained in:
parent
92c9b5c053
commit
2cdf45cd01
@ -10,16 +10,30 @@ from conf_parser import build_configuration
|
|||||||
|
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
def start_server(server_conf: dict, configurator: Configurator) -> None:
|
def start_server(server_conf: dict, configurator: Configurator) -> None:
|
||||||
try:
|
|
||||||
app = configurator.make_wsgi_app()
|
app = configurator.make_wsgi_app()
|
||||||
|
|
||||||
port = server_conf['port'] if 'port' in server_conf else cmd_args.port
|
port = server_conf['port'] if 'port' in server_conf else cmd_args.port
|
||||||
host = server_conf['host'] if 'host' in server_conf else cmd_args.host
|
host = server_conf['host'] if 'host' in server_conf else cmd_args.host
|
||||||
server = make_server(host, port, app)
|
server = make_server(host, port, app)
|
||||||
|
|
||||||
if cmd_args.verbose:
|
|
||||||
print("Starting server {}:{}".format(host, port))
|
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
default_rc = join(expanduser('~'), '.repodrc')
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--verbose', action='store_true',
|
||||||
|
help='Run server in verbose mode')
|
||||||
|
parser.add_argument('--port', type=int, default=10000,
|
||||||
|
help='Port to use when starting the server')
|
||||||
|
parser.add_argument('--host', type=str, default='0.0.0.0',
|
||||||
|
help='Host address to start the server')
|
||||||
|
parser.add_argument('--configuration', type=str, default=default_rc,
|
||||||
|
help='Configuration file to start the server')
|
||||||
|
|
||||||
|
cmd_args = parser.parse_args()
|
||||||
|
try:
|
||||||
|
server_conf, configurator = build_configuration(cmd_args.configuration)
|
||||||
|
start_server(server_conf, configurator)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print("Unable to find configuration file. Does {} exist?"
|
print("Unable to find configuration file. Does {} exist?"
|
||||||
.format(cmd_args.configuration))
|
.format(cmd_args.configuration))
|
||||||
@ -35,20 +49,3 @@ def start_server(server_conf: dict, configurator: Configurator) -> None:
|
|||||||
'section?')
|
'section?')
|
||||||
if cmd_args.verbose:
|
if cmd_args.verbose:
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
default_rc = join(expanduser('~'), '.repodrc')
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument('--verbose', action='store_true',
|
|
||||||
help='Run server in verbose mode')
|
|
||||||
parser.add_argument('--port', type=int, default=10000,
|
|
||||||
help='Port to use when starting the server')
|
|
||||||
parser.add_argument('--host', type=str, default='0.0.0.0',
|
|
||||||
help='Host address to start the server')
|
|
||||||
parser.add_argument('--configuration', type=str, default=default_rc,
|
|
||||||
help='Configuration file to start the server')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
server_conf, configurator = build_configuration(args.configuration)
|
|
||||||
start_server(server_conf, configurator)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user