|
1 | 1 | # A part of NonVisual Desktop Access (NVDA) |
2 | | -# Copyright (C) 2007-2020 NV Access Limited, Rui Batista, Joseph Lee, Leonard de Ruijter, Babbage B.V., |
| 2 | +# Copyright (C) 2007-2022 NV Access Limited, Rui Batista, Joseph Lee, Leonard de Ruijter, Babbage B.V., |
3 | 3 | # Accessolutions, Julien Cochuyt |
4 | 4 | # This file is covered by the GNU General Public License. |
5 | 5 | # See the file COPYING for more details. |
@@ -125,15 +125,16 @@ def shouldPlayErrorSound() -> bool: |
125 | 125 |
|
126 | 126 |
|
127 | 127 | # Function to strip the base path of our code from traceback text to improve readability. |
128 | | -if getattr(sys, "frozen", None): |
129 | | - # We're running a py2exe build. |
130 | | - stripBasePathFromTracebackText = lambda text: text |
131 | | -else: |
| 128 | +if globalVars.runningAsSource: |
132 | 129 | BASE_PATH = os.path.split(__file__)[0] + os.sep |
133 | 130 | TB_BASE_PATH_PREFIX = ' File "' |
134 | 131 | TB_BASE_PATH_MATCH = TB_BASE_PATH_PREFIX + BASE_PATH |
135 | 132 | def stripBasePathFromTracebackText(text): |
136 | 133 | return text.replace(TB_BASE_PATH_MATCH, TB_BASE_PATH_PREFIX) |
| 134 | +else: |
| 135 | + def stripBasePathFromTracebackText(text: str) -> str: |
| 136 | + return text |
| 137 | + |
137 | 138 |
|
138 | 139 | class Logger(logging.Logger): |
139 | 140 | # Import standard levels for convenience. |
@@ -379,12 +380,14 @@ def redirectStdout(logger): |
379 | 380 | #: The singleton log handler instance. |
380 | 381 | logHandler: Optional[logging.Handler] = None |
381 | 382 |
|
| 383 | + |
382 | 384 | def _getDefaultLogFilePath(): |
383 | | - if getattr(sys, "frozen", None): |
| 385 | + if globalVars.runningAsSource: |
| 386 | + return os.path.join(globalVars.appDir, "nvda.log") |
| 387 | + else: |
384 | 388 | import tempfile |
385 | 389 | return os.path.join(tempfile.gettempdir(), "nvda.log") |
386 | | - else: |
387 | | - return os.path.join(globalVars.appDir, "nvda.log") |
| 390 | + |
388 | 391 |
|
389 | 392 | def _excepthook(*exc_info): |
390 | 393 | log.exception(exc_info=exc_info, codepath="unhandled exception") |
|
0 commit comments