-
Notifications
You must be signed in to change notification settings - Fork 1
/
zcant.py
executable file
·73 lines (58 loc) · 1.95 KB
/
zcant.py
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
#!/usr/bin/env python
"""
Main executable which launches the ZCANT GUI.
---------------
Myotisoft ZCANT
Copyright (C) 2012-2017 Myotisoft LLC, all rights reserved.
You may use, distribute, and modify this code under the terms of the MIT License.
"""
import sys
import errno
import os.path
import logging
import platform
from logging.handlers import RotatingFileHandler
LOG_MAX_FILESIZE_MB = 2
LOG_BACKUP_COUNT = 9
LOG_FMT = '%(asctime)s\t%(levelname)s\t%(message)s'
LOG_FILE = '~/.myotisoft/zcant/logs/zcant.log'
def configure_logging(logfilename, level=logging.DEBUG):
"""Configure application-level console and file-based logging"""
# configure console logging...
logging.basicConfig(level=level, format=LOG_FMT)
# configure file-based logging
logfilename = os.path.expanduser(logfilename)
try:
os.makedirs(os.path.dirname(logfilename))
except OSError as e:
if e.errno != errno.EEXIST:
raise
try:
file_logger = RotatingFileHandler(logfilename, maxBytes=LOG_MAX_FILESIZE_MB*1024*1024, backupCount=LOG_BACKUP_COUNT)
file_logger.setFormatter(logging.Formatter(LOG_FMT))
file_logger.setLevel(level)
logging.getLogger().addHandler(file_logger) # root logger
except Exception:
log = logging.getLogger(__name__)
log.exception('Failed while configuring logging!')
def zcant_gui():
"""Launch the ZCANT GUI"""
import wx
from zcant.gui import ZcantMainFrame
app = wx.App(False)
frame = ZcantMainFrame(None)
frame.Maximize(True)
frame.Show(True)
app.MainLoop()
def main():
"""Main entrypoint"""
configure_logging(LOG_FILE)
log = logging.getLogger(__name__)
log.debug('%s %s %s', platform.python_implementation(), platform.python_version(), platform.platform())
try:
zcant_gui()
except Exception as e:
log.exception('GUI initialization failed!')
sys.exit(255)
if __name__ == '__main__':
main()