Passed
Push — master ( d52a5c...eb2b83 )
by Alexander
01:44
created

src.things3_app.main()   A

Complexity

Conditions 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nop 0
dl 0
loc 13
rs 9.9
c 0
b 0
f 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