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