Total Complexity | 3 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | #!/usr/bin/env python3 |
||
2 | # -*- coding: utf-8 -*- |
||
3 | |||
4 | """KanbanView (app) for Things 3.""" |
||
5 | |||
6 | from __future__ import print_function |
||
7 | |||
8 | __author__ = "Luc Beaulieu and Alexander Willner" |
||
9 | __copyright__ = "Copyright 2018 Luc Beaulieu / 2020 Alexander Willner" |
||
10 | __credits__ = ["Luc Beaulieu", "Alexander Willner"] |
||
11 | __license__ = "unknown" |
||
12 | __version__ = "1.2.0" |
||
13 | __maintainer__ = "Alexander Willner" |
||
14 | __email__ = "[email protected]" |
||
15 | __status__ = "Development" |
||
16 | |||
17 | import sys |
||
18 | from os import system |
||
19 | from threading import Thread |
||
20 | from time import sleep |
||
21 | import webbrowser |
||
22 | import things3_api |
||
23 | |||
24 | |||
25 | FILE = "kanban.html" |
||
26 | |||
27 | |||
28 | def open_browser(): |
||
29 | """Delay opening the browser.""" |
||
30 | sleep(2) |
||
31 | webbrowser.open('http://localhost:%s/%s' % (things3_api.PORT, FILE)) |
||
32 | |||
33 | |||
34 | def main(): |
||
35 | """Run the app.""" |
||
36 | # kill possible zombie processes; can't use psutil in py2app context |
||
37 | system('lsof -nti:' + str(things3_api.PORT) + ' | xargs kill -9 ; sleep 1') |
||
38 | |||
39 | try: |
||
40 | httpd = things3_api.setup() |
||
41 | Thread(target=open_browser).start() |
||
42 | httpd.serve_forever() |
||
43 | except KeyboardInterrupt: |
||
44 | print("Shutting down...") |
||
45 | httpd.shutdown() |
||
46 | sys.exit(0) |
||
47 | |||
48 | |||
49 | if __name__ == "__main__": |
||
50 | main() |
||
51 |