inspy-logger 3.0.dev5__py3-none-any.whl → 3.0.2.dev1__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.
- inspy_logger/Scripts/main.py +51 -37
- inspy_logger/__about__.py +0 -13
- inspy_logger/__init__.py +4 -0
- inspy_logger/helpers/base_classes.py +10 -0
- inspy_logger/helpers/debug/__init__.py +0 -0
- inspy_logger/helpers/debug/environment.py +179 -0
- inspy_logger/helpers/debug/system/__init__.py +0 -0
- inspy_logger/helpers/debug/system/processor/__init__.py +64 -0
- inspy_logger/helpers/debug/system/winx/__init__.py +25 -0
- inspy_logger/helpers/network.py +5 -5
- inspy_logger/helpers/units.py +57 -0
- inspy_logger/version.py +106 -153
- {inspy_logger-3.0.dev5.dist-info → inspy_logger-3.0.2.dev1.dist-info}/METADATA +1 -1
- inspy_logger-3.0.2.dev1.dist-info/RECORD +20 -0
- inspy_logger/helpers/cache.py +0 -140
- inspy_logger-3.0.dev5.dist-info/RECORD +0 -15
- {inspy_logger-3.0.dev5.dist-info → inspy_logger-3.0.2.dev1.dist-info}/LICENSE.md +0 -0
- {inspy_logger-3.0.dev5.dist-info → inspy_logger-3.0.2.dev1.dist-info}/WHEEL +0 -0
- {inspy_logger-3.0.dev5.dist-info → inspy_logger-3.0.2.dev1.dist-info}/entry_points.txt +0 -0
inspy_logger/Scripts/main.py
CHANGED
|
@@ -9,25 +9,50 @@ Author:
|
|
|
9
9
|
"""
|
|
10
10
|
INSPY_LOG_LEVEL = 'info'
|
|
11
11
|
|
|
12
|
+
from argparse import ArgumentParser
|
|
13
|
+
from inspy_logger.helpers.debug.environment import fetch_system_info
|
|
12
14
|
from inspy_logger.version import parse_version, get_full_version_name, PyPiVersionInfo
|
|
13
|
-
import sys
|
|
14
15
|
from rich import print
|
|
15
16
|
from rich.table import Table
|
|
16
|
-
|
|
17
|
+
import sys
|
|
17
18
|
|
|
19
|
+
# ---- SET UP PARSER --------------------------------
|
|
18
20
|
|
|
19
21
|
parser = ArgumentParser('inspy-logger-version', description='Displays version information for inspy-logger.')
|
|
20
22
|
|
|
21
23
|
parser.add_argument('-v', '--version', action='version', version=parse_version())
|
|
22
24
|
|
|
25
|
+
# ---- SET UP SUBPARSERS --------------------------------
|
|
26
|
+
|
|
23
27
|
subparsers = parser.add_subparsers(title='subcommands', dest='subcommand')
|
|
24
28
|
|
|
29
|
+
# ---- UPDATE COMMAND --------------------------------
|
|
30
|
+
|
|
25
31
|
update_parser =subparsers.add_parser('update', help='Checks for updates to inspy-logger.')
|
|
26
32
|
|
|
27
33
|
update_parser.add_argument('-p', '--pre-release', action='store_true', help='When checking for updates, include pre-release versions.')
|
|
28
34
|
|
|
35
|
+
# ---- DEBUG COMMAND --------------------------------
|
|
36
|
+
|
|
37
|
+
debug_parser = subparsers.add_parser('debug', help='Fetches a collection of environment information to help debug inspy-logger.')
|
|
38
|
+
|
|
39
|
+
debug_parser.add_argument('-C', '--copy-to-clipboard', action='store_true', help='Copies the debug information to the clipboard.')
|
|
40
|
+
debug_parser.add_argument('-P', '--print', action='store_true', help='Prints the debug information to the console.', default=True)
|
|
41
|
+
|
|
42
|
+
# ---- FORMAT FLAGS --------------------------------
|
|
43
|
+
|
|
44
|
+
fmt_grp = debug_parser.add_mutually_exclusive_group()
|
|
45
|
+
|
|
46
|
+
fmt_grp.add_argument('-M', '--markdown', action='store_true', help='Formats the debug information in Markdown.')
|
|
47
|
+
|
|
48
|
+
fmt_grp.add_argument('-J', '--json', action='store_true', help='Formats the debug information in JSON.')
|
|
49
|
+
|
|
50
|
+
fmt_grp.add_argument('-T', '--text', action='store_true', help='Formats the debug information in plain text.')
|
|
51
|
+
|
|
52
|
+
# Parse the arguments
|
|
29
53
|
parsed_args = parser.parse_args()
|
|
30
54
|
|
|
55
|
+
# END PARSER SETUP
|
|
31
56
|
|
|
32
57
|
if parsed_args.subcommand == 'update':
|
|
33
58
|
INCLUDE_PRE_RELEASE_FOR_UPDATE_CHECK = parsed_args.pre_release
|
|
@@ -35,57 +60,46 @@ else:
|
|
|
35
60
|
INCLUDE_PRE_RELEASE_FOR_UPDATE_CHECK = False
|
|
36
61
|
|
|
37
62
|
|
|
38
|
-
pypi_info = PyPiVersionInfo(include_pre_release_for_update_check=INCLUDE_PRE_RELEASE_FOR_UPDATE_CHECK)
|
|
39
|
-
|
|
40
63
|
|
|
41
|
-
def update():
|
|
42
|
-
"""
|
|
43
|
-
Checks for updates to inspy-logger.
|
|
44
64
|
|
|
45
|
-
Returns:
|
|
46
|
-
None
|
|
47
65
|
|
|
48
|
-
|
|
49
|
-
v3.0
|
|
50
|
-
"""
|
|
51
|
-
try:
|
|
52
|
-
if pypi_info.update_available:
|
|
53
|
-
print(f'\n\n[bold green]Update Available![/bold green] New version: [bold cyan]{pypi_info.new_version_available}[/bold cyan]')
|
|
54
|
-
else:
|
|
55
|
-
print(f'\n\n[bold green]No update available.[/bold green] Current version: [bold cyan]{parse_version()}[/bold cyan] {"which is newer than the available version on PyPi.org" if pypi_info.installed_newer_than_latest else ""}')
|
|
56
|
-
except Exception as e:
|
|
57
|
-
print(f'An error occurred during the update check: {str(e)}')
|
|
66
|
+
def main():
|
|
58
67
|
|
|
68
|
+
version = PyPiVersionInfo()
|
|
59
69
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
ACTIONS = {
|
|
71
|
+
'default': version.print_version_info,
|
|
72
|
+
'update': version.update,
|
|
73
|
+
'debug': fetch_system_info,
|
|
64
74
|
|
|
65
|
-
|
|
66
|
-
table.add_column('Property', style='cyan', width=20)
|
|
67
|
-
table.add_column('Value', justify='center')
|
|
75
|
+
}
|
|
68
76
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
table.add_row('Full Version Name', get_full_version_name())
|
|
77
|
+
if parsed_args.subcommand is None:
|
|
78
|
+
parsed_args.subcommand = 'default'
|
|
72
79
|
|
|
73
|
-
if
|
|
74
|
-
table.add_row('Update Available', '[bold green]Yes[/bold green]')
|
|
75
|
-
table.add_row('Latest Version', f'{pypi_info.new_version_available_num}')
|
|
80
|
+
if parsed_args.subcommand == 'debug':
|
|
76
81
|
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
if (
|
|
83
|
+
parsed_args.markdown
|
|
84
|
+
or not parsed_args.json
|
|
85
|
+
and not parsed_args.text
|
|
86
|
+
):
|
|
87
|
+
fmt = 'markdown'
|
|
88
|
+
elif parsed_args.json:
|
|
89
|
+
fmt = 'json'
|
|
90
|
+
else:
|
|
91
|
+
fmt = 'text'
|
|
79
92
|
|
|
80
|
-
|
|
93
|
+
fetch_system_info(copy_to_clipboard=parsed_args.copy_to_clipboard, format_type=fmt, print_to_console=parsed_args.print)
|
|
81
94
|
|
|
82
95
|
|
|
83
96
|
|
|
84
|
-
|
|
97
|
+
if parsed_args.subcommand in ACTIONS:
|
|
98
|
+
ACTIONS[parsed_args.subcommand]()
|
|
85
99
|
|
|
86
|
-
return update() if parsed_args.subcommand == 'update' else get_version_info()
|
|
87
100
|
|
|
88
101
|
|
|
102
|
+
return parsed_args
|
|
89
103
|
|
|
90
104
|
if __name__ == '__main__':
|
|
91
105
|
main()
|
inspy_logger/__about__.py
CHANGED
|
@@ -19,16 +19,3 @@ __authors__ = [
|
|
|
19
19
|
('Inspyre-Softworks', 'https://inspyre.tech'),
|
|
20
20
|
('Taylor-Jayde Blackstone', '<t.blackstone@inspyre.tech')
|
|
21
21
|
]
|
|
22
|
-
|
|
23
|
-
'''
|
|
24
|
-
File Change History:
|
|
25
|
-
11/5/22 - 4:21 AM (v2.1.2):
|
|
26
|
-
- Added description to docstring. (target: 2.1.2)
|
|
27
|
-
|
|
28
|
-
11/5/22 - 4:41 AM:
|
|
29
|
-
- Version bump (target: 2.1.3)
|
|
30
|
-
|
|
31
|
-
08/16/2023 - 13:49 (v3.0):
|
|
32
|
-
- Version bump (v2.1.3 -> v3.0-dev.1)
|
|
33
|
-
|
|
34
|
-
'''
|
inspy_logger/__init__.py
CHANGED
|
@@ -251,10 +251,12 @@ class Logger:
|
|
|
251
251
|
"""
|
|
252
252
|
self._log(logging.INFO, message, args=(), stacklevel=2)
|
|
253
253
|
|
|
254
|
+
|
|
254
255
|
def warning(self, message):
|
|
255
256
|
"""
|
|
256
257
|
Logs a warning message.
|
|
257
258
|
|
|
259
|
+
|
|
258
260
|
Args:
|
|
259
261
|
message (str): The message to log.
|
|
260
262
|
"""
|
|
@@ -264,6 +266,7 @@ class Logger:
|
|
|
264
266
|
"""
|
|
265
267
|
Logs an error message.
|
|
266
268
|
|
|
269
|
+
|
|
267
270
|
Args:
|
|
268
271
|
message (str): The message to log.
|
|
269
272
|
"""
|
|
@@ -284,6 +287,7 @@ class Logger:
|
|
|
284
287
|
|
|
285
288
|
return f'<Logger: {name} w/ level {self.logger.level} at {hex_id}{parent_part}>'
|
|
286
289
|
|
|
290
|
+
|
|
287
291
|
@classmethod
|
|
288
292
|
def create_logger_for_caller(cls):
|
|
289
293
|
"""
|
|
@@ -61,6 +61,16 @@ class Loggable:
|
|
|
61
61
|
class_logger = None
|
|
62
62
|
|
|
63
63
|
def __init__(self, parent_log_device=None, **kwargs):
|
|
64
|
+
"""
|
|
65
|
+
Initializes an instance of the class.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
parent_log_device (optional): The parent log device. Defaults to None.
|
|
69
|
+
**kwargs: Additional keyword arguments.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
None
|
|
73
|
+
"""
|
|
64
74
|
self.parent_log_device = parent_log_device
|
|
65
75
|
self.__log_name = self.__class__.__name__
|
|
66
76
|
if self.parent_log_device is not None:
|
|
File without changes
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import json
|
|
3
|
+
import platform
|
|
4
|
+
import sys
|
|
5
|
+
import pyperclip
|
|
6
|
+
from pyperclip import copy
|
|
7
|
+
|
|
8
|
+
from inspy_logger.version import parse_version
|
|
9
|
+
|
|
10
|
+
VALID_DATA_FORMATS = [
|
|
11
|
+
'markdown',
|
|
12
|
+
'json',
|
|
13
|
+
'text'
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def determine_execution_mode():
|
|
18
|
+
"""
|
|
19
|
+
Determines the execution mode of the program.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
str:
|
|
23
|
+
Either 'Script' or 'REPL' depending on the execution mode.
|
|
24
|
+
"""
|
|
25
|
+
return "REPL" if len(sys.argv) == 1 else "Script"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_operating_system_info():
|
|
29
|
+
"""
|
|
30
|
+
Gets the operating system information.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
dict:
|
|
34
|
+
A dictionary containing the operating system information.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
os_name = platform.system()
|
|
38
|
+
|
|
39
|
+
if os_name.lower() == 'windows':
|
|
40
|
+
from inspy_logger.helpers.debug.system.winx import get_win_version_info
|
|
41
|
+
|
|
42
|
+
return get_win_version_info()
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
'name': platform.system(),
|
|
46
|
+
'version': platform.release()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def is_valid_data_format(data_format):
|
|
52
|
+
"""
|
|
53
|
+
Checks if the specified data format is valid.
|
|
54
|
+
|
|
55
|
+
This function is case-insensitive and compares the specified data format against the `VALID_DATA_FORMATS` list.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
Note:
|
|
59
|
+
Valid formats are as follows:
|
|
60
|
+
- markdown
|
|
61
|
+
- json
|
|
62
|
+
- text
|
|
63
|
+
|
|
64
|
+
Parameters:
|
|
65
|
+
data_format (str):
|
|
66
|
+
The format you'd like the data to be returned in.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
bool:
|
|
70
|
+
Whether the specified data format is valid.
|
|
71
|
+
|
|
72
|
+
"""
|
|
73
|
+
return data_format.lower() in VALID_DATA_FORMATS
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def get_system_info(format_type='markdown'):
|
|
77
|
+
"""
|
|
78
|
+
Gathers system information and formats it based on the specified format type.
|
|
79
|
+
|
|
80
|
+
Parameters:
|
|
81
|
+
format_type (str):
|
|
82
|
+
The format type for the output. Options are 'markdown', 'json', 'text'.
|
|
83
|
+
Default is 'markdown'.
|
|
84
|
+
|
|
85
|
+
Note:
|
|
86
|
+
Valid formats are 'markdown', 'json', and 'text'.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
str:
|
|
90
|
+
A string containing the system information in the specified format.
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
if not is_valid_data_format(format_type):
|
|
94
|
+
raise ValueError(f"Invalid format type: {format_type}. Must be one of {VALID_DATA_FORMATS}")
|
|
95
|
+
|
|
96
|
+
# Gather system information
|
|
97
|
+
os_name = platform.system()
|
|
98
|
+
os_version = platform.release()
|
|
99
|
+
|
|
100
|
+
os_version_full = platform.version()
|
|
101
|
+
|
|
102
|
+
if os_name.lower() == 'windows' and os_version == '10':
|
|
103
|
+
from inspy_logger.helpers.debug.system.winx import is_win_11
|
|
104
|
+
|
|
105
|
+
if is_win_11(os_version_full):
|
|
106
|
+
os_version = '11'
|
|
107
|
+
|
|
108
|
+
os_version = f'{os_version} ({os_version_full})'
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
python_version = platform.python_version()
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
sys_info = {
|
|
117
|
+
'os_name': platform.system(),
|
|
118
|
+
'os_version': platform.release(),
|
|
119
|
+
'python_version': platform.python_version(),
|
|
120
|
+
'isl_version': parse_version(),
|
|
121
|
+
'execution_mode': "REPL" if len(sys.argv) == 1 else "Script"
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
# Format the information
|
|
125
|
+
if format_type == 'markdown':
|
|
126
|
+
return f"""
|
|
127
|
+
💻 **System Info:**
|
|
128
|
+
- 💾 **Operating System**:
|
|
129
|
+
- [x] {os_name} {os_version}
|
|
130
|
+
- 🐍 **Python Version**: {python_version}
|
|
131
|
+
- 🌈 **InSPy-Logger Version**: {sys_info['isl_version']}
|
|
132
|
+
- - [{sys_info['execution_mode'] == 'Script'}] Script
|
|
133
|
+
- [{sys_info['execution_mode'] == 'REPL'}] REPL
|
|
134
|
+
""".strip()
|
|
135
|
+
elif format_type == 'json':
|
|
136
|
+
return json.dumps({
|
|
137
|
+
"System Info": {
|
|
138
|
+
"Operating System": f"{os_name} {os_version}",
|
|
139
|
+
"Python Version": python_version,
|
|
140
|
+
"InSPy-Logger Version": sys_info['isl_version'],
|
|
141
|
+
"Execution Mode": sys_info['execution_mode']
|
|
142
|
+
}
|
|
143
|
+
}, indent=4)
|
|
144
|
+
else: # plain text
|
|
145
|
+
return f"""
|
|
146
|
+
System Info:
|
|
147
|
+
Operating System: {os_name} {os_version}
|
|
148
|
+
Python Version: {python_version}
|
|
149
|
+
InSPy-Logger Version: {sys_info['isl_version']}
|
|
150
|
+
Execution Mode: {sys_info['execution_mode']}
|
|
151
|
+
""".strip()
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def fetch_system_info(copy_to_clipboard=False, format_type='markdown', print_to_console=None):
|
|
155
|
+
"""
|
|
156
|
+
Fetches system information and formats it based on the specified format type.
|
|
157
|
+
|
|
158
|
+
Parameters:
|
|
159
|
+
copy_to_clipboard (bool):
|
|
160
|
+
Whether to copy the output to the clipboard. Default is False.
|
|
161
|
+
|
|
162
|
+
format_type (str):
|
|
163
|
+
The format type for the output. Options are 'markdown',
|
|
164
|
+
'json', 'text'. Default is 'markdown'.
|
|
165
|
+
|
|
166
|
+
print_to_console (bool):
|
|
167
|
+
Whether to print the output to the console. Default is None.
|
|
168
|
+
|
|
169
|
+
Note:
|
|
170
|
+
If this is None, it will default to True.
|
|
171
|
+
|
|
172
|
+
Returns:
|
|
173
|
+
str:
|
|
174
|
+
A string containing the system information in the specified format.
|
|
175
|
+
"""
|
|
176
|
+
info = get_system_info(format_type)
|
|
177
|
+
if copy_to_clipboard:
|
|
178
|
+
copy(info)
|
|
179
|
+
return info
|
|
File without changes
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import platform
|
|
2
|
+
import multiprocessing
|
|
3
|
+
import psutil
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
# Function to check if the system architecture is 64-bit
|
|
7
|
+
def is_64bit():
|
|
8
|
+
"""
|
|
9
|
+
Checks if the system architecture is 64-bit.
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
bool: True if the system architecture is 64-bit, False otherwise.
|
|
13
|
+
"""
|
|
14
|
+
return platform.architecture()[0] == '64bit'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Function to get the number of cores
|
|
18
|
+
def number_of_cores():
|
|
19
|
+
"""
|
|
20
|
+
Gets the number of cores in the system.
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
int: The number of cores in the system.
|
|
24
|
+
"""
|
|
25
|
+
return multiprocessing.cpu_count()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# Function to get the processor core information
|
|
29
|
+
def get_processor_core_info():
|
|
30
|
+
"""
|
|
31
|
+
Gets the processor core information.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
dict: A dictionary containing the total number of cores, the number of physical cores, and the number of logical cores.
|
|
35
|
+
"""
|
|
36
|
+
phys = psutil.cpu_count(logical=False)
|
|
37
|
+
total = number_of_cores()
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
'total': total,
|
|
41
|
+
'physical': phys,
|
|
42
|
+
'logical': total - phys
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# Function to get the processor information
|
|
47
|
+
def _get_processor_info():
|
|
48
|
+
"""
|
|
49
|
+
Gets the processor information.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
dict: A dictionary containing the name of the processor, the architecture of the processor, and the core information of the processor.
|
|
53
|
+
"""
|
|
54
|
+
cores = get_processor_core_info()
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
'name': platform.processor(),
|
|
58
|
+
'architecture': '64-bit' if is_64bit() else '32-bit',
|
|
59
|
+
'cores': get_processor_core_info()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# A dictionary containing the processor information
|
|
64
|
+
PROCESSOR_INFO = _get_processor_info()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from packaging import version
|
|
2
|
+
import platform
|
|
3
|
+
|
|
4
|
+
WIN_11_VERSION = version.parse('10.0.2200')
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def is_win_11(os_version):
|
|
8
|
+
return version.parse(os_version) >= WIN_11_VERSION
|
|
9
|
+
|
|
10
|
+
def is_64bit():
|
|
11
|
+
return platform.architecture()[0] == '64bit'
|
|
12
|
+
|
|
13
|
+
def get_win_version():
|
|
14
|
+
release, build_num, service_pack, _ = platform.win32_ver()
|
|
15
|
+
|
|
16
|
+
if release == '10' and is_win_11(build_num):
|
|
17
|
+
release = '11'
|
|
18
|
+
|
|
19
|
+
ver = {
|
|
20
|
+
'release': f'Windows {release}',
|
|
21
|
+
'build': build_num,
|
|
22
|
+
'service_pack': service_pack.replace('SP', ''),
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
}
|
inspy_logger/helpers/network.py
CHANGED
|
@@ -27,8 +27,7 @@ from __future__ import annotations
|
|
|
27
27
|
from urllib.parse import quote as url_safe
|
|
28
28
|
|
|
29
29
|
import requests
|
|
30
|
-
|
|
31
|
-
from inspy_logger.helpers.cache import TLDCache
|
|
30
|
+
from public_suffix_list import PublicSuffixList
|
|
32
31
|
|
|
33
32
|
DEFAULT_TEST_HOSTS = [
|
|
34
33
|
['https', 'inspyre', 'tech'],
|
|
@@ -44,10 +43,11 @@ hosts = []
|
|
|
44
43
|
:obj:`list`[:obj:`Host`]:
|
|
45
44
|
A list of host objects that will be used to connect to.
|
|
46
45
|
"""
|
|
46
|
+
psl = PublicSuffixList()
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
URL_SUFFIXES = psl._suffixes
|
|
49
49
|
|
|
50
|
-
VALID_TLDS =
|
|
50
|
+
VALID_TLDS = URL_SUFFIXES
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
class Host():
|
|
@@ -169,7 +169,7 @@ class Host():
|
|
|
169
169
|
def tld(self, new):
|
|
170
170
|
if not isinstance(new, str):
|
|
171
171
|
raise TypeError(f"New value must be a string not {type(new)}")
|
|
172
|
-
if new not in
|
|
172
|
+
if new not in URL_SUFFIXES:
|
|
173
173
|
raise ValueError("TLD must be valid!")
|
|
174
174
|
|
|
175
175
|
self.__tld = new
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
class ByteConverter:
|
|
2
|
+
"""
|
|
3
|
+
A class to convert between various units of digital storage.
|
|
4
|
+
|
|
5
|
+
Supported units: Bytes, Kilobytes, Megabytes, Gigabytes, Terabytes, Petabytes, Exabytes, Zettabytes, Yottabytes,
|
|
6
|
+
Kibibytes, Mebibytes, Gibibytes, Tebibytes, Pebibytes, Exbibytes, Zebibytes, Yobibytes.
|
|
7
|
+
|
|
8
|
+
Methods:
|
|
9
|
+
convert(value, from_unit, to_unit): Converts the given value from one unit to another.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
# Dictionary to store conversion rates relative to bytes
|
|
13
|
+
_conversion_rates = {
|
|
14
|
+
'bytes': 1,
|
|
15
|
+
'kilobytes': 1000,
|
|
16
|
+
'megabytes': 1000 ** 2,
|
|
17
|
+
'gigabytes': 1000 ** 3,
|
|
18
|
+
'terabytes': 1000 ** 4,
|
|
19
|
+
'petabytes': 1000 ** 5,
|
|
20
|
+
'exabytes': 1000 ** 6,
|
|
21
|
+
'zettabytes': 1000 ** 7,
|
|
22
|
+
'yottabytes': 1000 ** 8,
|
|
23
|
+
'kibibytes': 1024,
|
|
24
|
+
'mebibytes': 1024 ** 2,
|
|
25
|
+
'gibibytes': 1024 ** 3,
|
|
26
|
+
'tebibytes': 1024 ** 4,
|
|
27
|
+
'pebibytes': 1024 ** 5,
|
|
28
|
+
'exbibytes': 1024 ** 6,
|
|
29
|
+
'zebibytes': 1024 ** 7,
|
|
30
|
+
'yobibytes': 1024 ** 8
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@classmethod
|
|
34
|
+
def convert(cls, value: float, from_unit: str, to_unit: str) -> float:
|
|
35
|
+
"""
|
|
36
|
+
Converts the given value from one unit to another.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
value (float): The value to convert.
|
|
40
|
+
from_unit (str): The unit to convert from. Must be one of the supported units.
|
|
41
|
+
to_unit (str): The unit to convert to. Must be one of the supported units.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
float: The converted value in the target unit.
|
|
45
|
+
|
|
46
|
+
Raises:
|
|
47
|
+
ValueError: If an unsupported unit is specified.
|
|
48
|
+
"""
|
|
49
|
+
from_unit = from_unit.lower()
|
|
50
|
+
to_unit = to_unit.lower()
|
|
51
|
+
|
|
52
|
+
if from_unit not in cls._conversion_rates or to_unit not in cls._conversion_rates:
|
|
53
|
+
raise ValueError("Unsupported unit. Supported units are: " + ', '.join(cls._conversion_rates.keys()))
|
|
54
|
+
|
|
55
|
+
# Convert the value to bytes first, then to the target unit
|
|
56
|
+
value_in_bytes = value * cls._conversion_rates[from_unit]
|
|
57
|
+
return value_in_bytes / cls._conversion_rates[to_unit]
|
inspy_logger/version.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import requests
|
|
2
|
-
import packaging
|
|
3
2
|
from packaging import version as pkg_version
|
|
3
|
+
import sys
|
|
4
|
+
from rich.table import Table
|
|
5
|
+
from rich import print
|
|
4
6
|
|
|
7
|
+
# Constants
|
|
5
8
|
RELEASE_MAP = {
|
|
6
9
|
'dev': 'Development Build',
|
|
7
10
|
'alpha': 'Alpha Build',
|
|
@@ -10,13 +13,12 @@ RELEASE_MAP = {
|
|
|
10
13
|
'final': 'Final Release Build'
|
|
11
14
|
}
|
|
12
15
|
|
|
13
|
-
|
|
14
16
|
__VERSION__ = {
|
|
15
17
|
'major': 3,
|
|
16
18
|
'minor': 0,
|
|
17
|
-
'patch':
|
|
19
|
+
'patch': 2,
|
|
18
20
|
'release': 'dev',
|
|
19
|
-
'release_num':
|
|
21
|
+
'release_num': 1
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
|
|
@@ -50,24 +52,11 @@ def get_full_version_name():
|
|
|
50
52
|
"""
|
|
51
53
|
ver = parse_version()
|
|
52
54
|
ver = ver.split('-')[0]
|
|
53
|
-
return f'v{ver} {RELEASE_MAP[__VERSION__["release"]]} ({__VERSION__["release_num"]})'
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def get_pypi_info():
|
|
57
|
-
"""
|
|
58
|
-
Gets the latest version information from PyPI.
|
|
59
|
-
|
|
60
|
-
Returns:
|
|
61
|
-
dict: The latest version information.
|
|
62
55
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
""
|
|
66
|
-
|
|
67
|
-
resp = requests.get(url)
|
|
68
|
-
resp.raise_for_status()
|
|
69
|
-
resp = resp.json()
|
|
70
|
-
return resp
|
|
56
|
+
release_type = RELEASE_MAP[__VERSION__["release"]]
|
|
57
|
+
release_num = __VERSION__["release_num"]
|
|
58
|
+
release_str = f" {release_type} {'' if __VERSION__['release'].lower() == 'final' else f'({release_num})'}"
|
|
59
|
+
return f'v{ver}{release_str}'
|
|
71
60
|
|
|
72
61
|
|
|
73
62
|
class PyPiVersionInfo:
|
|
@@ -75,213 +64,177 @@ class PyPiVersionInfo:
|
|
|
75
64
|
A class to represent the version information for this package from PyPi.
|
|
76
65
|
|
|
77
66
|
Attributes:
|
|
78
|
-
latest_stable (
|
|
67
|
+
latest_stable (packaging.version.Version):
|
|
79
68
|
The latest stable version of the package on PyPi.
|
|
80
69
|
|
|
81
|
-
latest_pre_release (
|
|
70
|
+
latest_pre_release (packaging.version.Version):
|
|
82
71
|
The latest pre-release version of the package.
|
|
83
72
|
Since:
|
|
84
73
|
v3.0
|
|
85
74
|
"""
|
|
86
|
-
__url
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
__installed_newer_than_latest = None
|
|
93
|
-
|
|
94
|
-
def __init__(self, include_pre_release_for_update_check=__include_pre_release_for_update_check):
|
|
75
|
+
__url = 'https://pypi.org/pypi/inspy-logger/json'
|
|
76
|
+
__installed = parse_version()
|
|
77
|
+
__checked_for_update = False
|
|
78
|
+
__newer_available_version = None
|
|
79
|
+
|
|
80
|
+
def __init__(self, include_pre_release_for_update_check=False):
|
|
95
81
|
self.__latest_stable = None
|
|
96
82
|
self.__latest_pre_release = None
|
|
97
|
-
|
|
98
83
|
self.__all_versions = None
|
|
99
|
-
|
|
100
84
|
self.include_pre_release_for_update_check = include_pre_release_for_update_check
|
|
101
|
-
|
|
102
85
|
self.__query_versions()
|
|
103
86
|
|
|
104
87
|
@property
|
|
105
88
|
def all_versions(self):
|
|
106
|
-
|
|
89
|
+
if self.__all_versions is None:
|
|
90
|
+
self.__query_versions()
|
|
91
|
+
return sorted([pkg_version.parse(v) for v in self.__all_versions])
|
|
107
92
|
|
|
108
93
|
@property
|
|
109
94
|
def checked_for_update(self):
|
|
110
95
|
return self.__checked_for_update
|
|
111
96
|
|
|
112
97
|
@property
|
|
113
|
-
def
|
|
98
|
+
def installed(self):
|
|
114
99
|
"""
|
|
115
|
-
Gets
|
|
116
|
-
|
|
117
|
-
Returns:
|
|
118
|
-
bool:
|
|
119
|
-
True if pre-release versions should be included, False otherwise.
|
|
120
|
-
|
|
121
|
-
Since:
|
|
122
|
-
v3.0
|
|
123
|
-
|
|
100
|
+
Gets the installed version of the package.
|
|
124
101
|
"""
|
|
125
|
-
return self.
|
|
102
|
+
return pkg_version.parse(self.__installed)
|
|
126
103
|
|
|
127
104
|
@property
|
|
128
105
|
def installed_newer_than_latest(self):
|
|
129
|
-
return self.installed > self.
|
|
130
|
-
|
|
131
|
-
@include_pre_release_for_update_check.setter
|
|
132
|
-
def include_pre_release_for_update_check(self, new):
|
|
133
|
-
if isinstance(new, bool):
|
|
134
|
-
self.__include_pre_release_for_update_check = new
|
|
135
|
-
else:
|
|
136
|
-
raise TypeError(f'Expected bool, received {type(new)}.')
|
|
106
|
+
return self.installed > self.latest
|
|
137
107
|
|
|
138
108
|
@property
|
|
139
|
-
def
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
The installed version of the package.
|
|
146
|
-
|
|
147
|
-
"""
|
|
148
|
-
return pkg_version.parse(self.__installed)
|
|
109
|
+
def latest(self):
|
|
110
|
+
return (
|
|
111
|
+
self.all_versions[-1]
|
|
112
|
+
if self.include_pre_release_for_update_check
|
|
113
|
+
else self.latest_stable
|
|
114
|
+
)
|
|
149
115
|
|
|
150
116
|
@property
|
|
151
117
|
def latest_stable(self):
|
|
152
118
|
"""
|
|
153
119
|
Gets the latest stable version of the package on PyPi.
|
|
154
|
-
|
|
155
|
-
Returns:
|
|
156
|
-
str: The latest stable version of the package on PyPi.
|
|
157
|
-
|
|
158
|
-
Since:
|
|
159
|
-
v3.0
|
|
160
120
|
"""
|
|
161
|
-
if self.__latest_stable is
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return self.__latest_stable
|
|
121
|
+
if self.__latest_stable is None:
|
|
122
|
+
self.__query_versions()
|
|
123
|
+
return pkg_version.parse(self.__latest_stable)
|
|
165
124
|
|
|
166
125
|
@property
|
|
167
126
|
def latest_pre_release(self):
|
|
168
127
|
"""
|
|
169
128
|
Gets the latest pre-release version of the package.
|
|
170
|
-
|
|
171
|
-
Returns:
|
|
172
|
-
str: The latest pre-release version of the package.
|
|
173
|
-
|
|
174
|
-
Since:
|
|
175
|
-
v3.0
|
|
176
129
|
"""
|
|
177
|
-
if self.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
return self.__latest_pre_release
|
|
130
|
+
if self.__all_versions is None:
|
|
131
|
+
self.__query_versions()
|
|
132
|
+
pre_release_versions = [v for v in self.all_versions if v.is_prerelease]
|
|
133
|
+
return pre_release_versions[-1] if pre_release_versions else None
|
|
183
134
|
|
|
184
135
|
@property
|
|
185
|
-
def
|
|
186
|
-
"""
|
|
187
|
-
Gets the number of the latest version available on PyPi.
|
|
136
|
+
def newer_available_version(self):
|
|
188
137
|
|
|
189
|
-
|
|
190
|
-
|
|
138
|
+
if self.__newer_available_version is None:
|
|
139
|
+
self.check_for_update()
|
|
191
140
|
|
|
192
|
-
|
|
193
|
-
v3.0
|
|
194
|
-
"""
|
|
195
|
-
if not self.checked_for_update:
|
|
196
|
-
self.update_available
|
|
197
|
-
return self.__new_version_available_num
|
|
141
|
+
return self.__newer_available_version
|
|
198
142
|
|
|
199
|
-
|
|
200
|
-
def queried(self):
|
|
143
|
+
def __query_versions(self):
|
|
201
144
|
"""
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
Returns:
|
|
205
|
-
bool: True if the versions have been queried, False otherwise.
|
|
206
|
-
|
|
207
|
-
Since:
|
|
208
|
-
v3.0
|
|
145
|
+
Queries the versions from PyPi.
|
|
209
146
|
"""
|
|
210
|
-
|
|
147
|
+
try:
|
|
148
|
+
response = requests.get(self.__url)
|
|
149
|
+
response.raise_for_status()
|
|
150
|
+
data = response.json()
|
|
151
|
+
|
|
152
|
+
self.__all_versions = list(data['releases'].keys())
|
|
153
|
+
self.__latest_stable = data['info']['version']
|
|
154
|
+
except requests.RequestException as e:
|
|
155
|
+
# Handle connection errors, HTTP errors, etc.
|
|
156
|
+
print(f"Error querying PyPi: {e}")
|
|
211
157
|
|
|
212
158
|
@property
|
|
213
159
|
def update_available(self):
|
|
214
160
|
"""
|
|
215
161
|
Checks if an update is available.
|
|
216
|
-
|
|
217
|
-
Returns:
|
|
218
|
-
bool: True if an update is available, False otherwise.
|
|
219
|
-
|
|
220
|
-
Since:
|
|
221
|
-
v3.0
|
|
222
162
|
"""
|
|
223
|
-
if
|
|
224
|
-
|
|
225
|
-
|
|
163
|
+
if self.__newer_available_version is None:
|
|
164
|
+
self.check_for_update()
|
|
165
|
+
return self.__newer_available_version is not None
|
|
226
166
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
self.__compare_latest()
|
|
230
|
-
self.__checked_for_update = True
|
|
167
|
+
def check_for_update(self, include_pre_releases=False):
|
|
168
|
+
latest_version = self.latest_stable
|
|
231
169
|
|
|
232
|
-
if
|
|
233
|
-
|
|
234
|
-
self.__compare_latest()
|
|
170
|
+
if include_pre_releases or self.include_pre_release_for_update_check:
|
|
171
|
+
latest_version = max(latest_version, self.latest_pre_release)
|
|
235
172
|
|
|
236
|
-
|
|
173
|
+
if latest_version > self.installed:
|
|
174
|
+
self.__newer_available_version = latest_version
|
|
237
175
|
|
|
176
|
+
self.__checked_for_update = True
|
|
238
177
|
|
|
178
|
+
return latest_version > self.installed
|
|
239
179
|
|
|
240
|
-
|
|
241
|
-
def __query_versions(self):
|
|
180
|
+
def update(self):
|
|
242
181
|
"""
|
|
243
|
-
|
|
182
|
+
Checks for updates to inspy-logger.
|
|
244
183
|
|
|
245
184
|
Returns:
|
|
246
|
-
|
|
185
|
+
None`
|
|
247
186
|
|
|
248
187
|
Since:
|
|
249
188
|
v3.0
|
|
250
189
|
"""
|
|
251
|
-
if not self.queried:
|
|
252
|
-
resp = requests.get(self.__url)
|
|
253
|
-
resp.raise_for_status()
|
|
254
|
-
#print(resp.status_code)
|
|
255
|
-
resp = resp.json()
|
|
256
190
|
|
|
257
|
-
|
|
258
|
-
#print(self.all_versions)
|
|
191
|
+
local_newer_statement = 'Local version is newer than latest version. This is likely a development build.'
|
|
259
192
|
|
|
260
|
-
|
|
261
|
-
|
|
193
|
+
if not self.installed_newer_than_latest:
|
|
194
|
+
local_newer_statement = ''
|
|
262
195
|
|
|
196
|
+
try:
|
|
197
|
+
if self.update_available:
|
|
198
|
+
print(f'\n\n[bold green]Update Available![/bold green] New version: '
|
|
199
|
+
f'[bold cyan]{self.update_available}[/bold cyan]')
|
|
200
|
+
else:
|
|
201
|
+
print(f'\n\n[bold green]No update available.[/bold green] Current version: '
|
|
202
|
+
f'[bold cyan]{parse_version()}[/bold cyan] {local_newer_statement}')
|
|
263
203
|
|
|
204
|
+
except Exception as e:
|
|
205
|
+
print(f'An error occurred during the update check: {str(e)}')
|
|
264
206
|
|
|
265
|
-
|
|
207
|
+
def print_version_info(self):
|
|
208
|
+
"""
|
|
209
|
+
Print version information in a formatted table.
|
|
266
210
|
|
|
267
|
-
|
|
268
|
-
latest = self.__get_latest()
|
|
211
|
+
This function creates a table using the `Table` class and populates it with version information about the current Python environment. It then prints the table to the console.
|
|
269
212
|
|
|
270
|
-
|
|
271
|
-
self
|
|
213
|
+
Parameters:
|
|
214
|
+
self: The current instance of the class.
|
|
272
215
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
216
|
+
Returns:
|
|
217
|
+
None
|
|
218
|
+
"""
|
|
219
|
+
|
|
220
|
+
# Create a table
|
|
221
|
+
|
|
222
|
+
table = Table(show_header=False, show_lines=True, expand=True, border_style='bright_blue',
|
|
223
|
+
row_styles=['none', 'dim'])
|
|
277
224
|
|
|
278
|
-
|
|
279
|
-
|
|
225
|
+
# Add columns
|
|
226
|
+
table.add_column('Property', style='cyan', width=20)
|
|
227
|
+
table.add_column('Value', justify='center')
|
|
280
228
|
|
|
281
|
-
|
|
282
|
-
|
|
229
|
+
# Add rows
|
|
230
|
+
table.add_row('Version', parse_version(), )
|
|
231
|
+
table.add_row('Full Version Name', get_full_version_name())
|
|
283
232
|
|
|
284
|
-
|
|
233
|
+
if self.update_available:
|
|
234
|
+
table.add_row('Update Available', '[bold green]Yes[/bold green]')
|
|
235
|
+
table.add_row('Latest Version', f'{self.new_version_available_num}')
|
|
285
236
|
|
|
237
|
+
table.add_row('Python Executable Path', sys.executable)
|
|
238
|
+
table.add_row('Python Version', sys.version)
|
|
286
239
|
|
|
287
|
-
|
|
240
|
+
print(table)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
inspy_logger/__about__.py,sha256=aNqZy-kB4huBKO64BnBCuPOmf9kycF9bSQOR219ixgw,438
|
|
2
|
+
inspy_logger/__init__.py,sha256=GPqHTKyRu-vd4U4cYq2QrtYVSL-Ez7dCRCIsVcDiJME,10963
|
|
3
|
+
inspy_logger/errors/__init__.py,sha256=jQNGb7VJAZvvE0X3uglhqWdMb10m_6fuwf3RWQg6Xl0,4239
|
|
4
|
+
inspy_logger/helpers/__init__.py,sha256=x36yutCqSgC7BTjPUFwd8VhFKLtusG7RrWViPO3MS5Q,5888
|
|
5
|
+
inspy_logger/helpers/base_classes.py,sha256=krz9wG-Jgart24JJtFAsI0VyiM_ZtXizEy1r9EBVCRw,5202
|
|
6
|
+
inspy_logger/helpers/debug/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
inspy_logger/helpers/debug/environment.py,sha256=nQEQ6irJyjHmjE3oEMkenz68E_Mk6Ww8N-9htfak5Xs,4938
|
|
8
|
+
inspy_logger/helpers/debug/system/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
inspy_logger/helpers/debug/system/processor/__init__.py,sha256=RKnUKf1M3SmIpMXdzgNAYfqRrWIN5cPAxs3EeLgWAyo,1650
|
|
10
|
+
inspy_logger/helpers/debug/system/winx/__init__.py,sha256=WH1xB0KkWlSojE2jiCsUpr89P7KLldYbam_l3UKpkAU,572
|
|
11
|
+
inspy_logger/helpers/network.py,sha256=CNygWy2FnxNpdoP-VzONxuV5_eT0fwdMezT3RgX6C5k,10631
|
|
12
|
+
inspy_logger/helpers/units.py,sha256=7ymMPF4jlWqC-CSSXBPtoR0LLcBbRkkL9BFIAizx3VU,2175
|
|
13
|
+
inspy_logger/manifest.py,sha256=GpgMGySEHZIT9a0sLDwWJ8MtPuAO4N5ViPH0qtSjvIo,992
|
|
14
|
+
inspy_logger/Scripts/main.py,sha256=DTxLtzOANsuwrVN7EyHcNHxLgCU60e77GdkP_H9RkLA,3124
|
|
15
|
+
inspy_logger/version.py,sha256=aGwqTH1LaMXoDipNCQgmfMcD0ERsrDVZAHigqLhFDQs,7213
|
|
16
|
+
inspy_logger-3.0.2.dev1.dist-info/entry_points.txt,sha256=pLNE_K89FS2os-phFuhhgEql6hrl91Q3kGCuGLv9lqM,68
|
|
17
|
+
inspy_logger-3.0.2.dev1.dist-info/LICENSE.md,sha256=UgnCI50WkvWQoNLgJZ9J-tekn5fzB9ViNadKvQCjys4,885
|
|
18
|
+
inspy_logger-3.0.2.dev1.dist-info/METADATA,sha256=jXxky_UUq1kzNu_PgTVaUHk5t610UFuaiqucs-CFp-0,4241
|
|
19
|
+
inspy_logger-3.0.2.dev1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
20
|
+
inspy_logger-3.0.2.dev1.dist-info/RECORD,,
|
inspy_logger/helpers/cache.py
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from os import makedirs
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
from pickle import dump as pkl_dump
|
|
6
|
-
from pickle import load as pkl_load
|
|
7
|
-
from time import time
|
|
8
|
-
from appdirs import user_cache_dir
|
|
9
|
-
from domain_suffixes.suffixes import Suffixes
|
|
10
|
-
from humanize.time import precisedelta
|
|
11
|
-
|
|
12
|
-
PICKLE_FILEPATH = Path(
|
|
13
|
-
user_cache_dir(
|
|
14
|
-
appname='InspyLogger',
|
|
15
|
-
appauthor='Inspyre-Softworks'
|
|
16
|
-
)
|
|
17
|
-
).joinpath('tld.pkl')
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class TLDCache(object):
|
|
21
|
-
|
|
22
|
-
parent_dir = PICKLE_FILEPATH.parent
|
|
23
|
-
|
|
24
|
-
def __init__(self):
|
|
25
|
-
self.__created_ts = None
|
|
26
|
-
self.__pickle_fp_exists = None
|
|
27
|
-
self.__num_tlds = None
|
|
28
|
-
self.__tlds = None
|
|
29
|
-
self.__data = None
|
|
30
|
-
self.__last_renewal_ts = None
|
|
31
|
-
self.__renewal_hist = None
|
|
32
|
-
|
|
33
|
-
def build(self):
|
|
34
|
-
self.__data = {
|
|
35
|
-
'created_ts': time(),
|
|
36
|
-
'renewal_data': {
|
|
37
|
-
'last_ts': None,
|
|
38
|
-
'history': [],
|
|
39
|
-
},
|
|
40
|
-
'tlds': self.fetch_from_source()
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return self.__data
|
|
44
|
-
|
|
45
|
-
@staticmethod
|
|
46
|
-
def load(self):
|
|
47
|
-
""" Load the pickle file for the cache.
|
|
48
|
-
|
|
49
|
-
Will attempt to load the pickle file into memory from the path indicated by :obj:`PICKLE_FILEPATH`
|
|
50
|
-
|
|
51
|
-
Raises:
|
|
52
|
-
:exception:`FileNotFoundError`: If the pickle file does not exist.
|
|
53
|
-
|
|
54
|
-
"""
|
|
55
|
-
with open(PICKLE_FILEPATH, 'rb') as pfp:
|
|
56
|
-
res = pkl_load(pfp)
|
|
57
|
-
|
|
58
|
-
return res
|
|
59
|
-
|
|
60
|
-
def write(self):
|
|
61
|
-
""" Write the pickle file.
|
|
62
|
-
|
|
63
|
-
Write the contents of the cache to the file-system path indicated by :obj:`PICKLE_FILEPATH`
|
|
64
|
-
|
|
65
|
-
Raises:
|
|
66
|
-
:exception:`PermissionError`: If the pickle file can't be written due to permissions writing the file to storage.
|
|
67
|
-
"""
|
|
68
|
-
|
|
69
|
-
if not self.parent_dir.exists():
|
|
70
|
-
makedirs(self.parent_dir, exist_ok=True)
|
|
71
|
-
|
|
72
|
-
with open(PICKLE_FILEPATH, 'wb') as pfp:
|
|
73
|
-
pkl_dump(self.__data, pfp)
|
|
74
|
-
|
|
75
|
-
@staticmethod
|
|
76
|
-
def fetch_from_source(self):
|
|
77
|
-
""" Fetch the top-level-domain list from the source
|
|
78
|
-
|
|
79
|
-
Returns:
|
|
80
|
-
:class:`list`: A list of all known top-level domain suffixes from the domain-suffixes package.
|
|
81
|
-
"""
|
|
82
|
-
suffixes = Suffixes()
|
|
83
|
-
return suffixes.get_all_tlds()
|
|
84
|
-
|
|
85
|
-
@property
|
|
86
|
-
def contents(self) -> dict:
|
|
87
|
-
if self.__data is None:
|
|
88
|
-
try:
|
|
89
|
-
self.__data = self.load()
|
|
90
|
-
except FileNotFoundError:
|
|
91
|
-
self.__data = self.build()
|
|
92
|
-
self.write()
|
|
93
|
-
|
|
94
|
-
return self.__data
|
|
95
|
-
|
|
96
|
-
@property
|
|
97
|
-
def TLDs(self) -> list:
|
|
98
|
-
""" Returns a list of TLDs (top-level domains) for validating against """
|
|
99
|
-
return self.contents['tlds']
|
|
100
|
-
|
|
101
|
-
@property
|
|
102
|
-
def created_timestamp(self) -> float:
|
|
103
|
-
"""
|
|
104
|
-
An alias for :attr:`created_ts`
|
|
105
|
-
|
|
106
|
-
Returns:
|
|
107
|
-
created_ts (float):
|
|
108
|
-
The time (in seconds since Epoch) when the cache was created.
|
|
109
|
-
|
|
110
|
-
"""
|
|
111
|
-
return self.created_ts
|
|
112
|
-
|
|
113
|
-
@property
|
|
114
|
-
def created_ts(self) -> float:
|
|
115
|
-
"""
|
|
116
|
-
The time (in seconds since Epoch) when the cache was created
|
|
117
|
-
"""
|
|
118
|
-
return self.contents['created_ts']
|
|
119
|
-
|
|
120
|
-
@property
|
|
121
|
-
def age_in_seconds(self) -> float:
|
|
122
|
-
"""
|
|
123
|
-
The number of seconds that have elapsed since creation of the cache.
|
|
124
|
-
"""
|
|
125
|
-
return time() - self.created_ts
|
|
126
|
-
|
|
127
|
-
@property
|
|
128
|
-
def age(self) -> str:
|
|
129
|
-
return precisedelta(self.age_in_seconds)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
"""
|
|
133
|
-
File Change History:
|
|
134
|
-
|
|
135
|
-
11/5/22 - 4:24 AM (target: v2.1.2):
|
|
136
|
-
- Code cleanup
|
|
137
|
-
- Transform from class functions to static methods;
|
|
138
|
-
- `TLDCache.load`
|
|
139
|
-
- `TLDCache.fetch_from_source`
|
|
140
|
-
"""
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
inspy_logger/__about__.py,sha256=OQtsehNzctQ5zCFFMFKaRQSJtQ0GJgY3ex8xO3KdtSc,674
|
|
2
|
-
inspy_logger/__init__.py,sha256=Gw7zILrweTzU1ZfY0CaYYtjqU1gv2ZuEZJ1AynrwiXU,10959
|
|
3
|
-
inspy_logger/errors/__init__.py,sha256=jQNGb7VJAZvvE0X3uglhqWdMb10m_6fuwf3RWQg6Xl0,4239
|
|
4
|
-
inspy_logger/helpers/__init__.py,sha256=x36yutCqSgC7BTjPUFwd8VhFKLtusG7RrWViPO3MS5Q,5888
|
|
5
|
-
inspy_logger/helpers/base_classes.py,sha256=u-IEb6zEixc9G8grWZBGkhmCPiNxUoW9plr0JqFm_1c,4937
|
|
6
|
-
inspy_logger/helpers/cache.py,sha256=VFKvkJv9Uv9OgTg-WS4G4TLPuCC2_dXITQhofqr6v0c,3693
|
|
7
|
-
inspy_logger/helpers/network.py,sha256=B0XFtHGkb0Na-GT9CCx1Civ7VWa6SK2jjskzrxRAIQk,10605
|
|
8
|
-
inspy_logger/manifest.py,sha256=GpgMGySEHZIT9a0sLDwWJ8MtPuAO4N5ViPH0qtSjvIo,992
|
|
9
|
-
inspy_logger/Scripts/main.py,sha256=1f03Z0shNZRUfGcx1VhAq3J4IUpAgYy-zuTMqFeCXrw,2750
|
|
10
|
-
inspy_logger/version.py,sha256=GiABV5MisL5M2sRybN3MMfXTXWVSSDBvALCRB9VZPhY,7414
|
|
11
|
-
inspy_logger-3.0.dev5.dist-info/entry_points.txt,sha256=pLNE_K89FS2os-phFuhhgEql6hrl91Q3kGCuGLv9lqM,68
|
|
12
|
-
inspy_logger-3.0.dev5.dist-info/LICENSE.md,sha256=UgnCI50WkvWQoNLgJZ9J-tekn5fzB9ViNadKvQCjys4,885
|
|
13
|
-
inspy_logger-3.0.dev5.dist-info/METADATA,sha256=ceU64SAtLh6njgGeylm4J0c3duE7xcdwJ1VvHlQEywU,4239
|
|
14
|
-
inspy_logger-3.0.dev5.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
15
|
-
inspy_logger-3.0.dev5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|