X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/cards/%7B%7Bcard_id%7D%7D/static/git-logo.png?a=blobdiff_plain;f=run.py;h=ef6aeab6b7fd56a93ed3c9e76a7b5bbfe532b68c;hb=9c3ba57169fdc71d3ffefd4c7c20cae4e89f9c9c;hp=644fc4abbf5aa7fcc1e7cd410d931e0f1af8798f;hpb=b557c789f4eec704db0e6276390395fac5d8db9e;p=plomtask diff --git a/run.py b/run.py index 644fc4a..ef6aeab 100755 --- a/run.py +++ b/run.py @@ -1,15 +1,32 @@ #!/usr/bin/env python3 """Call this to start the application.""" from sys import exit as sys_exit +from os import environ from plomtask.misc import HandledException from plomtask.http import TaskHandler, TaskServer +from plomtask.db import DatabaseFile +PATH_DB = environ.get('PATH_DB') HTTP_PORT = 8082 +TEMPLATES_DIR = 'templates' +DB_CREATION_ASK = 'Database file not found. Create? Y/n\n' if __name__ == '__main__': try: - server = TaskServer(('localhost', HTTP_PORT), TaskHandler) + if not PATH_DB: + raise HandledException('PATH_DB not set.') + db_file = DatabaseFile(PATH_DB) + if not db_file.exists: + legal_yesses = {'y', 'yes', 'yes.', 'yes!'} + reply = input(DB_CREATION_ASK) + if reply.lower() in legal_yesses: + db_file.remake() + else: + print('Not recognizing reply as "yes".') + raise HandledException('Cannot run without database.') + server = TaskServer(TEMPLATES_DIR, db_file, + ('localhost', HTTP_PORT), TaskHandler) print(f'running at port {HTTP_PORT}') try: server.serve_forever() @@ -17,5 +34,5 @@ if __name__ == '__main__': print('aborting due to keyboard interrupt') server.server_close() except HandledException as e: - print(f'Aborting due to: {e}') + print(f'Aborting because: {e}') sys_exit(1)