logger-36 2023.13__py3-none-any.whl → 2025.3__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- logger_36/__init__.py +65 -41
- logger_36/api/logger.py +53 -0
- logger_36/api/storage.py +53 -0
- logger_36/catalog/config/console_rich.py +76 -0
- logger_36/catalog/handler/console.py +117 -0
- logger_36/catalog/handler/console_rich.py +235 -0
- logger_36/catalog/handler/file.py +128 -0
- logger_36/catalog/handler/generic.py +228 -0
- logger_36/catalog/logger/chronos.py +61 -0
- logger_36/catalog/logger/gpu.py +90 -0
- logger_36/catalog/logger/memory.py +129 -0
- logger_36/catalog/logger/system.py +84 -0
- logger_36/config/issue.py +56 -0
- logger_36/config/logger.py +103 -0
- logger_36/config/memory.py +54 -0
- logger_36/config/message.py +66 -0
- logger_36/config/system.py +70 -0
- logger_36/constant/error.py +70 -0
- logger_36/constant/generic.py +58 -0
- logger_36/constant/handler.py +58 -0
- logger_36/constant/issue.py +58 -0
- logger_36/constant/logger.py +67 -0
- logger_36/constant/memory.py +58 -0
- logger_36/constant/message.py +72 -0
- logger_36/constant/record.py +55 -0
- logger_36/constant/system.py +60 -0
- logger_36/content.py +55 -0
- logger_36/exception.py +105 -0
- logger_36/gpu.py +53 -0
- logger_36/handler.py +209 -0
- logger_36/instance/logger.py +55 -0
- logger_36/instance/loggers.py +56 -0
- logger_36/memory.py +60 -0
- logger_36/storage.py +53 -0
- logger_36/system.py +53 -0
- logger_36/task/format/memory.py +132 -0
- logger_36/task/format/message.py +111 -0
- logger_36/task/format/rule.py +74 -0
- logger_36/task/inspection.py +70 -48
- logger_36/task/measure/chronos.py +84 -0
- logger_36/task/measure/memory.py +72 -0
- logger_36/task/storage.py +164 -0
- logger_36/time.py +54 -0
- logger_36/type/handler.py +184 -0
- logger_36/type/issue.py +91 -0
- logger_36/type/logger.py +542 -0
- logger_36/type/loggers.py +78 -0
- logger_36/version.py +53 -32
- logger_36-2025.3.dist-info/METADATA +154 -0
- logger_36-2025.3.dist-info/RECORD +52 -0
- {logger_36-2023.13.dist-info → logger_36-2025.3.dist-info}/WHEEL +1 -1
- logger_36/config.py +0 -66
- logger_36/constant.py +0 -57
- logger_36/main.py +0 -185
- logger_36/measure/chronos.py +0 -55
- logger_36/measure/memory.py +0 -102
- logger_36/type/console.py +0 -122
- logger_36/type/extension.py +0 -122
- logger_36/type/file.py +0 -52
- logger_36/type/generic.py +0 -116
- logger_36-2023.13.dist-info/METADATA +0 -106
- logger_36-2023.13.dist-info/RECORD +0 -16
- {logger_36-2023.13.dist-info → logger_36-2025.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,111 @@
|
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
6
|
+
|
7
|
+
import difflib as diff
|
8
|
+
import typing as h
|
9
|
+
|
10
|
+
from logger_36.constant.generic import NOT_PASSED
|
11
|
+
from logger_36.constant.message import expected_op_h
|
12
|
+
|
13
|
+
|
14
|
+
def MessageWithActualExpected(
|
15
|
+
message: str,
|
16
|
+
/,
|
17
|
+
*,
|
18
|
+
actual: h.Any = NOT_PASSED,
|
19
|
+
expected: h.Any | None = None,
|
20
|
+
expected_is_choices: bool = False,
|
21
|
+
expected_op: expected_op_h = "=",
|
22
|
+
with_final_dot: bool = True,
|
23
|
+
) -> str:
|
24
|
+
""""""
|
25
|
+
if actual is NOT_PASSED:
|
26
|
+
if with_final_dot:
|
27
|
+
if message[-1] != ".":
|
28
|
+
message += "."
|
29
|
+
elif message[-1] == ".":
|
30
|
+
message = message[:-1]
|
31
|
+
|
32
|
+
return message
|
33
|
+
|
34
|
+
if message[-1] == ".":
|
35
|
+
message = message[:-1]
|
36
|
+
expected = _FormattedExpected(expected_op, expected, expected_is_choices, actual)
|
37
|
+
if with_final_dot:
|
38
|
+
dot = "."
|
39
|
+
else:
|
40
|
+
dot = ""
|
41
|
+
|
42
|
+
return f"{message}: Actual={actual}:{type(actual).__name__}; {expected}{dot}"
|
43
|
+
|
44
|
+
|
45
|
+
def _FormattedExpected(
|
46
|
+
operator: str, expected: h.Any, expected_is_choices: bool, actual: h.Any, /
|
47
|
+
) -> str:
|
48
|
+
""""""
|
49
|
+
if isinstance(expected, h.Sequence) and expected_is_choices:
|
50
|
+
close_matches = diff.get_close_matches(actual, expected)
|
51
|
+
if close_matches.__len__() > 0:
|
52
|
+
close_matches = ", ".join(close_matches)
|
53
|
+
return f"Close matche(s): {close_matches}"
|
54
|
+
else:
|
55
|
+
expected = ", ".join(map(str, expected))
|
56
|
+
return f"Valid values: {expected}"
|
57
|
+
else:
|
58
|
+
if operator == "=":
|
59
|
+
stripe = f":{type(expected).__name__}"
|
60
|
+
else:
|
61
|
+
stripe = ""
|
62
|
+
if operator == ":":
|
63
|
+
operator = ": "
|
64
|
+
return f"Expected{operator}{expected}{stripe}"
|
65
|
+
|
66
|
+
|
67
|
+
"""
|
68
|
+
COPYRIGHT NOTICE
|
69
|
+
|
70
|
+
This software is governed by the CeCILL license under French law and
|
71
|
+
abiding by the rules of distribution of free software. You can use,
|
72
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
73
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
74
|
+
"http://www.cecill.info".
|
75
|
+
|
76
|
+
As a counterpart to the access to the source code and rights to copy,
|
77
|
+
modify and redistribute granted by the license, users are provided only
|
78
|
+
with a limited warranty and the software's author, the holder of the
|
79
|
+
economic rights, and the successive licensors have only limited
|
80
|
+
liability.
|
81
|
+
|
82
|
+
In this respect, the user's attention is drawn to the risks associated
|
83
|
+
with loading, using, modifying and/or developing or reproducing the
|
84
|
+
software by the user in light of its specific status of free software,
|
85
|
+
that may mean that it is complicated to manipulate, and that also
|
86
|
+
therefore means that it is reserved for developers and experienced
|
87
|
+
professionals having in-depth computer knowledge. Users are therefore
|
88
|
+
encouraged to load and test the software's suitability as regards their
|
89
|
+
requirements in conditions enabling the security of their systems and/or
|
90
|
+
data to be ensured and, more generally, to use and operate it in the
|
91
|
+
same conditions as regards security.
|
92
|
+
|
93
|
+
The fact that you are presently reading this means that you have had
|
94
|
+
knowledge of the CeCILL license and that you accept its terms.
|
95
|
+
|
96
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
97
|
+
|
98
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
99
|
+
member of team Morpheme.
|
100
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
101
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
102
|
+
I3S, and Laboratory iBV.
|
103
|
+
|
104
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
105
|
+
Inria: https://www.inria.fr/en/
|
106
|
+
UniCA: https://univ-cotedazur.eu/
|
107
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
108
|
+
I3S: https://www.i3s.unice.fr/en/
|
109
|
+
iBV: http://ibv.unice.fr/
|
110
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
111
|
+
"""
|
@@ -0,0 +1,74 @@
|
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
6
|
+
|
7
|
+
|
8
|
+
def RuleAsText(text: str | None, /) -> str:
|
9
|
+
""""""
|
10
|
+
if text is None:
|
11
|
+
return "---- ---- ---- ---- ---- ---- ---- ---- ----"
|
12
|
+
else:
|
13
|
+
return f"---- ---- ---- ---- {text} ---- ---- ---- ----"
|
14
|
+
|
15
|
+
|
16
|
+
try:
|
17
|
+
from rich.rule import Rule as rule_t # noqa
|
18
|
+
from rich.text import Text as text_t # noqa
|
19
|
+
|
20
|
+
def Rule(text: str | None, color: str, /) -> rule_t | str:
|
21
|
+
""""""
|
22
|
+
if text is None:
|
23
|
+
return rule_t(style=color)
|
24
|
+
else:
|
25
|
+
return rule_t(title=text_t(text, style=f"bold {color}"), style=color)
|
26
|
+
|
27
|
+
except ModuleNotFoundError:
|
28
|
+
Rule = lambda _txt, _: RuleAsText(_txt)
|
29
|
+
|
30
|
+
"""
|
31
|
+
COPYRIGHT NOTICE
|
32
|
+
|
33
|
+
This software is governed by the CeCILL license under French law and
|
34
|
+
abiding by the rules of distribution of free software. You can use,
|
35
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
36
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
37
|
+
"http://www.cecill.info".
|
38
|
+
|
39
|
+
As a counterpart to the access to the source code and rights to copy,
|
40
|
+
modify and redistribute granted by the license, users are provided only
|
41
|
+
with a limited warranty and the software's author, the holder of the
|
42
|
+
economic rights, and the successive licensors have only limited
|
43
|
+
liability.
|
44
|
+
|
45
|
+
In this respect, the user's attention is drawn to the risks associated
|
46
|
+
with loading, using, modifying and/or developing or reproducing the
|
47
|
+
software by the user in light of its specific status of free software,
|
48
|
+
that may mean that it is complicated to manipulate, and that also
|
49
|
+
therefore means that it is reserved for developers and experienced
|
50
|
+
professionals having in-depth computer knowledge. Users are therefore
|
51
|
+
encouraged to load and test the software's suitability as regards their
|
52
|
+
requirements in conditions enabling the security of their systems and/or
|
53
|
+
data to be ensured and, more generally, to use and operate it in the
|
54
|
+
same conditions as regards security.
|
55
|
+
|
56
|
+
The fact that you are presently reading this means that you have had
|
57
|
+
knowledge of the CeCILL license and that you accept its terms.
|
58
|
+
|
59
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
60
|
+
|
61
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
62
|
+
member of team Morpheme.
|
63
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
64
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
65
|
+
I3S, and Laboratory iBV.
|
66
|
+
|
67
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
68
|
+
Inria: https://www.inria.fr/en/
|
69
|
+
UniCA: https://univ-cotedazur.eu/
|
70
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
71
|
+
I3S: https://www.i3s.unice.fr/en/
|
72
|
+
iBV: http://ibv.unice.fr/
|
73
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
74
|
+
"""
|
logger_36/task/inspection.py
CHANGED
@@ -1,33 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# This software is governed by the CeCILL license under French law and
|
7
|
-
# abiding by the rules of distribution of free software. You can use,
|
8
|
-
# modify and/ or redistribute the software under the terms of the CeCILL
|
9
|
-
# license as circulated by CEA, CNRS and INRIA at the following URL
|
10
|
-
# "http://www.cecill.info".
|
11
|
-
#
|
12
|
-
# As a counterpart to the access to the source code and rights to copy,
|
13
|
-
# modify and redistribute granted by the license, users are provided only
|
14
|
-
# with a limited warranty and the software's author, the holder of the
|
15
|
-
# economic rights, and the successive licensors have only limited
|
16
|
-
# liability.
|
17
|
-
#
|
18
|
-
# In this respect, the user's attention is drawn to the risks associated
|
19
|
-
# with loading, using, modifying and/or developing or reproducing the
|
20
|
-
# software by the user in light of its specific status of free software,
|
21
|
-
# that may mean that it is complicated to manipulate, and that also
|
22
|
-
# therefore means that it is reserved for developers and experienced
|
23
|
-
# professionals having in-depth computer knowledge. Users are therefore
|
24
|
-
# encouraged to load and test the software's suitability as regards their
|
25
|
-
# requirements in conditions enabling the security of their systems and/or
|
26
|
-
# data to be ensured and, more generally, to use and operate it in the
|
27
|
-
# same conditions as regards security.
|
28
|
-
#
|
29
|
-
# The fact that you are presently reading this means that you have had
|
30
|
-
# knowledge of the CeCILL license and that you accept its terms.
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
31
6
|
|
32
7
|
import importlib.metadata as mprt
|
33
8
|
import pkgutil as pkgs
|
@@ -36,14 +11,15 @@ from types import FunctionType, MethodType
|
|
36
11
|
|
37
12
|
|
38
13
|
def Modules(
|
39
|
-
with_version: bool, formatted: bool, /, *, only_loaded: bool = True
|
14
|
+
with_version: bool, formatted: bool, /, *, only_loaded: bool = True, indent: int = 0
|
40
15
|
) -> tuple[str, ...] | str:
|
41
16
|
""""""
|
42
17
|
output = []
|
43
18
|
|
44
19
|
if only_loaded:
|
45
20
|
modules = sstm.modules
|
46
|
-
module_names =
|
21
|
+
module_names = set(modules.keys()).difference(sstm.stdlib_module_names)
|
22
|
+
module_names = sorted(module_names, key=str.lower)
|
47
23
|
else:
|
48
24
|
modules = None
|
49
25
|
module_names = _ModulesUsingPkgUtil()
|
@@ -53,35 +29,34 @@ def Modules(
|
|
53
29
|
if name.startswith("_") or ("." in name):
|
54
30
|
continue
|
55
31
|
|
56
|
-
if modules is None:
|
57
|
-
version = "?version?"
|
58
|
-
else:
|
59
|
-
module = modules[name]
|
60
|
-
version = getattr(module, "__version__", None)
|
61
|
-
if version is None:
|
62
|
-
continue
|
63
|
-
|
64
|
-
if formatted and (m_idx > 0) and (m_idx % 4 == 0):
|
65
|
-
output.append("\n")
|
66
|
-
|
67
32
|
if with_version:
|
33
|
+
if modules is None:
|
34
|
+
version = "?"
|
35
|
+
else:
|
36
|
+
module = modules[name]
|
37
|
+
# strip: Some packages have a \n at the end of their version. Just in
|
38
|
+
# case, let's strip it left and right.
|
39
|
+
version = getattr(module, "__version__", "?").strip()
|
68
40
|
element = f"{name}={version}"
|
69
41
|
else:
|
70
42
|
element = name
|
43
|
+
|
44
|
+
if formatted and (m_idx > 0) and (m_idx % 4 == 0):
|
45
|
+
output.append("\n")
|
71
46
|
output.append(element)
|
72
47
|
|
73
48
|
if formatted:
|
74
|
-
max_length = max(max_length,
|
49
|
+
max_length = max(max_length, element.__len__())
|
75
50
|
m_idx += 1
|
76
51
|
|
77
52
|
if formatted:
|
78
53
|
max_length += 4
|
79
|
-
AlignedInColumns =
|
80
|
-
lambda _str: f"{_str:{max_length}}" if _str != "\n" else "\n "
|
81
|
-
)
|
54
|
+
AlignedInColumns = lambda _str: f"{_str:{max_length}}" if _str != "\n" else "\n"
|
82
55
|
output = map(AlignedInColumns, output)
|
56
|
+
output = "".join(output).rstrip()
|
83
57
|
|
84
|
-
|
58
|
+
spaces = indent * " "
|
59
|
+
return spaces + f"\n{spaces}".join(map(str.rstrip, output.splitlines()))
|
85
60
|
|
86
61
|
return tuple(output)
|
87
62
|
|
@@ -125,3 +100,50 @@ def _ModulesUsingImportlib() -> tuple[str, ...]:
|
|
125
100
|
if (_elm[0] != "_") and ("__" not in _elm) and ("/" not in _elm)
|
126
101
|
)
|
127
102
|
)
|
103
|
+
|
104
|
+
|
105
|
+
"""
|
106
|
+
COPYRIGHT NOTICE
|
107
|
+
|
108
|
+
This software is governed by the CeCILL license under French law and
|
109
|
+
abiding by the rules of distribution of free software. You can use,
|
110
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
111
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
112
|
+
"http://www.cecill.info".
|
113
|
+
|
114
|
+
As a counterpart to the access to the source code and rights to copy,
|
115
|
+
modify and redistribute granted by the license, users are provided only
|
116
|
+
with a limited warranty and the software's author, the holder of the
|
117
|
+
economic rights, and the successive licensors have only limited
|
118
|
+
liability.
|
119
|
+
|
120
|
+
In this respect, the user's attention is drawn to the risks associated
|
121
|
+
with loading, using, modifying and/or developing or reproducing the
|
122
|
+
software by the user in light of its specific status of free software,
|
123
|
+
that may mean that it is complicated to manipulate, and that also
|
124
|
+
therefore means that it is reserved for developers and experienced
|
125
|
+
professionals having in-depth computer knowledge. Users are therefore
|
126
|
+
encouraged to load and test the software's suitability as regards their
|
127
|
+
requirements in conditions enabling the security of their systems and/or
|
128
|
+
data to be ensured and, more generally, to use and operate it in the
|
129
|
+
same conditions as regards security.
|
130
|
+
|
131
|
+
The fact that you are presently reading this means that you have had
|
132
|
+
knowledge of the CeCILL license and that you accept its terms.
|
133
|
+
|
134
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
135
|
+
|
136
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
137
|
+
member of team Morpheme.
|
138
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
139
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
140
|
+
I3S, and Laboratory iBV.
|
141
|
+
|
142
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
143
|
+
Inria: https://www.inria.fr/en/
|
144
|
+
UniCA: https://univ-cotedazur.eu/
|
145
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
146
|
+
I3S: https://www.i3s.unice.fr/en/
|
147
|
+
iBV: http://ibv.unice.fr/
|
148
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
149
|
+
"""
|
@@ -0,0 +1,84 @@
|
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
6
|
+
|
7
|
+
import time
|
8
|
+
from datetime import datetime as date_time_t
|
9
|
+
|
10
|
+
# This module is imported early. Therefore, the current date and time should be close
|
11
|
+
# enough to the real start time of the main script.
|
12
|
+
_START_DATE_AND_TIME = date_time_t.now()
|
13
|
+
|
14
|
+
|
15
|
+
def TimeStamp(*, precision: str = "microseconds") -> str:
|
16
|
+
""""""
|
17
|
+
return (
|
18
|
+
date_time_t.now()
|
19
|
+
.isoformat(timespec=precision)
|
20
|
+
.replace(".", "-")
|
21
|
+
.replace(":", "-")
|
22
|
+
)
|
23
|
+
|
24
|
+
|
25
|
+
def ElapsedTime(
|
26
|
+
*, should_return_now: bool = False
|
27
|
+
) -> str | tuple[str, date_time_t]:
|
28
|
+
""""""
|
29
|
+
now = date_time_t.now()
|
30
|
+
elapsed_seconds = (now - _START_DATE_AND_TIME).total_seconds()
|
31
|
+
output = time.strftime("%H:%M:%S", time.gmtime(elapsed_seconds))
|
32
|
+
while output.startswith("00:"):
|
33
|
+
output = output.split(sep=":", maxsplit=1)[-1]
|
34
|
+
|
35
|
+
if should_return_now:
|
36
|
+
return output, now
|
37
|
+
return output
|
38
|
+
|
39
|
+
|
40
|
+
"""
|
41
|
+
COPYRIGHT NOTICE
|
42
|
+
|
43
|
+
This software is governed by the CeCILL license under French law and
|
44
|
+
abiding by the rules of distribution of free software. You can use,
|
45
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
46
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
47
|
+
"http://www.cecill.info".
|
48
|
+
|
49
|
+
As a counterpart to the access to the source code and rights to copy,
|
50
|
+
modify and redistribute granted by the license, users are provided only
|
51
|
+
with a limited warranty and the software's author, the holder of the
|
52
|
+
economic rights, and the successive licensors have only limited
|
53
|
+
liability.
|
54
|
+
|
55
|
+
In this respect, the user's attention is drawn to the risks associated
|
56
|
+
with loading, using, modifying and/or developing or reproducing the
|
57
|
+
software by the user in light of its specific status of free software,
|
58
|
+
that may mean that it is complicated to manipulate, and that also
|
59
|
+
therefore means that it is reserved for developers and experienced
|
60
|
+
professionals having in-depth computer knowledge. Users are therefore
|
61
|
+
encouraged to load and test the software's suitability as regards their
|
62
|
+
requirements in conditions enabling the security of their systems and/or
|
63
|
+
data to be ensured and, more generally, to use and operate it in the
|
64
|
+
same conditions as regards security.
|
65
|
+
|
66
|
+
The fact that you are presently reading this means that you have had
|
67
|
+
knowledge of the CeCILL license and that you accept its terms.
|
68
|
+
|
69
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
70
|
+
|
71
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
72
|
+
member of team Morpheme.
|
73
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
74
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
75
|
+
I3S, and Laboratory iBV.
|
76
|
+
|
77
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
78
|
+
Inria: https://www.inria.fr/en/
|
79
|
+
UniCA: https://univ-cotedazur.eu/
|
80
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
81
|
+
I3S: https://www.i3s.unice.fr/en/
|
82
|
+
iBV: http://ibv.unice.fr/
|
83
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
84
|
+
"""
|
@@ -0,0 +1,72 @@
|
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
6
|
+
|
7
|
+
try:
|
8
|
+
from psutil import Process as process_t # noqa
|
9
|
+
|
10
|
+
_PROCESS = process_t()
|
11
|
+
except ModuleNotFoundError:
|
12
|
+
_PROCESS = None
|
13
|
+
|
14
|
+
|
15
|
+
def CanCheckUsage() -> bool:
|
16
|
+
""""""
|
17
|
+
return _PROCESS is not None
|
18
|
+
|
19
|
+
|
20
|
+
def CurrentUsage() -> int:
|
21
|
+
""""""
|
22
|
+
if _PROCESS is None:
|
23
|
+
return -1
|
24
|
+
|
25
|
+
return _PROCESS.memory_info().rss
|
26
|
+
|
27
|
+
|
28
|
+
"""
|
29
|
+
COPYRIGHT NOTICE
|
30
|
+
|
31
|
+
This software is governed by the CeCILL license under French law and
|
32
|
+
abiding by the rules of distribution of free software. You can use,
|
33
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
34
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
35
|
+
"http://www.cecill.info".
|
36
|
+
|
37
|
+
As a counterpart to the access to the source code and rights to copy,
|
38
|
+
modify and redistribute granted by the license, users are provided only
|
39
|
+
with a limited warranty and the software's author, the holder of the
|
40
|
+
economic rights, and the successive licensors have only limited
|
41
|
+
liability.
|
42
|
+
|
43
|
+
In this respect, the user's attention is drawn to the risks associated
|
44
|
+
with loading, using, modifying and/or developing or reproducing the
|
45
|
+
software by the user in light of its specific status of free software,
|
46
|
+
that may mean that it is complicated to manipulate, and that also
|
47
|
+
therefore means that it is reserved for developers and experienced
|
48
|
+
professionals having in-depth computer knowledge. Users are therefore
|
49
|
+
encouraged to load and test the software's suitability as regards their
|
50
|
+
requirements in conditions enabling the security of their systems and/or
|
51
|
+
data to be ensured and, more generally, to use and operate it in the
|
52
|
+
same conditions as regards security.
|
53
|
+
|
54
|
+
The fact that you are presently reading this means that you have had
|
55
|
+
knowledge of the CeCILL license and that you accept its terms.
|
56
|
+
|
57
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
58
|
+
|
59
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
60
|
+
member of team Morpheme.
|
61
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
62
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
63
|
+
I3S, and Laboratory iBV.
|
64
|
+
|
65
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
66
|
+
Inria: https://www.inria.fr/en/
|
67
|
+
UniCA: https://univ-cotedazur.eu/
|
68
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
69
|
+
I3S: https://www.i3s.unice.fr/en/
|
70
|
+
iBV: http://ibv.unice.fr/
|
71
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
72
|
+
"""
|
@@ -0,0 +1,164 @@
|
|
1
|
+
"""
|
2
|
+
Copyright CNRS/Inria/UniCA
|
3
|
+
Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
4
|
+
SEE COPYRIGHT NOTICE BELOW
|
5
|
+
"""
|
6
|
+
|
7
|
+
import dataclasses as d
|
8
|
+
import logging as lggg
|
9
|
+
import re as regx
|
10
|
+
from html.parser import HTMLParser as html_parser_t
|
11
|
+
from io import IOBase as io_base_t
|
12
|
+
from pathlib import Path as path_t
|
13
|
+
|
14
|
+
try:
|
15
|
+
from rich.console import Console as console_t # noqa
|
16
|
+
except ModuleNotFoundError:
|
17
|
+
console_t = None
|
18
|
+
|
19
|
+
from logger_36.instance.logger import LOGGER
|
20
|
+
|
21
|
+
_BODY_END_PATTERN = r"</[bB][oO][dD][yY]>(.|\n)*$"
|
22
|
+
|
23
|
+
|
24
|
+
@d.dataclass(slots=True, repr=False, eq=False)
|
25
|
+
class html_reader_t(html_parser_t):
|
26
|
+
source: str = ""
|
27
|
+
inside_body: bool = d.field(init=False, default=False)
|
28
|
+
body_position_start: tuple[int, int] = d.field(init=False, default=(-1, -1))
|
29
|
+
body_position_end: tuple[int, int] = d.field(init=False, default=(-1, -1))
|
30
|
+
pieces: list[str] = d.field(init=False, default_factory=list)
|
31
|
+
|
32
|
+
def __post_init__(self) -> None:
|
33
|
+
""""""
|
34
|
+
html_parser_t.__init__(self)
|
35
|
+
self.source = self.source.strip()
|
36
|
+
self.feed(self.source)
|
37
|
+
|
38
|
+
def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]], /) -> None:
|
39
|
+
""""""
|
40
|
+
if tag == "body":
|
41
|
+
self.body_position_start = self.getpos()
|
42
|
+
self.inside_body = True
|
43
|
+
|
44
|
+
def handle_endtag(self, tag: str, /) -> None:
|
45
|
+
""""""
|
46
|
+
if tag == "body":
|
47
|
+
self.body_position_end = self.getpos()
|
48
|
+
self.inside_body = False
|
49
|
+
|
50
|
+
def handle_data(self, data: str, /) -> None:
|
51
|
+
""""""
|
52
|
+
if self.inside_body:
|
53
|
+
self.pieces.append(data)
|
54
|
+
|
55
|
+
@property
|
56
|
+
def body(self) -> str:
|
57
|
+
""""""
|
58
|
+
output = self.source.splitlines()
|
59
|
+
output = "\n".join(
|
60
|
+
output[self.body_position_start[0] : (self.body_position_end[0] + 1)]
|
61
|
+
)
|
62
|
+
output = output[self.body_position_start[1] :]
|
63
|
+
output = regx.sub(_BODY_END_PATTERN, "", output, count=1)
|
64
|
+
|
65
|
+
return output.strip()
|
66
|
+
|
67
|
+
@property
|
68
|
+
def body_as_text(self) -> str:
|
69
|
+
""""""
|
70
|
+
return "".join(self.pieces).strip()
|
71
|
+
|
72
|
+
|
73
|
+
def SaveLOGasHTML(path: str | path_t | io_base_t | None = None) -> None:
|
74
|
+
"""
|
75
|
+
From first console handler found.
|
76
|
+
"""
|
77
|
+
cannot_save = "Cannot save logging record as HTML"
|
78
|
+
|
79
|
+
if console_t is None:
|
80
|
+
LOGGER.warning(f"{cannot_save}: The Rich console cannot be imported.")
|
81
|
+
return
|
82
|
+
|
83
|
+
if path is None:
|
84
|
+
for handler in LOGGER.handlers:
|
85
|
+
if isinstance(handler, lggg.FileHandler):
|
86
|
+
path = path_t(handler.baseFilename).with_suffix(".htm")
|
87
|
+
break
|
88
|
+
if path is None:
|
89
|
+
LOGGER.warning(f"{cannot_save}: No file handler to build a filename from.")
|
90
|
+
return
|
91
|
+
if path.exists():
|
92
|
+
LOGGER.warning(
|
93
|
+
f'{cannot_save}: Automatically generated path "{path}" already exists.'
|
94
|
+
)
|
95
|
+
return
|
96
|
+
elif isinstance(path, str):
|
97
|
+
path = path_t(path)
|
98
|
+
|
99
|
+
actual_file = isinstance(path, path_t)
|
100
|
+
if actual_file and path.exists():
|
101
|
+
LOGGER.warning(f'{cannot_save}: File "{path}" already exists.')
|
102
|
+
return
|
103
|
+
|
104
|
+
for handler in LOGGER.handlers:
|
105
|
+
console = getattr(handler, "console", None)
|
106
|
+
if isinstance(console, console_t) and console.record:
|
107
|
+
html = console.export_html()
|
108
|
+
if actual_file:
|
109
|
+
with open(path, "w") as accessor:
|
110
|
+
accessor.write(html)
|
111
|
+
else:
|
112
|
+
path.write(html)
|
113
|
+
break
|
114
|
+
else:
|
115
|
+
LOGGER.warning(
|
116
|
+
f"{cannot_save}: No handler has a RICH console with recording ON."
|
117
|
+
)
|
118
|
+
|
119
|
+
|
120
|
+
"""
|
121
|
+
COPYRIGHT NOTICE
|
122
|
+
|
123
|
+
This software is governed by the CeCILL license under French law and
|
124
|
+
abiding by the rules of distribution of free software. You can use,
|
125
|
+
modify and/ or redistribute the software under the terms of the CeCILL
|
126
|
+
license as circulated by CEA, CNRS and INRIA at the following URL
|
127
|
+
"http://www.cecill.info".
|
128
|
+
|
129
|
+
As a counterpart to the access to the source code and rights to copy,
|
130
|
+
modify and redistribute granted by the license, users are provided only
|
131
|
+
with a limited warranty and the software's author, the holder of the
|
132
|
+
economic rights, and the successive licensors have only limited
|
133
|
+
liability.
|
134
|
+
|
135
|
+
In this respect, the user's attention is drawn to the risks associated
|
136
|
+
with loading, using, modifying and/or developing or reproducing the
|
137
|
+
software by the user in light of its specific status of free software,
|
138
|
+
that may mean that it is complicated to manipulate, and that also
|
139
|
+
therefore means that it is reserved for developers and experienced
|
140
|
+
professionals having in-depth computer knowledge. Users are therefore
|
141
|
+
encouraged to load and test the software's suitability as regards their
|
142
|
+
requirements in conditions enabling the security of their systems and/or
|
143
|
+
data to be ensured and, more generally, to use and operate it in the
|
144
|
+
same conditions as regards security.
|
145
|
+
|
146
|
+
The fact that you are presently reading this means that you have had
|
147
|
+
knowledge of the CeCILL license and that you accept its terms.
|
148
|
+
|
149
|
+
SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
|
150
|
+
|
151
|
+
This software is being developed by Eric Debreuve, a CNRS employee and
|
152
|
+
member of team Morpheme.
|
153
|
+
Team Morpheme is a joint team between Inria, CNRS, and UniCA.
|
154
|
+
It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
|
155
|
+
I3S, and Laboratory iBV.
|
156
|
+
|
157
|
+
CNRS: https://www.cnrs.fr/index.php/en
|
158
|
+
Inria: https://www.inria.fr/en/
|
159
|
+
UniCA: https://univ-cotedazur.eu/
|
160
|
+
Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
|
161
|
+
I3S: https://www.i3s.unice.fr/en/
|
162
|
+
iBV: http://ibv.unice.fr/
|
163
|
+
Team Morpheme: https://team.inria.fr/morpheme/
|
164
|
+
"""
|