python-sdk-remote 0.0.148__py3-none-any.whl → 0.0.150__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_sdk_remote/constants.py +2 -3
- python_sdk_remote/mini_logger.py +60 -66
- python_sdk_remote/utilities.py +36 -15
- {python_sdk_remote-0.0.148.dist-info → python_sdk_remote-0.0.150.dist-info}/METADATA +1 -1
- {python_sdk_remote-0.0.148.dist-info → python_sdk_remote-0.0.150.dist-info}/RECORD +7 -8
- python_sdk_remote/constants_src_mini_logger.py +0 -14
- {python_sdk_remote-0.0.148.dist-info → python_sdk_remote-0.0.150.dist-info}/WHEEL +0 -0
- {python_sdk_remote-0.0.148.dist-info → python_sdk_remote-0.0.150.dist-info}/top_level.txt +0 -0
python_sdk_remote/constants.py
CHANGED
|
@@ -7,7 +7,7 @@ OBJECT_TO_INSERT_CODE = {
|
|
|
7
7
|
'component_id': PYTHON_SDK_REMOTE_COMPONENT_ID,
|
|
8
8
|
'component_name': PYTHON_SDK_REMOTE_COMPONENT_NAME,
|
|
9
9
|
'component_category': LoggerComponentEnum.ComponentCategory.Code.value,
|
|
10
|
-
'
|
|
10
|
+
'developer_email_address': 'sahar.g@circ.zone'
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
OBJECT_TO_INSERT_TEST = {
|
|
@@ -15,6 +15,5 @@ OBJECT_TO_INSERT_TEST = {
|
|
|
15
15
|
'component_name': PYTHON_SDK_REMOTE_COMPONENT_NAME,
|
|
16
16
|
'component_category': LoggerComponentEnum.ComponentCategory.Unit_Test.value,
|
|
17
17
|
'testing_framework': LoggerComponentEnum.testingFramework.pytest.value,
|
|
18
|
-
'
|
|
18
|
+
'developer_email_address': 'sahar.g@circ.zone'
|
|
19
19
|
}
|
|
20
|
-
|
python_sdk_remote/mini_logger.py
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import os
|
|
3
3
|
import sys
|
|
4
|
-
|
|
5
|
-
import inspect
|
|
6
|
-
from .constants_src_mini_logger import LogMessageSeverity, StartEndEnum
|
|
7
|
-
|
|
4
|
+
|
|
8
5
|
# TODO LOGGER_MINIMAL_SEVERITY_DEFAULT
|
|
9
6
|
LOGGER_MINIMUM_SEVERITY = os.getenv("LOGGER_MINIMUM_SEVERITY", "INFO").upper()
|
|
10
7
|
# logging expects NOTSET/DEBUG/INFO/WARNING/ERROR/FATAL/CRITICAL
|
|
@@ -12,18 +9,18 @@ if LOGGER_MINIMUM_SEVERITY.isdigit():
|
|
|
12
9
|
# TODO logger_minimal_severity_default_value
|
|
13
10
|
logger_minimum_severity = int(LOGGER_MINIMUM_SEVERITY)
|
|
14
11
|
# TODO Change Magic Numbers and use the values from Logger.MessageSeverity
|
|
15
|
-
if logger_minimum_severity <
|
|
12
|
+
if logger_minimum_severity < 400:
|
|
16
13
|
# TODO LOGGER_MINIMAL_SEVERITY_DEFAULT_NAME =
|
|
17
|
-
# TODO Change "DEBUG", "INFO", "WARNING" ... into enum values from Logger.
|
|
18
|
-
LOGGER_MINIMUM_SEVERITY =
|
|
19
|
-
elif logger_minimum_severity <
|
|
20
|
-
LOGGER_MINIMUM_SEVERITY =
|
|
21
|
-
elif logger_minimum_severity <
|
|
22
|
-
LOGGER_MINIMUM_SEVERITY =
|
|
23
|
-
elif logger_minimum_severity <
|
|
24
|
-
LOGGER_MINIMUM_SEVERITY =
|
|
14
|
+
# TODO Change "DEBUG", "INFO", "WARNING" ... into enum values from Logger.MessageSeverity
|
|
15
|
+
LOGGER_MINIMUM_SEVERITY = "DEBUG"
|
|
16
|
+
elif logger_minimum_severity < 600:
|
|
17
|
+
LOGGER_MINIMUM_SEVERITY = "INFO"
|
|
18
|
+
elif logger_minimum_severity < 700:
|
|
19
|
+
LOGGER_MINIMUM_SEVERITY = "WARNING"
|
|
20
|
+
elif logger_minimum_severity < 800:
|
|
21
|
+
LOGGER_MINIMUM_SEVERITY = "ERROR"
|
|
25
22
|
else:
|
|
26
|
-
LOGGER_MINIMUM_SEVERITY =
|
|
23
|
+
LOGGER_MINIMUM_SEVERITY = "CRITICAL"
|
|
27
24
|
|
|
28
25
|
logging.basicConfig(level=LOGGER_MINIMUM_SEVERITY, stream=sys.stdout,
|
|
29
26
|
format="%(asctime)s - %(message)s")
|
|
@@ -31,108 +28,105 @@ logger = logging.getLogger(__name__)
|
|
|
31
28
|
|
|
32
29
|
|
|
33
30
|
class MiniLogger:
|
|
34
|
-
# TODO Can we
|
|
31
|
+
# TODO Can we have one generic function called by all as we have a lot of duplicated code here?
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
def _log(level: LogMessageSeverity, start_or_end: StartEndEnum = None, log_message: str = None, **kwargs):
|
|
38
|
-
"""
|
|
39
|
-
Private method to unify all log methods
|
|
40
|
-
|
|
41
|
-
Parameters:
|
|
42
|
-
level (MessageSeverity): log level
|
|
43
|
-
log_message (str): The message to be printed.
|
|
44
|
-
"""
|
|
45
|
-
object = kwargs.get("object")
|
|
46
|
-
method_name = level.name.lower()
|
|
47
|
-
method = getattr(logger, method_name)
|
|
48
|
-
if not start_or_end:
|
|
49
|
-
action_name = level.name
|
|
50
|
-
else:
|
|
51
|
-
action_name = start_or_end.name
|
|
52
|
-
stk = inspect.stack()[2]
|
|
53
|
-
function = stk.function
|
|
54
|
-
line = stk.lineno
|
|
55
|
-
if object is None:
|
|
56
|
-
method(f"Function: {function}, Line: {line}; {action_name} - {log_message}")
|
|
57
|
-
else:
|
|
58
|
-
method(f"Function: {function}, Line: {line}; {action_name} - {log_message} - {object}")
|
|
59
|
-
|
|
33
|
+
# TODO: print the caller function name
|
|
60
34
|
|
|
61
35
|
@staticmethod
|
|
62
|
-
|
|
63
|
-
def start(log_message: str = None, **kwargs):
|
|
36
|
+
def start(message: str = "", object: dict = None):
|
|
64
37
|
"""
|
|
65
38
|
Print a log message with the current time.
|
|
66
39
|
|
|
67
40
|
Parameters:
|
|
68
|
-
|
|
41
|
+
message (str): The message to be printed.
|
|
42
|
+
object (dict): The object to be printed.
|
|
69
43
|
"""
|
|
70
|
-
|
|
44
|
+
if object is None:
|
|
45
|
+
logger.debug(f"START - {message}")
|
|
46
|
+
else:
|
|
47
|
+
logger.debug(f"START - {message} - {object}")
|
|
71
48
|
|
|
72
49
|
@staticmethod
|
|
73
|
-
def end(
|
|
50
|
+
def end(message: str = "", object: dict = None):
|
|
74
51
|
"""
|
|
75
52
|
Print a log message with the current time.
|
|
76
53
|
|
|
77
54
|
Parameters:
|
|
78
|
-
|
|
55
|
+
message (str): The message to be printed.
|
|
79
56
|
"""
|
|
80
|
-
|
|
57
|
+
if object is None:
|
|
58
|
+
logger.debug(f"END - {message}")
|
|
59
|
+
else:
|
|
60
|
+
logger.debug(f"END - {message} - {object}")
|
|
81
61
|
|
|
82
62
|
# TODO convert all those methods (debug, info, warning, error) into one unified private method
|
|
83
|
-
# TODO Add to the unified private method print of the name of method, version
|
|
84
|
-
# and line number of the calling function/method to the mini_logger methods
|
|
63
|
+
# TODO Add to the unified private method print of the name of method, version and line number of the calling function/method to the mini_logger methods # noqa: E501
|
|
85
64
|
@staticmethod
|
|
86
|
-
def debug(
|
|
65
|
+
def debug(message: str = "", object: dict = None):
|
|
87
66
|
"""
|
|
88
67
|
Print a log message with the current time.
|
|
89
68
|
|
|
90
69
|
Parameters:
|
|
91
|
-
|
|
70
|
+
message (str): The message to be printed.
|
|
71
|
+
object (dict): The object to be printed.
|
|
92
72
|
"""
|
|
93
|
-
|
|
73
|
+
if object is None:
|
|
74
|
+
logger.debug(f"DEBUG - {message}")
|
|
75
|
+
else:
|
|
76
|
+
logger.debug(f"DEBUG {message} - {object}")
|
|
94
77
|
|
|
95
78
|
@staticmethod
|
|
96
|
-
def info(
|
|
79
|
+
def info(message: str = "", object: dict = None):
|
|
97
80
|
"""
|
|
98
81
|
Print a log message with the current time.
|
|
99
82
|
|
|
100
83
|
Parameters:
|
|
101
|
-
|
|
84
|
+
message (str): The message to be printed.
|
|
85
|
+
object (dict): The object to be printed.
|
|
102
86
|
"""
|
|
103
|
-
|
|
87
|
+
if object is None:
|
|
88
|
+
logger.info(f"INFO - {message}")
|
|
89
|
+
else:
|
|
90
|
+
logger.info(f"INFO {message} - {object}")
|
|
104
91
|
|
|
105
92
|
@staticmethod
|
|
106
|
-
def warning(
|
|
93
|
+
def warning(message: str = "", object: dict = None):
|
|
107
94
|
"""
|
|
108
95
|
Print a log message with the current time.
|
|
109
96
|
|
|
110
97
|
Parameters:
|
|
111
|
-
|
|
98
|
+
message (str): The message to be printed.
|
|
99
|
+
object (dict): The object to be printed.
|
|
112
100
|
"""
|
|
113
101
|
# TODO Add the source of the message - We should add the object or atleast some parts of it
|
|
114
|
-
|
|
115
|
-
|
|
102
|
+
if object is None:
|
|
103
|
+
logger.warning(f"WARNING - {message}")
|
|
104
|
+
else:
|
|
105
|
+
logger.warning(f"WARNING {message} - {object}")
|
|
116
106
|
|
|
117
107
|
@staticmethod
|
|
118
|
-
def error(
|
|
108
|
+
def error(message: str = "", object: dict = None):
|
|
119
109
|
"""
|
|
120
110
|
Print a log error message with the current time.
|
|
121
111
|
|
|
122
112
|
Parameters:
|
|
123
|
-
|
|
113
|
+
message (str): The message to be printed.
|
|
114
|
+
object (dict): The object to be printed.
|
|
124
115
|
"""
|
|
125
|
-
|
|
116
|
+
if object is None:
|
|
117
|
+
logger.error(f"ERROR - {message}")
|
|
118
|
+
else:
|
|
119
|
+
logger.error(f"ERROR - {message} - {object}")
|
|
126
120
|
|
|
127
121
|
@staticmethod
|
|
128
|
-
def exception(
|
|
122
|
+
def exception(message: str = "", object: Exception or dict = None):
|
|
129
123
|
"""
|
|
130
124
|
Print a log error message with the current time.
|
|
131
125
|
|
|
132
126
|
Parameters:
|
|
133
|
-
|
|
127
|
+
message (str): The message to be printed.
|
|
128
|
+
object (dict / Exception): The object / Exception to be printed.
|
|
134
129
|
"""
|
|
135
|
-
object = kwargs.get("object")
|
|
136
130
|
if isinstance(object, Exception):
|
|
137
131
|
exception = object
|
|
138
132
|
elif isinstance(object, dict):
|
|
@@ -141,6 +135,6 @@ class MiniLogger:
|
|
|
141
135
|
exception = None
|
|
142
136
|
|
|
143
137
|
if object is None:
|
|
144
|
-
logger.exception(f"EXCEPTION - {
|
|
138
|
+
logger.exception(f"EXCEPTION - {message}")
|
|
145
139
|
else:
|
|
146
|
-
logger.exception(f"EXCEPTION- {
|
|
140
|
+
logger.exception(f"EXCEPTION- {message} - {object}", exc_info=exception)
|
python_sdk_remote/utilities.py
CHANGED
|
@@ -279,6 +279,21 @@ def is_datetime_in_datetime_range(check_datetime: datetime, datetime_range: (dat
|
|
|
279
279
|
return is_datetime_in_datetime_range_result
|
|
280
280
|
|
|
281
281
|
|
|
282
|
+
# TODO add optional_prefix optional parameter. First check with optional_prefix, if not found, check without it.
|
|
283
|
+
def our_get_env(key: str, default: str = None, raise_if_not_found: bool = True,
|
|
284
|
+
raise_if_empty: bool = False) -> str:
|
|
285
|
+
logger.start(object={"key": key, "default": default,
|
|
286
|
+
"raise_if_not_found": raise_if_not_found,
|
|
287
|
+
"raise_if_empty": raise_if_empty})
|
|
288
|
+
env_var = os.getenv(key, default)
|
|
289
|
+
# TODO: "default is None" is always False
|
|
290
|
+
if ((raise_if_not_found and key not in os.environ and default is None)
|
|
291
|
+
or (raise_if_empty and not env_var and not default)):
|
|
292
|
+
raise Exception(f"Environment variable {key} not found - please check your .env file") # noqa: E501
|
|
293
|
+
logger.end(object={"env_var": env_var})
|
|
294
|
+
return env_var
|
|
295
|
+
|
|
296
|
+
|
|
282
297
|
def get_brand_name(raise_if_not_found: bool = True,
|
|
283
298
|
raise_if_empty: bool = False) -> str:
|
|
284
299
|
get_brand_name_result = our_get_env("BRAND_NAME",
|
|
@@ -296,22 +311,26 @@ def get_environment_name(raise_if_not_found: bool = True,
|
|
|
296
311
|
return environment_name
|
|
297
312
|
|
|
298
313
|
|
|
299
|
-
def
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
314
|
+
def get_product_user_identifier(raise_if_not_found: bool = True,
|
|
315
|
+
raise_if_empty: bool = False) -> str:
|
|
316
|
+
get_product_user_identifier_result = our_get_env("PRODUCT_USER_IDENTIFIER",
|
|
317
|
+
raise_if_not_found=raise_if_not_found, # noqa E501
|
|
318
|
+
raise_if_empty=raise_if_empty) # noqa E501
|
|
319
|
+
return get_product_user_identifier_result
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def get_product_user_password(raise_if_not_found: bool = True,
|
|
323
|
+
raise_if_empty: bool = False) -> str:
|
|
324
|
+
# TODO Add support to PRODUCT_USER_PASSWORD and deprecation message for PRODUCT_PASSWORD (backward compatible)
|
|
325
|
+
get_product_user_password_result = our_get_env("PRODUCT_PASSWORD",
|
|
326
|
+
raise_if_not_found=raise_if_not_found, # noqa E501
|
|
327
|
+
raise_if_empty=raise_if_empty) # noqa E501
|
|
328
|
+
return get_product_user_password_result
|
|
311
329
|
|
|
312
330
|
|
|
313
331
|
# TODO As only the database package uses those, let's move those three to the database package # noqa: E501
|
|
314
|
-
def get_sql_hostname(raise_if_not_found: bool = True,
|
|
332
|
+
def get_sql_hostname(raise_if_not_found: bool = True,
|
|
333
|
+
raise_if_empty: bool = False) -> str:
|
|
315
334
|
get_sql_hostname_result = our_get_env("RDS_HOSTNAME",
|
|
316
335
|
raise_if_empty=raise_if_empty)
|
|
317
336
|
return get_sql_hostname_result
|
|
@@ -416,7 +435,7 @@ def validate_arguments(args: dict) -> None:
|
|
|
416
435
|
:return: True if all arguments are not None or '', False otherwise
|
|
417
436
|
"""
|
|
418
437
|
for arg, value in args.items():
|
|
419
|
-
if not
|
|
438
|
+
if not arg:
|
|
420
439
|
raise ValueError(f"Argument {arg} is cannot be empty (got {value})")
|
|
421
440
|
|
|
422
441
|
|
|
@@ -456,8 +475,10 @@ def camel_to_snake(camel_str: str) -> str:
|
|
|
456
475
|
return snake_str
|
|
457
476
|
|
|
458
477
|
|
|
478
|
+
# We have both deprecation_warning as method in Logger and as a standalone function
|
|
479
|
+
# We can call the deprecation_warning_function from the logger
|
|
459
480
|
@lru_cache(maxsize=64) # don't print the same warning multiple times
|
|
460
|
-
def
|
|
481
|
+
def deprecation_warning_function(old_name: str, new_name: str, start_date: date = None) -> None:
|
|
461
482
|
if start_date and start_date < date.today():
|
|
462
483
|
return
|
|
463
484
|
warnings_message = f"Please use {old_name} instead of {new_name}."
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
python_sdk_remote/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
python_sdk_remote/constants.py,sha256=
|
|
3
|
-
python_sdk_remote/constants_src_mini_logger.py,sha256=ukaPhopFSxnLeQwyHa4VUi3TACh4QuKn77JtSK8Z1Tg,247
|
|
2
|
+
python_sdk_remote/constants.py,sha256=8n1iV8CJV5YdVeusue2Hfef8BGEFP72V3ycl2E0INLI,767
|
|
4
3
|
python_sdk_remote/http_response.py,sha256=5_h9xOtUhsMzxUiLT4wkYBpL0StA7XYtaqKF4esGwis,6370
|
|
5
4
|
python_sdk_remote/is_test_data.py,sha256=zbUz-Juj7vOPG9TtIttMIBWFxbsOs4-TuR1RYfGNkp4,92
|
|
6
5
|
python_sdk_remote/item.py,sha256=6DQs1nBKbEmnHjE50vZtkMr14ECS_9b8cvE7ItPAbhE,322
|
|
7
|
-
python_sdk_remote/mini_logger.py,sha256=
|
|
6
|
+
python_sdk_remote/mini_logger.py,sha256=EAARhRUvUTQKeSJLDS5n9AxNra9Jk0DUyFsAMhX0wCs,4869
|
|
8
7
|
python_sdk_remote/our_object.py,sha256=Db3_CbM4e1VtDU97VDesnBNMXNuYvnuDL7QqHv4MgJo,4618
|
|
9
8
|
python_sdk_remote/unified_json.py,sha256=zk4Lo9t9MSHXW8UKdo50YCYmFv5FgTsmHf6l2AWqLWU,961
|
|
10
|
-
python_sdk_remote/utilities.py,sha256=
|
|
9
|
+
python_sdk_remote/utilities.py,sha256=MVWbVkuWQNywumh-7Sw1cLy3Fiq7EMtJiYzJ0HclRzw,18072
|
|
11
10
|
python_sdk_remote/valid_json_versions.py,sha256=-ZU65JYI6gTEfK8o6gu9Dmm9SQmwzj5pDbEXiyUbBhQ,138
|
|
12
11
|
python_sdk_remote/validate_environment.py,sha256=nzCHZDw56G56ekrTQT3gG48utjsU4VCwQi9dVsBDas0,2268
|
|
13
|
-
python_sdk_remote-0.0.
|
|
14
|
-
python_sdk_remote-0.0.
|
|
15
|
-
python_sdk_remote-0.0.
|
|
16
|
-
python_sdk_remote-0.0.
|
|
12
|
+
python_sdk_remote-0.0.150.dist-info/METADATA,sha256=dtgAcLP89567n7fieDu8GWgxXB3fHwyNkIKK6t8yXhI,729
|
|
13
|
+
python_sdk_remote-0.0.150.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
14
|
+
python_sdk_remote-0.0.150.dist-info/top_level.txt,sha256=JTpEq_svPlI5hTlPq30Ne-NkR-u5464gjVDP2U74PvE,18
|
|
15
|
+
python_sdk_remote-0.0.150.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|