2 """Call this to start the application."""
3 from sys import exit as sys_exit
5 from plomtask.exceptions import HandledException
6 from plomtask.http import TaskHandler, TaskServer
7 from plomtask.db import DatabaseFile
9 PLOMTASK_DB_PATH = environ.get('PLOMTASK_DB_PATH')
11 DB_CREATION_ASK = 'Database file not found. Create? Y/n\n'
14 if __name__ == '__main__':
16 if not PLOMTASK_DB_PATH:
17 raise HandledException('PLOMTASK_DB_PATH not set.')
18 db_file = DatabaseFile(PLOMTASK_DB_PATH)
19 if not db_file.exists:
20 legal_yesses = {'y', 'yes', 'yes.', 'yes!'}
21 reply = input(DB_CREATION_ASK)
22 if reply.lower() in legal_yesses:
25 print('Not recognizing reply as "yes".')
26 raise HandledException('Cannot run without database.')
27 server = TaskServer(db_file, ('localhost', HTTP_PORT), TaskHandler)
28 print(f'running at port {HTTP_PORT}')
30 server.serve_forever()
31 except KeyboardInterrupt:
32 print('aborting due to keyboard interrupt')
34 except HandledException as e:
35 print(f'Aborting because: {e}')