-
Notifications
You must be signed in to change notification settings - Fork 102
/
config.py
153 lines (108 loc) · 3.73 KB
/
config.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"""
Configuration module that holds some configuration options for
Web2Executable.
"""
from __future__ import print_function
import os
import logging
import logging.handlers as lh
import traceback
import sys
import zipfile
import ssl
import utils
ZIP_MODE = zipfile.ZIP_STORED
MAX_RECENT = 10
DEBUG = False
TESTING = False
SSL_CONTEXT = ssl._create_unverified_context()
### The following sections are code that needs to be run when importing
### from main.py.
## CWD Computation --------------------------------------
inside_packed_exe = getattr(sys, "frozen", "")
if inside_packed_exe:
# we are running in a |PyInstaller| bundle
CWD = os.path.dirname(sys.executable)
else:
# we are running in a normal Python environment
CWD = os.path.dirname(os.path.realpath(__file__))
## CMD Utility functions --------------------------------
def get_file(path):
parts = path.split("/")
independent_path = utils.path_join(CWD, *parts)
return independent_path
def is_installed():
uninst = get_file("uninst.exe")
return utils.is_windows() and os.path.exists(uninst)
## Version Setting ----------------------------------------
__version__ = "v0.0.0"
with open(get_file("files/version.txt")) as f:
__version__ = f.read().strip()
ICON_PATH = "files/images/icon.png"
WARNING_ICON = "files/images/warning.png"
APP_SETTINGS_ICON = "files/images/app_settings.png"
WINDOW_SETTINGS_ICON = "files/images/window_settings.png"
EXPORT_SETTINGS_ICON = "files/images/export_settings.png"
COMPRESS_SETTINGS_ICON = "files/images/compress_settings.png"
DOWNLOAD_SETTINGS_ICON = "files/images/download_settings.png"
FOLDER_OPEN_ICON = "files/images/folder_open.png"
W2E_VER_FILE = "files/version.txt"
TEMP_DIR = utils.get_temp_dir()
ERROR_LOG_FILE = "files/error.log"
VER_FILE = "files/nw-versions.txt"
SETTINGS_FILE = "files/settings.cfg"
GLOBAL_JSON_FILE = "files/global.json"
WEB2EXE_JSON_FILE = "web2exe.json"
LAST_PROJECT_FILE = "files/last_project_path.txt"
RECENT_FILES_FILE = "files/recent_files.txt"
NW_BRANCH_FILE = "files/nw-branch.txt"
UPX_WIN_PATH = "files/compressors/upx-win.exe"
UPX_MAC_PATH = "files/compressors/upx-mac"
UPX_LIN32_PATH = "files/compressors/upx-linux-x32"
UPX_LIN64_PATH = "files/compressors/upx-linux-x64"
ENV_VARS_PY_PATH = "files/env_vars.py"
ENV_VARS_BAT_PATH = "files/env_vars.bat"
ENV_VARS_BASH_PATH = "files/env_vars.bash"
## Logger setup ----------------------------------------------
LOG_FILENAME = utils.get_data_file_path(ERROR_LOG_FILE)
def getLogHandler():
return lh.RotatingFileHandler(
LOG_FILENAME, maxBytes=100000, backupCount=2, encoding="utf-8"
)
if DEBUG:
logging.basicConfig(
format=(
"%(levelname) -10s %(asctime)s %(module)s.py: "
"%(lineno)s %(funcName)s - %(message)s"
),
level=logging.DEBUG,
handlers=[getLogHandler()],
)
else:
logging.basicConfig(
format=(
"%(levelname) -10s %(asctime)s %(module)s.py: "
"%(lineno)s %(funcName)s - %(message)s"
),
level=logging.INFO,
handlers=[getLogHandler()],
)
def getLogger(name):
logger = logging.getLogger(name)
logger.addHandler(getLogHandler())
return logger
logger = getLogger(__name__)
## Custom except hook to log all errors ----------------------
def my_excepthook(type_, value, tback):
output_err = "".join([x for x in traceback.format_exception(type_, value, tback)])
logger.error("{}".format(output_err))
sys.__excepthook__(type_, value, tback)
sys.excepthook = my_excepthook
def download_path(path=None):
# Ensure that the default download path exists
path = path or utils.get_data_path("files/downloads")
try:
os.makedirs(path)
except:
pass
return path