Philipp Hörist pushed to branch master at gajim / gajim
Commits:
3 changed files:
Changes:
| ... | ... | @@ -34,9 +34,7 @@ |
| 34 | 34 |
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
| 35 | 35 |
|
| 36 | 36 |
import os
|
| 37 |
-import time
|
|
| 38 | 37 |
import sys
|
| 39 |
-from datetime import datetime
|
|
| 40 | 38 |
from urllib.parse import unquote
|
| 41 | 39 |
|
| 42 | 40 |
from nbxmpp.namespaces import Namespace
|
| ... | ... | @@ -358,14 +356,7 @@ def _handle_local_options(self, |
| 358 | 356 |
if options.contains('gdebug'):
|
| 359 | 357 |
os.environ['G_MESSAGES_DEBUG'] = 'all'
|
| 360 | 358 |
|
| 361 |
- if app.get_debug_mode():
|
|
| 362 |
- # Redirect has to happen before logging init
|
|
| 363 |
- self._cleanup_debug_logs()
|
|
| 364 |
- self._redirect_output()
|
|
| 365 |
- logging_helpers.init()
|
|
| 366 |
- logging_helpers.set_verbose()
|
|
| 367 |
- else:
|
|
| 368 |
- logging_helpers.init()
|
|
| 359 |
+ logging_helpers.init()
|
|
| 369 | 360 |
|
| 370 | 361 |
if options.contains('quiet'):
|
| 371 | 362 |
logging_helpers.set_quiet()
|
| ... | ... | @@ -393,24 +384,6 @@ def warn_with_traceback(message, category, filename, lineno, |
| 393 | 384 |
warnings.showwarning = warn_with_traceback
|
| 394 | 385 |
warnings.filterwarnings(action="always")
|
| 395 | 386 |
|
| 396 |
- @staticmethod
|
|
| 397 |
- def _redirect_output():
|
|
| 398 |
- debug_folder = configpaths.get('DEBUG')
|
|
| 399 |
- date = datetime.today().strftime('%d%m%Y-%H%M%S')
|
|
| 400 |
- filename = '%s-debug.log' % date
|
|
| 401 |
- fd = open(debug_folder / filename, 'a')
|
|
| 402 |
- sys.stderr = sys.stdout = fd
|
|
| 403 |
- |
|
| 404 |
- @staticmethod
|
|
| 405 |
- def _cleanup_debug_logs():
|
|
| 406 |
- debug_folder = configpaths.get('DEBUG')
|
|
| 407 |
- debug_files = list(debug_folder.glob('*-debug.log*'))
|
|
| 408 |
- now = time.time()
|
|
| 409 |
- for file in debug_files:
|
|
| 410 |
- # Delete everything older than 3 days
|
|
| 411 |
- if file.stat().st_ctime < now - 259200:
|
|
| 412 |
- file.unlink()
|
|
| 413 |
- |
|
| 414 | 387 |
def add_actions(self):
|
| 415 | 388 |
''' Build Application Actions '''
|
| 416 | 389 |
from gajim import app_actions
|
| ... | ... | @@ -17,7 +17,11 @@ |
| 17 | 17 |
import logging
|
| 18 | 18 |
import os
|
| 19 | 19 |
import sys
|
| 20 |
+import time
|
|
| 21 |
+from datetime import datetime
|
|
| 20 | 22 |
|
| 23 |
+from gajim.common import app
|
|
| 24 |
+from gajim.common import configpaths
|
|
| 21 | 25 |
from gajim.common.i18n import _
|
| 22 | 26 |
|
| 23 | 27 |
def parseLogLevel(arg):
|
| ... | ... | @@ -136,6 +140,11 @@ def init(): |
| 136 | 140 |
"""
|
| 137 | 141 |
Iinitialize the logging system
|
| 138 | 142 |
"""
|
| 143 |
+ |
|
| 144 |
+ if app.get_debug_mode():
|
|
| 145 |
+ _cleanup_debug_logs()
|
|
| 146 |
+ _redirect_output()
|
|
| 147 |
+ |
|
| 139 | 148 |
use_color = False
|
| 140 | 149 |
if os.name != 'nt':
|
| 141 | 150 |
use_color = sys.stderr.isatty()
|
| ... | ... | @@ -164,6 +173,12 @@ def init(): |
| 164 | 173 |
root_log.addHandler(consoleloghandler)
|
| 165 | 174 |
root_log.propagate = False
|
| 166 | 175 |
|
| 176 |
+ # GAJIM_DEBUG is set only on Windows when using Gajim-Debug.exe
|
|
| 177 |
+ # Gajim-Debug.exe shows a command line prompt and we want to redirect
|
|
| 178 |
+ # log output to it
|
|
| 179 |
+ if app.get_debug_mode() or os.environ.get('GAJIM_DEBUG', False):
|
|
| 180 |
+ set_verbose()
|
|
| 181 |
+ |
|
| 167 | 182 |
def set_loglevels(loglevels_string):
|
| 168 | 183 |
parseAndSetLogLevels(loglevels_string)
|
| 169 | 184 |
|
| ... | ... | @@ -176,6 +191,25 @@ def set_quiet(): |
| 176 | 191 |
parseAndSetLogLevels('.nbxmpp=CRITICAL')
|
| 177 | 192 |
|
| 178 | 193 |
|
| 194 |
+def _redirect_output():
|
|
| 195 |
+ debug_folder = configpaths.get('DEBUG')
|
|
| 196 |
+ date = datetime.today().strftime('%d%m%Y-%H%M%S')
|
|
| 197 |
+ filename = '%s-debug.log' % date
|
|
| 198 |
+ fd = open(debug_folder / filename, 'a')
|
|
| 199 |
+ sys.stderr = sys.stdout = fd
|
|
| 200 |
+ |
|
| 201 |
+ |
|
| 202 |
+def _cleanup_debug_logs():
|
|
| 203 |
+ debug_folder = configpaths.get('DEBUG')
|
|
| 204 |
+ debug_files = list(debug_folder.glob('*-debug.log*'))
|
|
| 205 |
+ now = time.time()
|
|
| 206 |
+ for file in debug_files:
|
|
| 207 |
+ # Delete everything older than 3 days
|
|
| 208 |
+ if file.stat().st_ctime < now - 259200:
|
|
| 209 |
+ file.unlink()
|
|
| 210 |
+ |
|
| 211 |
+ |
|
| 212 |
+ |
|
| 179 | 213 |
# tests
|
| 180 | 214 |
if __name__ == '__main__':
|
| 181 | 215 |
init()
|
| ... | ... | @@ -58,7 +58,7 @@ def build_exe(source_path, resource_path, is_gui, out_path): |
| 58 | 58 |
subprocess.check_call(args)
|
| 59 | 59 |
|
| 60 | 60 |
|
| 61 |
-def get_launcher_code():
|
|
| 61 |
+def get_launcher_code(debug):
|
|
| 62 | 62 |
template = """\
|
| 63 | 63 |
#include "Python.h"
|
| 64 | 64 |
#define WIN32_LEAN_AND_MEAN
|
| ... | ... | @@ -89,6 +89,7 @@ def get_launcher_code(): |
| 89 | 89 |
PySys_SetArgvEx(__argc, szArglist, 0);
|
| 90 | 90 |
result = PyRun_SimpleString(
|
| 91 | 91 |
"import sys; import os;"
|
| 92 |
+ "os.environ['GAJIM_DEBUG'] = %s;"
|
|
| 92 | 93 |
"sys.frozen=True;"
|
| 93 | 94 |
"from pathlib import Path;"
|
| 94 | 95 |
"root_path = Path(sys.executable).parents[1];"
|
| ... | ... | @@ -99,7 +100,7 @@ def get_launcher_code(): |
| 99 | 100 |
Py_Finalize();
|
| 100 | 101 |
return result;
|
| 101 | 102 |
}
|
| 102 |
- """
|
|
| 103 |
+ """ % int(debug)
|
|
| 103 | 104 |
|
| 104 | 105 |
return template
|
| 105 | 106 |
|
| ... | ... | @@ -153,7 +154,7 @@ def to_ver_list(v): |
| 153 | 154 |
|
| 154 | 155 |
|
| 155 | 156 |
def build_launcher(out_path, icon_path, file_desc, product_name, product_version,
|
| 156 |
- company_name, is_gui):
|
|
| 157 |
+ company_name, is_gui, debug=False):
|
|
| 157 | 158 |
|
| 158 | 159 |
src_ico = os.path.abspath(icon_path)
|
| 159 | 160 |
target = os.path.abspath(out_path)
|
| ... | ... | @@ -165,7 +166,7 @@ def build_launcher(out_path, icon_path, file_desc, product_name, product_version |
| 165 | 166 |
try:
|
| 166 | 167 |
os.chdir(temp)
|
| 167 | 168 |
with open("launcher.c", "w") as h:
|
| 168 |
- h.write(get_launcher_code())
|
|
| 169 |
+ h.write(get_launcher_code(debug))
|
|
| 169 | 170 |
shutil.copyfile(src_ico, "launcher.ico")
|
| 170 | 171 |
with open("launcher.rc", "w") as h:
|
| 171 | 172 |
h.write(get_resouce_code(
|
| ... | ... | @@ -196,7 +197,7 @@ def main(): |
| 196 | 197 |
build_launcher(
|
| 197 | 198 |
os.path.join(target, "Gajim-Debug.exe"),
|
| 198 | 199 |
os.path.join(misc, "gajim.ico"), "Gajim", "Gajim",
|
| 199 |
- version, company_name, False)
|
|
| 200 |
+ version, company_name, False, debug=True)
|
|
| 200 | 201 |
|
| 201 | 202 |
# build_launcher(
|
| 202 | 203 |
# os.path.join(target, "history_manager.exe"),
|