/
Blackhole.pyw
54 lines (45 loc) · 2.08 KB
/
Blackhole.pyw
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
#! python3
# -*- coding: utf-8 -*-
# ┌─────────────────────────────────────────────────────┐
# │ Blackhole 0.1 - A fiddler replacement in python │
# ├─────────────────────────────────────────────────────┤
# │ Copyright (c) 2012 Amadeusguo │
# │ http://amadeus.herokuapp.com/ │
# │ Licensed under the MIT license. │
# └─────────────────────────────────────────────────────┘
import os
import sys
import logging
import logging.handlers
if __name__=='__main__':
### setup path ###
if hasattr(sys, 'frozen'):
app_dir = os.path.dirname(sys.executable)
else:
app_dir = os.path.abspath(os.path.dirname(__file__) or '.')
sys.path.insert(0, os.path.join(app_dir, 'lib'))
if len(sys.argv) > 1:
config_file = os.path.join(os.getcwd(), sys.argv[1])
else:
config_file = os.path.join(app_dir, 'config.ini')
sys.argv.append(config_file)
config_dir = os.path.dirname(config_file)
os.chdir(config_dir)
import blackhole.utils as utils
utils.register_path(app_dir, config_dir)
### setup logging ###
logfile = utils.get_res('data/log/log.txt')
try:
os.makedirs(os.path.dirname(logfile))
except FileExistsError:
pass
rotateLogger = logging.handlers.RotatingFileHandler(logfile, maxBytes=100*1024*1024, backupCount=3)
format = '%(asctime)-15s %(levelname)s:%(module)s:%(lineno)d > %(message)s'
logging.basicConfig(format=format, level=logging.DEBUG, handlers=(rotateLogger,))
### startup app ###
from blackhole.confparser import get_config
import blackhole.router as router
import blackhole.ui.tk_ui as ui
config = get_config(config_file)
router.run(config)
ui.init(config)