xulbux 1.6.8__py3-none-any.whl → 1.6.9__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.
Potentially problematic release.
This version of xulbux might be problematic. Click here for more details.
- xulbux/__init__.py +4 -36
- xulbux/_cli_.py +4 -4
- xulbux/xx_code.py +61 -45
- xulbux/xx_color.py +91 -58
- xulbux/xx_console.py +98 -39
- xulbux/xx_data.py +60 -53
- xulbux/xx_env_path.py +0 -4
- xulbux/xx_file.py +22 -26
- xulbux/xx_format_codes.py +25 -8
- xulbux/xx_json.py +105 -50
- xulbux/xx_path.py +71 -21
- xulbux/xx_regex.py +5 -9
- xulbux/xx_string.py +4 -1
- xulbux/xx_system.py +1 -5
- {xulbux-1.6.8.dist-info → xulbux-1.6.9.dist-info}/METADATA +18 -39
- xulbux-1.6.9.dist-info/RECORD +21 -0
- {xulbux-1.6.8.dist-info → xulbux-1.6.9.dist-info}/WHEEL +1 -1
- xulbux-1.6.8.dist-info/RECORD +0 -21
- {xulbux-1.6.8.dist-info → xulbux-1.6.9.dist-info}/entry_points.txt +0 -0
- {xulbux-1.6.8.dist-info → xulbux-1.6.9.dist-info/licenses}/LICENSE +0 -0
- {xulbux-1.6.8.dist-info → xulbux-1.6.9.dist-info}/top_level.txt +0 -0
xulbux/xx_json.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
from .xx_data import Data
|
|
2
2
|
from .xx_file import File
|
|
3
|
+
from .xx_path import Path
|
|
3
4
|
|
|
5
|
+
from typing import Any
|
|
4
6
|
import json as _json
|
|
5
|
-
import os as _os
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
class Json:
|
|
@@ -15,16 +16,16 @@ class Json:
|
|
|
15
16
|
return_original: bool = False,
|
|
16
17
|
) -> dict | tuple[dict, dict]:
|
|
17
18
|
"""Read JSON files, ignoring comments.\n
|
|
18
|
-
|
|
19
|
+
------------------------------------------------------------------
|
|
19
20
|
If only `comment_start` is found at the beginning of an item,
|
|
20
21
|
the whole item is counted as a comment and therefore ignored.
|
|
21
22
|
If `comment_start` and `comment_end` are found inside an item,
|
|
22
23
|
the the section from `comment_start` to `comment_end` is ignored.
|
|
23
|
-
If `return_original` is
|
|
24
|
+
If `return_original` is true, the original JSON is returned
|
|
24
25
|
additionally. (returns: `[processed_json, original_json]`)"""
|
|
25
26
|
if not json_file.endswith(".json"):
|
|
26
27
|
json_file += ".json"
|
|
27
|
-
file_path =
|
|
28
|
+
file_path = Path.extend_or_make(json_file, prefer_script_dir=True)
|
|
28
29
|
with open(file_path, "r") as f:
|
|
29
30
|
content = f.read()
|
|
30
31
|
try:
|
|
@@ -38,66 +39,120 @@ class Json:
|
|
|
38
39
|
|
|
39
40
|
@staticmethod
|
|
40
41
|
def create(
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
json_file: str,
|
|
43
|
+
data: dict,
|
|
43
44
|
indent: int = 2,
|
|
44
45
|
compactness: int = 1,
|
|
45
46
|
force: bool = False,
|
|
46
47
|
) -> str:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
"""Create a nicely formatted JSON file from a dictionary.\n
|
|
49
|
+
----------------------------------------------------------------------
|
|
50
|
+
The `indent` is the amount of spaces to use for indentation.\n
|
|
51
|
+
The `compactness` can be `0`, `1` or `2` and indicates how compact
|
|
52
|
+
the data should be formatted (see `Data.to_str()`).\n
|
|
53
|
+
The function will throw a `FileExistsError` if a file with the same
|
|
54
|
+
name already exists and a `SameContentFileExistsError` if a file with
|
|
55
|
+
the same name and content already exists.
|
|
56
|
+
To always overwrite the file, set the `force` parameter to `True`."""
|
|
57
|
+
if not json_file.endswith(".json"):
|
|
58
|
+
json_file += ".json"
|
|
59
|
+
file_path = Path.extend_or_make(json_file, prefer_script_dir=True)
|
|
60
|
+
File.create(
|
|
61
|
+
file=file_path,
|
|
62
|
+
content=Data.to_str(data, indent, compactness, as_json=True),
|
|
63
|
+
force=force,
|
|
64
|
+
)
|
|
65
|
+
return file_path
|
|
60
66
|
|
|
61
67
|
@staticmethod
|
|
62
68
|
def update(
|
|
63
69
|
json_file: str,
|
|
64
|
-
update_values: str
|
|
70
|
+
update_values: dict[str, Any],
|
|
65
71
|
comment_start: str = ">>",
|
|
66
72
|
comment_end: str = "<<",
|
|
67
|
-
|
|
73
|
+
path_sep: str = "->",
|
|
68
74
|
) -> None:
|
|
69
|
-
"""
|
|
70
|
-
|
|
71
|
-
The
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
the new value at the end of the path.\n
|
|
75
|
-
In this example:
|
|
75
|
+
"""Update single/multiple values inside JSON files, without needing to know the rest of the data.\n
|
|
76
|
+
----------------------------------------------------------------------------------------------------
|
|
77
|
+
The `update_values` parameter is a dictionary, where the keys are the paths to the data to update,
|
|
78
|
+
and the values are the new values to set.\n
|
|
79
|
+
Example: For this JSON data:
|
|
76
80
|
```python
|
|
77
81
|
{
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
"healthy": {
|
|
83
|
+
"fruit": ["apples", "bananas", "oranges"],
|
|
84
|
+
"vegetables": ["carrots", "broccoli", "celery"]
|
|
85
|
+
}
|
|
82
86
|
}
|
|
83
87
|
```
|
|
84
|
-
...
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
... the `update_values` dictionary could look like this:
|
|
89
|
+
```python
|
|
90
|
+
{
|
|
91
|
+
# CHANGE VALUE "apples" TO "strawberries"
|
|
92
|
+
"healthy->fruit->0": "strawberries",
|
|
93
|
+
# CHANGE VALUE UNDER KEY "vegetables" TO [1, 2, 3]
|
|
94
|
+
"healthy->vegetables": [1, 2, 3]
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
In this example, if you want to change the value of `"apples"`, you can use `healthy->fruit->apples`
|
|
98
|
+
as the value-path. If you don't know that the first list item is `"apples"`, you can use the items
|
|
99
|
+
list index inside the value-path, so `healthy->fruit->0`.\n
|
|
100
|
+
⇾ If the given value-path doesn't exist, it will be created.\n
|
|
101
|
+
-----------------------------------------------------------------------------------------------------
|
|
89
102
|
If only `comment_start` is found at the beginning of an item, the whole item is counted as a comment
|
|
90
|
-
and therefore ignored. If `comment_start` and `comment_end` are found inside an item, the
|
|
91
|
-
from `comment_start` to `comment_end` is ignored."""
|
|
92
|
-
if isinstance(update_values, str):
|
|
93
|
-
update_values = [update_values]
|
|
94
|
-
valid_entries = [(parts[0].strip(), parts[1]) for update_value in update_values
|
|
95
|
-
if len(parts := update_value.split(str(sep[1]).strip())) == 2]
|
|
96
|
-
value_paths, new_values = zip(*valid_entries) if valid_entries else ([], [])
|
|
103
|
+
and therefore completely ignored. If `comment_start` and `comment_end` are found inside an item, the
|
|
104
|
+
section from `comment_start` to `comment_end` is counted as a comment and ignored."""
|
|
97
105
|
processed_data, data = Json.read(json_file, comment_start, comment_end, return_original=True)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
|
|
107
|
+
def create_nested_path(data_obj: dict, path_keys: list[str], value: Any) -> dict:
|
|
108
|
+
current = data_obj
|
|
109
|
+
last_idx = len(path_keys) - 1
|
|
110
|
+
for i, key in enumerate(path_keys):
|
|
111
|
+
if i == last_idx:
|
|
112
|
+
if isinstance(current, dict):
|
|
113
|
+
current[key] = value
|
|
114
|
+
elif isinstance(current, list) and key.isdigit():
|
|
115
|
+
idx = int(key)
|
|
116
|
+
while len(current) <= idx:
|
|
117
|
+
current.append(None)
|
|
118
|
+
current[idx] = value
|
|
119
|
+
else:
|
|
120
|
+
raise TypeError(f"Cannot set key '{key}' on {type(current).__name__}")
|
|
121
|
+
else:
|
|
122
|
+
next_key = path_keys[i + 1]
|
|
123
|
+
if isinstance(current, dict):
|
|
124
|
+
if key not in current:
|
|
125
|
+
current[key] = [] if next_key.isdigit() else {}
|
|
126
|
+
current = current[key]
|
|
127
|
+
elif isinstance(current, list) and key.isdigit():
|
|
128
|
+
idx = int(key)
|
|
129
|
+
while len(current) <= idx:
|
|
130
|
+
current.append(None)
|
|
131
|
+
if current[idx] is None:
|
|
132
|
+
current[idx] = [] if next_key.isdigit() else {}
|
|
133
|
+
current = current[idx]
|
|
134
|
+
else:
|
|
135
|
+
raise TypeError(f"Cannot navigate through {type(current).__name__}")
|
|
136
|
+
return data_obj
|
|
137
|
+
|
|
138
|
+
for value_path, new_value in update_values.items():
|
|
139
|
+
try:
|
|
140
|
+
path_id = Data.get_path_id(
|
|
141
|
+
data=processed_data,
|
|
142
|
+
value_paths=value_path,
|
|
143
|
+
path_sep=path_sep,
|
|
144
|
+
ignore_not_found=True,
|
|
145
|
+
)
|
|
146
|
+
if path_id is not None:
|
|
147
|
+
if 'update' not in locals():
|
|
148
|
+
update = {}
|
|
149
|
+
update[path_id] = new_value
|
|
150
|
+
else:
|
|
151
|
+
keys = value_path.split(path_sep)
|
|
152
|
+
data = create_nested_path(data, keys, new_value)
|
|
153
|
+
except Exception:
|
|
154
|
+
keys = value_path.split(path_sep)
|
|
155
|
+
data = create_nested_path(data, keys, new_value)
|
|
156
|
+
if 'update' in locals() and update:
|
|
157
|
+
data = Data.set_value_by_path_id(data, update)
|
|
158
|
+
Json.create(json_file=json_file, data=data, force=True)
|
xulbux/xx_path.py
CHANGED
|
@@ -6,15 +6,18 @@ import sys as _sys
|
|
|
6
6
|
import os as _os
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
class PathNotFoundError(FileNotFoundError):
|
|
10
|
+
...
|
|
11
|
+
|
|
12
12
|
|
|
13
13
|
class _Cwd:
|
|
14
|
+
|
|
14
15
|
def __get__(self, obj, owner=None):
|
|
15
16
|
return _os.getcwd()
|
|
16
17
|
|
|
18
|
+
|
|
17
19
|
class _ScriptDir:
|
|
20
|
+
|
|
18
21
|
def __get__(self, obj, owner=None):
|
|
19
22
|
if getattr(_sys, "frozen", False):
|
|
20
23
|
base_path = _os.path.dirname(_sys.executable)
|
|
@@ -22,13 +25,11 @@ class _ScriptDir:
|
|
|
22
25
|
main_module = _sys.modules["__main__"]
|
|
23
26
|
if hasattr(main_module, "__file__"):
|
|
24
27
|
base_path = _os.path.dirname(_os.path.abspath(main_module.__file__))
|
|
25
|
-
elif (hasattr(main_module, "__spec__") and main_module.__spec__
|
|
26
|
-
and getattr(main_module.__spec__, "origin", None)):
|
|
28
|
+
elif (hasattr(main_module, "__spec__") and main_module.__spec__ and getattr(main_module.__spec__, "origin", None)):
|
|
27
29
|
base_path = _os.path.dirname(_os.path.abspath(main_module.__spec__.origin))
|
|
28
30
|
else:
|
|
29
31
|
raise RuntimeError("Can only get base directory if accessed from a file.")
|
|
30
32
|
return base_path
|
|
31
|
-
# YAPF: enable
|
|
32
33
|
|
|
33
34
|
|
|
34
35
|
class Path:
|
|
@@ -39,9 +40,26 @@ class Path:
|
|
|
39
40
|
"""The path to the directory of the current script."""
|
|
40
41
|
|
|
41
42
|
@staticmethod
|
|
42
|
-
def extend(
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
def extend(
|
|
44
|
+
rel_path: str,
|
|
45
|
+
search_in: str | list[str] = None,
|
|
46
|
+
raise_error: bool = False,
|
|
47
|
+
use_closest_match: bool = False,
|
|
48
|
+
) -> Optional[str]:
|
|
49
|
+
"""Tries to locate and extend a relative path to an absolute path.\n
|
|
50
|
+
--------------------------------------------------------------------------------
|
|
51
|
+
If the `rel_path` couldn't be located in predefined directories, it will be
|
|
52
|
+
searched in the `search_in` directory/s. If the `rel_path` is still not found,
|
|
53
|
+
it returns `None` or raises a `PathNotFoundError` if `raise_error` is true.\n
|
|
54
|
+
--------------------------------------------------------------------------------
|
|
55
|
+
If `use_closest_match` is true, it is possible to have typos in the `search_in`
|
|
56
|
+
path/s and it will still find the file if it is under one of those paths."""
|
|
57
|
+
if rel_path in (None, ""):
|
|
58
|
+
if raise_error:
|
|
59
|
+
raise PathNotFoundError("Path is empty.")
|
|
60
|
+
return None
|
|
61
|
+
elif _os.path.isabs(rel_path):
|
|
62
|
+
return rel_path
|
|
45
63
|
|
|
46
64
|
def get_closest_match(dir: str, part: str) -> Optional[str]:
|
|
47
65
|
try:
|
|
@@ -56,7 +74,7 @@ class Path:
|
|
|
56
74
|
for part in parts:
|
|
57
75
|
if _os.path.isfile(current):
|
|
58
76
|
return current
|
|
59
|
-
closest_match = get_closest_match(current, part) if
|
|
77
|
+
closest_match = get_closest_match(current, part) if use_closest_match else part
|
|
60
78
|
current = _os.path.join(current, closest_match) if closest_match else None
|
|
61
79
|
if current is None:
|
|
62
80
|
return None
|
|
@@ -71,20 +89,20 @@ class Path:
|
|
|
71
89
|
parts[i] = _os.environ[parts[i].upper()]
|
|
72
90
|
return "".join(parts)
|
|
73
91
|
|
|
74
|
-
|
|
75
|
-
if _os.path.isabs(
|
|
76
|
-
drive, rel_path = _os.path.splitdrive(
|
|
92
|
+
rel_path = _os.path.normpath(expand_env_path(rel_path))
|
|
93
|
+
if _os.path.isabs(rel_path):
|
|
94
|
+
drive, rel_path = _os.path.splitdrive(rel_path)
|
|
77
95
|
rel_path = rel_path.lstrip(_os.sep)
|
|
78
|
-
search_dirs = (drive + _os.sep) if drive else
|
|
96
|
+
search_dirs = [(drive + _os.sep) if drive else _os.sep]
|
|
79
97
|
else:
|
|
80
|
-
rel_path =
|
|
98
|
+
rel_path = rel_path.lstrip(_os.sep)
|
|
81
99
|
base_dir = Path.script_dir
|
|
82
|
-
search_dirs =
|
|
100
|
+
search_dirs = [
|
|
83
101
|
_os.getcwd(),
|
|
84
102
|
base_dir,
|
|
85
103
|
_os.path.expanduser("~"),
|
|
86
104
|
_tempfile.gettempdir(),
|
|
87
|
-
|
|
105
|
+
]
|
|
88
106
|
if search_in:
|
|
89
107
|
search_dirs.extend([search_in] if isinstance(search_in, str) else search_in)
|
|
90
108
|
path_parts = rel_path.split(_os.sep)
|
|
@@ -92,19 +110,51 @@ class Path:
|
|
|
92
110
|
full_path = _os.path.join(search_dir, rel_path)
|
|
93
111
|
if _os.path.exists(full_path):
|
|
94
112
|
return full_path
|
|
95
|
-
match = find_path(search_dir, path_parts) if
|
|
113
|
+
match = find_path(search_dir, path_parts) if use_closest_match else None
|
|
96
114
|
if match:
|
|
97
115
|
return match
|
|
98
116
|
if raise_error:
|
|
99
|
-
raise
|
|
100
|
-
return
|
|
117
|
+
raise PathNotFoundError(f"Path '{rel_path}' not found in specified directories.")
|
|
118
|
+
return None
|
|
119
|
+
|
|
120
|
+
@staticmethod
|
|
121
|
+
def extend_or_make(
|
|
122
|
+
rel_path: str,
|
|
123
|
+
search_in: str | list[str] = None,
|
|
124
|
+
prefer_script_dir: bool = True,
|
|
125
|
+
use_closest_match: bool = False,
|
|
126
|
+
) -> str:
|
|
127
|
+
"""Tries to locate and extend a relative path to an absolute path, and if the `rel_path`
|
|
128
|
+
couldn't be located, it generates a path, as if it was located.\n
|
|
129
|
+
-----------------------------------------------------------------------------------------
|
|
130
|
+
If the `rel_path` couldn't be located in predefined directories, it will be searched in
|
|
131
|
+
the `search_in` directory/s. If the `rel_path` is still not found, it will makes a path
|
|
132
|
+
that points to where the `rel_path` would be in the script directory, even though the
|
|
133
|
+
`rel_path` doesn't exist there. If `prefer_script_dir` is false, it will instead make a
|
|
134
|
+
path that points to where the `rel_path` would be in the CWD.\n
|
|
135
|
+
-----------------------------------------------------------------------------------------
|
|
136
|
+
If `use_closest_match` is true, it is possible to have typos in the `search_in` path/s
|
|
137
|
+
and it will still find the file if it is under one of those paths."""
|
|
138
|
+
try:
|
|
139
|
+
return Path.extend(rel_path, search_in, raise_error=True, use_closest_match=use_closest_match)
|
|
140
|
+
except PathNotFoundError:
|
|
141
|
+
normalized_rel_path = _os.path.normpath(rel_path)
|
|
142
|
+
base = Path.script_dir if prefer_script_dir else _os.getcwd()
|
|
143
|
+
return _os.path.join(base, normalized_rel_path)
|
|
101
144
|
|
|
102
145
|
@staticmethod
|
|
103
146
|
def remove(path: str, only_content: bool = False) -> None:
|
|
147
|
+
"""Removes the directory or the directory's content at the specified path.\n
|
|
148
|
+
-----------------------------------------------------------------------------
|
|
149
|
+
Normally it removes the directory and its content, but if `only_content` is
|
|
150
|
+
true, the directory is kept and only its contents are removed."""
|
|
104
151
|
if not _os.path.exists(path):
|
|
105
152
|
return None
|
|
106
153
|
if not only_content:
|
|
107
|
-
|
|
154
|
+
if _os.path.isfile(path) or _os.path.islink(path):
|
|
155
|
+
_os.unlink(path)
|
|
156
|
+
elif _os.path.isdir(path):
|
|
157
|
+
_shutil.rmtree(path)
|
|
108
158
|
elif _os.path.isdir(path):
|
|
109
159
|
for filename in _os.listdir(path):
|
|
110
160
|
file_path = _os.path.join(path, filename)
|
xulbux/xx_regex.py
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Very useful and complicated (generated) regex patterns.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
1
|
import regex as _rx
|
|
6
2
|
import re as _re
|
|
7
3
|
|
|
@@ -93,7 +89,7 @@ class Regex:
|
|
|
93
89
|
- `r` 0-255 (int: red)
|
|
94
90
|
- `g` 0-255 (int: green)
|
|
95
91
|
- `b` 0-255 (int: blue)
|
|
96
|
-
- `a` 0-1 (float: opacity)\n
|
|
92
|
+
- `a` 0.0-1.0 (float: opacity)\n
|
|
97
93
|
----------------------------------------------------------------------------
|
|
98
94
|
If the `fix_sep` is set to nothing, any char that is not a letter or number
|
|
99
95
|
can be used to separate the RGBA values, including just a space."""
|
|
@@ -126,7 +122,7 @@ class Regex:
|
|
|
126
122
|
- `h` 0-360 (int: hue)
|
|
127
123
|
- `s` 0-100 (int: saturation)
|
|
128
124
|
- `l` 0-100 (int: lightness)
|
|
129
|
-
- `a` 0-1 (float: opacity)\n
|
|
125
|
+
- `a` 0.0-1.0 (float: opacity)\n
|
|
130
126
|
----------------------------------------------------------------------------
|
|
131
127
|
If the `fix_sep` is set to nothing, any char that is not a letter or number
|
|
132
128
|
can be used to separate the HSLA values, including just a space."""
|
|
@@ -134,9 +130,9 @@ class Regex:
|
|
|
134
130
|
fix_sep = r"[^0-9A-Z]"
|
|
135
131
|
else:
|
|
136
132
|
fix_sep = _re.escape(fix_sep)
|
|
137
|
-
hsl_part = rf"""((?:0*(?:360|3[0-5][0-9]|[12][0-9][0-9]|[1-9]?[0-9])))
|
|
138
|
-
(?:\s*{fix_sep}\s*)((?:0*(?:100|[1-9][0-9]|[0-9])))
|
|
139
|
-
(?:\s*{fix_sep}\s*)((?:0*(?:100|[1-9][0-9]|[0-9])))"""
|
|
133
|
+
hsl_part = rf"""((?:0*(?:360|3[0-5][0-9]|[12][0-9][0-9]|[1-9]?[0-9]))(?:\s*°)?)
|
|
134
|
+
(?:\s*{fix_sep}\s*)((?:0*(?:100|[1-9][0-9]|[0-9]))(?:\s*%)?)
|
|
135
|
+
(?:\s*{fix_sep}\s*)((?:0*(?:100|[1-9][0-9]|[0-9]))(?:\s*%)?)"""
|
|
140
136
|
return (
|
|
141
137
|
rf"""(?ix)
|
|
142
138
|
(?:hsl|hsla)?\s*(?:\(?\s*{hsl_part}
|
xulbux/xx_string.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from typing import Any
|
|
1
2
|
import json as _json
|
|
2
3
|
import ast as _ast
|
|
3
4
|
import re as _re
|
|
@@ -6,7 +7,7 @@ import re as _re
|
|
|
6
7
|
class String:
|
|
7
8
|
|
|
8
9
|
@staticmethod
|
|
9
|
-
def to_type(string: str) ->
|
|
10
|
+
def to_type(string: str) -> Any:
|
|
10
11
|
"""Will convert a string to the found type, including complex nested structures."""
|
|
11
12
|
string = string.strip()
|
|
12
13
|
try:
|
|
@@ -102,4 +103,6 @@ class String:
|
|
|
102
103
|
@staticmethod
|
|
103
104
|
def split_count(string: str, count: int) -> list[str]:
|
|
104
105
|
"""Will split the string every `count` characters."""
|
|
106
|
+
if count <= 0:
|
|
107
|
+
raise ValueError("Count must be greater than 0.")
|
|
105
108
|
return [string[i:i + count] for i in range(0, len(string), count)]
|
xulbux/xx_system.py
CHANGED
|
@@ -7,11 +7,8 @@ import sys as _sys
|
|
|
7
7
|
import os as _os
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
# YAPF: disable
|
|
11
|
-
class ProcessNotFoundError(Exception):
|
|
12
|
-
pass
|
|
13
|
-
|
|
14
10
|
class _IsElevated:
|
|
11
|
+
|
|
15
12
|
def __get__(self, obj, owner=None):
|
|
16
13
|
try:
|
|
17
14
|
if _os.name == "nt":
|
|
@@ -21,7 +18,6 @@ class _IsElevated:
|
|
|
21
18
|
except Exception:
|
|
22
19
|
pass
|
|
23
20
|
return False
|
|
24
|
-
# YAPF: enable
|
|
25
21
|
|
|
26
22
|
|
|
27
23
|
class System:
|
|
@@ -1,30 +1,9 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: xulbux
|
|
3
|
-
Version: 1.6.
|
|
3
|
+
Version: 1.6.9
|
|
4
4
|
Summary: A Python library which includes lots of helpful classes, types and functions aiming to make common programming tasks simpler.
|
|
5
5
|
Author-email: XulbuX <xulbux.real@gmail.com>
|
|
6
|
-
License: MIT
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2024 XulbuX
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in all
|
|
18
|
-
copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
-
SOFTWARE.
|
|
27
|
-
|
|
6
|
+
License-Expression: MIT
|
|
28
7
|
Project-URL: Bug Reports, https://github.com/XulbuX/PythonLibraryXulbuX/issues
|
|
29
8
|
Project-URL: Changelog, https://github.com/XulbuX/PythonLibraryXulbuX/blob/main/CHANGELOG.md
|
|
30
9
|
Project-URL: Documentation, https://github.com/XulbuX/PythonLibraryXulbuX/wiki
|
|
@@ -37,7 +16,6 @@ Classifier: Programming Language :: Python :: 3
|
|
|
37
16
|
Classifier: Programming Language :: Python :: 3.10
|
|
38
17
|
Classifier: Programming Language :: Python :: 3.11
|
|
39
18
|
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
41
19
|
Classifier: Operating System :: OS Independent
|
|
42
20
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
43
21
|
Requires-Python: >=3.10.0
|
|
@@ -54,6 +32,7 @@ Requires-Dist: black>=23.7.0; extra == "dev"
|
|
|
54
32
|
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
55
33
|
Requires-Dist: flake8>=6.1.0; extra == "dev"
|
|
56
34
|
Requires-Dist: flake8-pyproject>=1.2.3; extra == "dev"
|
|
35
|
+
Dynamic: license-file
|
|
57
36
|
|
|
58
37
|
# **$\color{#8085FF}\Huge\textsf{XulbuX}$**
|
|
59
38
|
|
|
@@ -102,20 +81,20 @@ from xulbux import rgba, hsla, hexa
|
|
|
102
81
|
|
|
103
82
|
## Modules
|
|
104
83
|
|
|
105
|
-
| Module
|
|
106
|
-
|
|
|
107
|
-
|
|
|
108
|
-
|
|
|
109
|
-
|
|
|
110
|
-
|
|
|
111
|
-
|
|
|
112
|
-
|
|
|
113
|
-
|
|
|
114
|
-
|
|
|
115
|
-
|
|
|
116
|
-
|
|
|
117
|
-
|
|
|
118
|
-
|
|
|
84
|
+
| Module | Short Description |
|
|
85
|
+
| :---------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------- |
|
|
86
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_code) | advanced code-string operations (*changing the indent, finding function calls, ...*) |
|
|
87
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_color) | everything around colors (*converting, blending, searching colors in strings, ...*) |
|
|
88
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_console) | advanced actions related to the console (*pretty logging, advanced inputs, ...*) |
|
|
89
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_data) | advanced operations with data structures (*compare, generate path ID's, pretty print/format, ...*) |
|
|
90
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_env_path) | getting and editing the PATH variable (*get paths, check for paths, add paths, ...*) |
|
|
91
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_file) | advanced working with files (*create files, rename file-extensions, ...*) |
|
|
92
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_format_codes) | easy pretty printing with custom format codes (*print, inputs, custom format codes to ANSI, ...*) |
|
|
93
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_json) | advanced working with json files (*read, create, update, ...*) |
|
|
94
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_path) | advanced path operations (*get paths, smart-extend relative paths, delete paths, ...*) |
|
|
95
|
+
|  | generated regex pattern-templates (*match bracket- and quote pairs, match colors, ...*) |
|
|
96
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_string) | helpful actions when working with strings. (*normalize, escape, decompose, ...*) |
|
|
97
|
+
|  | advanced system actions (*restart with message, check installed Python libs, ...*) |
|
|
119
98
|
|
|
120
99
|
<br>
|
|
121
100
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
xulbux/__init__.py,sha256=mpAtWO0eumk7FZt6QS1Wvp7KWBsZd8oseSxUPSpAVJk,815
|
|
2
|
+
xulbux/_cli_.py,sha256=SaBlkIx73nfU6r2TbjQVWxOM-R0xTBqOAKtgi2FF-KA,3470
|
|
3
|
+
xulbux/_consts_.py,sha256=b85O5sePS18z7CJgrVw0V7v88PIG9qnQ7G2bJL71odk,6287
|
|
4
|
+
xulbux/xx_code.py,sha256=laA8osWgIW-QSv6P6Am_c6NocOPf8ZSm20EaVfgOC58,6100
|
|
5
|
+
xulbux/xx_color.py,sha256=NdNh-J89PXPhVcdgKBXThbRTnq1UpBg3yn4aG0fmRAE,47602
|
|
6
|
+
xulbux/xx_console.py,sha256=MJOE3giA6wZW0-VjJmBZaHqnUhOA6vRF41UdkAPIxgk,28019
|
|
7
|
+
xulbux/xx_data.py,sha256=zp-DjMJ_VnC-BQQlqdzdgwhnSRzs0MV356AbIjeGgP4,30696
|
|
8
|
+
xulbux/xx_env_path.py,sha256=A54TObZZwDvNZwv0iwHzEbNiCoEvz16OId-gMiUTHdo,4086
|
|
9
|
+
xulbux/xx_file.py,sha256=Efd7-1FFsXYGd_cH95FwI8Mg6PaA7H11ArBpdBhyVhE,2597
|
|
10
|
+
xulbux/xx_format_codes.py,sha256=QXb7ik_JyZJ6agtWykTerkb6NAPhOtOFh7nMpr-bpWo,22912
|
|
11
|
+
xulbux/xx_json.py,sha256=-Wzlg8pUIsLlYJKrlxeoXoPprPn8lGJ2Uqc36WYyk6U,7390
|
|
12
|
+
xulbux/xx_path.py,sha256=ZCnRJyIO5nigaKJjxNjfEz_4Z_mhBS0ELyJaLU7Lid0,7561
|
|
13
|
+
xulbux/xx_regex.py,sha256=oJ7V2ccQNYbnavvCEIyYGVM8001_pjMV1BRu3NGmMJw,7884
|
|
14
|
+
xulbux/xx_string.py,sha256=QaTo0TQ9m_2USNgQNaVw5ivQt-A1E-e5x8OpIB3xIlY,5561
|
|
15
|
+
xulbux/xx_system.py,sha256=vHuNzxG6fakd4pJ0esJNfGglUtRbqpGJhPODVJqwcV0,6411
|
|
16
|
+
xulbux-1.6.9.dist-info/licenses/LICENSE,sha256=6NflEcvzFEe8_JFVNCPVwZBwBhlLLd4vqQi8WiX_Xk4,1084
|
|
17
|
+
xulbux-1.6.9.dist-info/METADATA,sha256=1wGLeAPcJPPDMfhB_JsLCM7mphazUEqyVE4HIfoUbHI,9222
|
|
18
|
+
xulbux-1.6.9.dist-info/WHEEL,sha256=ooBFpIzZCPdw3uqIQsOo4qqbA4ZRPxHnOH7peeONza0,91
|
|
19
|
+
xulbux-1.6.9.dist-info/entry_points.txt,sha256=a3womfLIMZKnOFiyy-xnVb4g2qkZsHR5FbKKkljcGns,94
|
|
20
|
+
xulbux-1.6.9.dist-info/top_level.txt,sha256=FkK4EZajwfP36fnlrPaR98OrEvZpvdEOdW1T5zTj6og,7
|
|
21
|
+
xulbux-1.6.9.dist-info/RECORD,,
|
xulbux-1.6.8.dist-info/RECORD
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
xulbux/__init__.py,sha256=UY5nyn_XmeHAhiPtZmNMlc9hQRlNWbQ0uirICuihWzg,1654
|
|
2
|
-
xulbux/_cli_.py,sha256=I1TieHnX60mlRvMaTQnon-VRuf_70dkP7sOU1aHthQY,3470
|
|
3
|
-
xulbux/_consts_.py,sha256=b85O5sePS18z7CJgrVw0V7v88PIG9qnQ7G2bJL71odk,6287
|
|
4
|
-
xulbux/xx_code.py,sha256=GfzpbN-41L_qfzEdkl4PWq9tbCSAlnE2xX3lPtHo1Iw,5275
|
|
5
|
-
xulbux/xx_color.py,sha256=nwcd5_4JIRfZ99JqbCXMl4RWpic_-M361AA5zEa9Nuw,44846
|
|
6
|
-
xulbux/xx_console.py,sha256=2ZHNxwpSoILjHk45QwzJJbtCn3WOVQ9TmkyqPpdU_3w,25860
|
|
7
|
-
xulbux/xx_data.py,sha256=5MIEKDgbRLGkZi9Yd35XhzrWZY09oXyVLGs0BgTTHFA,30219
|
|
8
|
-
xulbux/xx_env_path.py,sha256=WoBYywFsncX-GMvSdvrGmuajXeeuRY2l_-3GuJJXChU,4200
|
|
9
|
-
xulbux/xx_file.py,sha256=Rij2NjxyBlwfFIN_Sc-vDJzzsn3jzgIigFQ_p6Zg80o,3246
|
|
10
|
-
xulbux/xx_format_codes.py,sha256=5Q5RAVfL-EmhqjJMQ4wMm0MQ3r0okjNKrpdsXeodupI,22313
|
|
11
|
-
xulbux/xx_json.py,sha256=dw2AiqMErdjW0ot4pICDBdTL6j03IrYJWJz-Lw21d4Q,5149
|
|
12
|
-
xulbux/xx_path.py,sha256=trDke1N9ewbkQmAIqjeB9gfbTuAlzqFY2mtPtlK2Ks0,4639
|
|
13
|
-
xulbux/xx_regex.py,sha256=rmy6stkVP-vm8j7QoIn0Z4ic_fMT9p_hs0QE6PkMcr0,7917
|
|
14
|
-
xulbux/xx_string.py,sha256=nJBXAVNknhTE9N_4yOyCVwSSIwOyHCRlZe_D7LOgrOY,5450
|
|
15
|
-
xulbux/xx_system.py,sha256=4WuItIeVF5cU3u3-cu3XqhtxBcap9YDJiQKTZuWsUyM,6494
|
|
16
|
-
xulbux-1.6.8.dist-info/LICENSE,sha256=6NflEcvzFEe8_JFVNCPVwZBwBhlLLd4vqQi8WiX_Xk4,1084
|
|
17
|
-
xulbux-1.6.8.dist-info/METADATA,sha256=D0zdyVryi5SUH7ylNmFbi5qa1dgbPt7zdn08LkgqFOQ,9673
|
|
18
|
-
xulbux-1.6.8.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
|
|
19
|
-
xulbux-1.6.8.dist-info/entry_points.txt,sha256=a3womfLIMZKnOFiyy-xnVb4g2qkZsHR5FbKKkljcGns,94
|
|
20
|
-
xulbux-1.6.8.dist-info/top_level.txt,sha256=FkK4EZajwfP36fnlrPaR98OrEvZpvdEOdW1T5zTj6og,7
|
|
21
|
-
xulbux-1.6.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|