-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathdebug.py
More file actions
34 lines (23 loc) · 1.08 KB
/
debug.py
File metadata and controls
34 lines (23 loc) · 1.08 KB
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
# --------------------------------------------------------------------
# SPDX-License-Identifier: AGPL-3.0-or-later
# Licensed under the GNU Affero General Public License v3.0 or later.
# Author: Jose M. Rodriguez-Rosa (a.k.a. Boriel) - https://boriel.com
# See https://www.gnu.org/licenses/agpl-3.0.html for details.
# --------------------------------------------------------------------
import inspect
import os
from .config import OPTIONS
__all__ = "__DEBUG__", "__FILE__", "__LINE__"
# --------------------- END OF GLOBAL FLAGS ---------------------
def __DEBUG__(msg, level=1):
if level > OPTIONS.debug_level:
return
line = inspect.getouterframes(inspect.currentframe())[1][2]
fname = os.path.basename(inspect.getouterframes(inspect.currentframe())[1][1])
OPTIONS.stderr.write("debug: %s:%i %s\n" % (fname, line, msg))
def __LINE__():
"""Returns current file interpreter line"""
return inspect.getouterframes(inspect.currentframe())[1][2]
def __FILE__():
"""Returns current file interpreter line"""
return inspect.currentframe().f_code.co_filename