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