28
28
29
29
## CWD Computation --------------------------------------
30
30
31
- inside_packed_exe = getattr (sys , ' frozen' , '' )
31
+ inside_packed_exe = getattr (sys , " frozen" , "" )
32
32
33
33
if inside_packed_exe :
34
34
# we are running in a |PyInstaller| bundle
39
39
40
40
## CMD Utility functions --------------------------------
41
41
42
+
42
43
def get_file (path ):
43
- parts = path .split ('/' )
44
+ parts = path .split ("/" )
44
45
independent_path = utils .path_join (CWD , * parts )
45
46
return independent_path
46
47
48
+
47
49
def is_installed ():
48
- uninst = get_file (' uninst.exe' )
50
+ uninst = get_file (" uninst.exe" )
49
51
return utils .is_windows () and os .path .exists (uninst )
50
52
53
+
51
54
## Version Setting ----------------------------------------
52
55
53
56
__version__ = "v0.0.0"
54
57
55
- with open (get_file (' files/version.txt' )) as f :
58
+ with open (get_file (" files/version.txt" )) as f :
56
59
__version__ = f .read ().strip ()
57
60
58
- ICON_PATH = ' files/images/icon.png'
59
- WARNING_ICON = ' files/images/warning.png'
60
- APP_SETTINGS_ICON = ' files/images/app_settings.png'
61
- WINDOW_SETTINGS_ICON = ' files/images/window_settings.png'
62
- EXPORT_SETTINGS_ICON = ' files/images/export_settings.png'
63
- COMPRESS_SETTINGS_ICON = ' files/images/compress_settings.png'
64
- DOWNLOAD_SETTINGS_ICON = ' files/images/download_settings.png'
65
- FOLDER_OPEN_ICON = ' files/images/folder_open.png'
61
+ ICON_PATH = " files/images/icon.png"
62
+ WARNING_ICON = " files/images/warning.png"
63
+ APP_SETTINGS_ICON = " files/images/app_settings.png"
64
+ WINDOW_SETTINGS_ICON = " files/images/window_settings.png"
65
+ EXPORT_SETTINGS_ICON = " files/images/export_settings.png"
66
+ COMPRESS_SETTINGS_ICON = " files/images/compress_settings.png"
67
+ DOWNLOAD_SETTINGS_ICON = " files/images/download_settings.png"
68
+ FOLDER_OPEN_ICON = " files/images/folder_open.png"
66
69
67
- W2E_VER_FILE = ' files/version.txt'
70
+ W2E_VER_FILE = " files/version.txt"
68
71
69
72
TEMP_DIR = utils .get_temp_dir ()
70
73
71
- ERROR_LOG_FILE = ' files/error.log'
72
- VER_FILE = ' files/nw-versions.txt'
73
- SETTINGS_FILE = ' files/settings.cfg'
74
- GLOBAL_JSON_FILE = ' files/global.json'
75
- WEB2EXE_JSON_FILE = ' web2exe.json'
74
+ ERROR_LOG_FILE = " files/error.log"
75
+ VER_FILE = " files/nw-versions.txt"
76
+ SETTINGS_FILE = " files/settings.cfg"
77
+ GLOBAL_JSON_FILE = " files/global.json"
78
+ WEB2EXE_JSON_FILE = " web2exe.json"
76
79
77
- LAST_PROJECT_FILE = ' files/last_project_path.txt'
78
- RECENT_FILES_FILE = ' files/recent_files.txt'
80
+ LAST_PROJECT_FILE = " files/last_project_path.txt"
81
+ RECENT_FILES_FILE = " files/recent_files.txt"
79
82
80
- NW_BRANCH_FILE = ' files/nw-branch.txt'
83
+ NW_BRANCH_FILE = " files/nw-branch.txt"
81
84
82
- UPX_WIN_PATH = ' files/compressors/upx-win.exe'
83
- UPX_MAC_PATH = ' files/compressors/upx-mac'
84
- UPX_LIN32_PATH = ' files/compressors/upx-linux-x32'
85
- UPX_LIN64_PATH = ' files/compressors/upx-linux-x64'
85
+ UPX_WIN_PATH = " files/compressors/upx-win.exe"
86
+ UPX_MAC_PATH = " files/compressors/upx-mac"
87
+ UPX_LIN32_PATH = " files/compressors/upx-linux-x32"
88
+ UPX_LIN64_PATH = " files/compressors/upx-linux-x64"
86
89
87
- ENV_VARS_PY_PATH = ' files/env_vars.py'
88
- ENV_VARS_BAT_PATH = ' files/env_vars.bat'
89
- ENV_VARS_BASH_PATH = ' files/env_vars.bash'
90
+ ENV_VARS_PY_PATH = " files/env_vars.py"
91
+ ENV_VARS_BAT_PATH = " files/env_vars.bat"
92
+ ENV_VARS_BASH_PATH = " files/env_vars.bash"
90
93
91
94
## Logger setup ----------------------------------------------
92
95
93
96
LOG_FILENAME = utils .get_data_file_path (ERROR_LOG_FILE )
94
97
98
+
95
99
def getLogHandler ():
96
100
return lh .RotatingFileHandler (
97
- LOG_FILENAME ,
98
- maxBytes = 100000 ,
99
- backupCount = 2 ,
100
- encoding = 'utf-8'
101
+ LOG_FILENAME , maxBytes = 100000 , backupCount = 2 , encoding = "utf-8"
101
102
)
102
103
103
104
104
105
if DEBUG :
105
106
logging .basicConfig (
106
- format = ("%(levelname) -10s %(asctime)s %(module)s.py: "
107
- "%(lineno)s %(funcName)s - %(message)s" ),
107
+ format = (
108
+ "%(levelname) -10s %(asctime)s %(module)s.py: "
109
+ "%(lineno)s %(funcName)s - %(message)s"
110
+ ),
108
111
level = logging .DEBUG ,
109
- handlers = [getLogHandler ()]
112
+ handlers = [getLogHandler ()],
110
113
)
111
114
else :
112
115
logging .basicConfig (
113
- format = ("%(levelname) -10s %(asctime)s %(module)s.py: "
114
- "%(lineno)s %(funcName)s - %(message)s" ),
116
+ format = (
117
+ "%(levelname) -10s %(asctime)s %(module)s.py: "
118
+ "%(lineno)s %(funcName)s - %(message)s"
119
+ ),
115
120
level = logging .INFO ,
116
- handlers = [getLogHandler ()]
121
+ handlers = [getLogHandler ()],
117
122
)
118
123
119
124
120
-
121
125
def getLogger (name ):
122
126
logger = logging .getLogger (name )
123
127
logger .addHandler (getLogHandler ())
@@ -129,17 +133,19 @@ def getLogger(name):
129
133
130
134
## Custom except hook to log all errors ----------------------
131
135
136
+
132
137
def my_excepthook (type_ , value , tback ):
133
- output_err = '' .join ([x for x in traceback .format_exception (type_ , value ,
134
- tback )])
135
- logger .error ('{}' .format (output_err ))
138
+ output_err = "" .join ([x for x in traceback .format_exception (type_ , value , tback )])
139
+ logger .error ("{}" .format (output_err ))
136
140
sys .__excepthook__ (type_ , value , tback )
137
141
142
+
138
143
sys .excepthook = my_excepthook
139
144
145
+
140
146
def download_path (path = None ):
141
147
# Ensure that the default download path exists
142
- path = path or utils .get_data_path (' files/downloads' )
148
+ path = path or utils .get_data_path (" files/downloads" )
143
149
try :
144
150
os .makedirs (path )
145
151
except :
0 commit comments