X-Git-Url: https://plomlompom.com/repos/feed.xml?a=blobdiff_plain;f=run.py;h=33346375ea8ad03a19b43ce8f26e0c3e8498bbbd;hb=1cddadfe3426a5845008e38f430b4bd371986b51;hp=d94905dc69bc97379567fb3f79d5f7288c7bbc57;hpb=30bc39c0af52c9fc474d3be0c040b7effe761187;p=plomtask diff --git a/run.py b/run.py index d94905d..3334637 100755 --- a/run.py +++ b/run.py @@ -1,16 +1,31 @@ #!/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 +PLOMTASK_DB_PATH = environ.get('PLOMTASK_DB_PATH') HTTP_PORT = 8082 TEMPLATES_DIR = 'templates' +DB_CREATION_ASK = 'Database file not found. Create? Y/n\n' if __name__ == '__main__': try: - server = TaskServer(TEMPLATES_DIR, + if not PLOMTASK_DB_PATH: + raise HandledException('PLOMTASK_DB_PATH not set.') + db_file = DatabaseFile(PLOMTASK_DB_PATH) + 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: @@ -19,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)