forked from jkellerer/iBrew
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ibrewui
executable file
·127 lines (100 loc) · 3.53 KB
/
ibrewui
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import os
import platform
import signal
#import rumps
import logging
import logging.handlers
from iBrewFolders import AppFolders
from iBrewWeb import *
#------------------------------------------------------
# iBrew
#
# Taskbar Launcher (MacOS & Windows)
#
# https://github.com/Tristan79/iBrew
#
# Copyright © 2016 Tristan (@monkeycat.nl)
#
# The Dream Tea
#------------------------------------------------------
class Launcher():
def signal_handler(self, signal, frame):
print "Caught Ctrl-C. exiting."
if self.web:
self.web.kill()
sys.exit(-1)
def __init__(self):
self.ui = None
def exit(self):
sys.exit()
os.exit()
def run(self):
try:
self.web.run("",2080,True)
except Exception, e:
logging.debug(e)
logging.info("iBrew: Failed to run Web Interface & REST API on port 2080")
self.web.kill()
if self.ui:
self.ui.quit_application()
print "I never ever had problems not exiting before, fucking python... why not exit?"
self.exit()
logging.info("iBrew: Starting Web Interface & REST API on port 2080")
def go(self):
#if platform.system() != "Darwin":
# print "iBrew: MacOS Only"
# return
AppFolders.makeFolders()
if platform.system() == "Darwin" or platform.system() == "Linux":
if getattr(sys, 'frozen', None):
try:
# do not touch if its not a symlink...
if os.path.islink("/usr/local/bin/ibrew"):
os.remove("/usr/local/bin/ibrew")
os.symlink(AppFolders.appBase()+"/iBrewConsole","/usr/local/bin/ibrew")
except Exception:
pass
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
log_file = os.path.join(AppFolders.logs(), "ibrewui.log")
fh = logging.handlers.RotatingFileHandler(log_file, maxBytes=1048576, backupCount=4, encoding="UTF8")
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
logger.addHandler(fh)
# By default only do info level to console
sh = logging.StreamHandler(sys.stdout)
sh.setLevel(logging.INFO)
sh.setFormatter(formatter)
logger.addHandler(sh)
sh.setLevel(logging.DEBUG)
self.web = iBrewWeb()
#signal.signal(signal.SIGINT, self.signal_handler)
#import threading
self.t = threading.Thread(target=self.run)
self.t.start()
logging.info("GUI Started")
try:
self.web.events = True
if platform.system() == "Darwin":
# For windows exe with pyinstaller disabled the following 3 lines!
#pass
from iBrewMac import MacGui
self.ui = MacGui(self.web)
self.ui.run()
elif platform.system() == "Windows":
from iBrewWin import WinGui
self.ui = WinGui(self.web)
self.ui.run()
else:
print "MacOS & Windows only"
except Exception:
if self.ui:
self.ui.quit_application()
self.web.kill()
Launcher().go()