absfuyu 5.2.0__py3-none-any.whl → 5.4.0__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 absfuyu might be problematic. Click here for more details.
- absfuyu/__init__.py +1 -1
- absfuyu/__main__.py +2 -2
- absfuyu/cli/__init__.py +2 -2
- absfuyu/cli/color.py +2 -2
- absfuyu/cli/config_group.py +2 -2
- absfuyu/cli/do_group.py +12 -2
- absfuyu/cli/game_group.py +2 -2
- absfuyu/cli/tool_group.py +2 -2
- absfuyu/config/__init__.py +2 -2
- absfuyu/core/__init__.py +2 -2
- absfuyu/core/baseclass.py +32 -2
- absfuyu/core/baseclass2.py +2 -2
- absfuyu/core/decorator.py +2 -2
- absfuyu/core/docstring.py +2 -2
- absfuyu/core/dummy_cli.py +2 -2
- absfuyu/core/dummy_func.py +2 -2
- absfuyu/dxt/__init__.py +2 -2
- absfuyu/dxt/dictext.py +15 -6
- absfuyu/dxt/dxt_support.py +2 -2
- absfuyu/dxt/intext.py +51 -33
- absfuyu/dxt/listext.py +138 -10
- absfuyu/dxt/strext.py +2 -2
- absfuyu/extra/__init__.py +2 -2
- absfuyu/extra/beautiful.py +2 -2
- absfuyu/extra/da/__init__.py +2 -2
- absfuyu/extra/da/dadf.py +57 -41
- absfuyu/extra/da/dadf_base.py +2 -2
- absfuyu/extra/da/df_func.py +2 -2
- absfuyu/extra/da/mplt.py +2 -2
- absfuyu/extra/data_analysis.py +2 -2
- absfuyu/fun/__init__.py +7 -2
- absfuyu/fun/rubik.py +442 -0
- absfuyu/fun/tarot.py +2 -2
- absfuyu/game/__init__.py +2 -2
- absfuyu/game/game_stat.py +2 -2
- absfuyu/game/sudoku.py +2 -2
- absfuyu/game/tictactoe.py +2 -2
- absfuyu/game/wordle.py +2 -2
- absfuyu/general/__init__.py +2 -2
- absfuyu/general/content.py +2 -2
- absfuyu/general/human.py +2 -2
- absfuyu/general/shape.py +2 -2
- absfuyu/logger.py +2 -2
- absfuyu/pkg_data/__init__.py +2 -2
- absfuyu/pkg_data/deprecated.py +2 -2
- absfuyu/sort.py +2 -2
- absfuyu/tools/__init__.py +4 -4
- absfuyu/tools/checksum.py +2 -2
- absfuyu/tools/converter.py +2 -2
- absfuyu/tools/generator.py +2 -2
- absfuyu/tools/inspector.py +41 -6
- absfuyu/tools/keygen.py +2 -2
- absfuyu/tools/obfuscator.py +2 -2
- absfuyu/tools/passwordlib.py +2 -2
- absfuyu/tools/shutdownizer.py +2 -2
- absfuyu/tools/web.py +2 -2
- absfuyu/typings.py +7 -2
- absfuyu/util/__init__.py +57 -3
- absfuyu/util/api.py +2 -2
- absfuyu/util/json_method.py +2 -2
- absfuyu/util/lunar.py +2 -2
- absfuyu/util/path.py +158 -4
- absfuyu/util/performance.py +2 -2
- absfuyu/util/shorten_number.py +2 -2
- absfuyu/util/text_table.py +220 -64
- absfuyu/util/zipped.py +2 -2
- absfuyu/version.py +2 -2
- {absfuyu-5.2.0.dist-info → absfuyu-5.4.0.dist-info}/METADATA +1 -1
- absfuyu-5.4.0.dist-info/RECORD +77 -0
- absfuyu-5.2.0.dist-info/RECORD +0 -76
- {absfuyu-5.2.0.dist-info → absfuyu-5.4.0.dist-info}/WHEEL +0 -0
- {absfuyu-5.2.0.dist-info → absfuyu-5.4.0.dist-info}/entry_points.txt +0 -0
- {absfuyu-5.2.0.dist-info → absfuyu-5.4.0.dist-info}/licenses/LICENSE +0 -0
absfuyu/tools/checksum.py
CHANGED
absfuyu/tools/converter.py
CHANGED
absfuyu/tools/generator.py
CHANGED
absfuyu/tools/inspector.py
CHANGED
|
@@ -3,22 +3,24 @@ Absfuyu: Inspector
|
|
|
3
3
|
------------------
|
|
4
4
|
Inspector
|
|
5
5
|
|
|
6
|
-
Version: 5.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.4.0
|
|
7
|
+
Date updated: 21/03/2025 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Module level
|
|
11
11
|
# ---------------------------------------------------------------------------
|
|
12
12
|
__all__ = ["Inspector", "inspect_all"]
|
|
13
13
|
|
|
14
|
+
|
|
14
15
|
# Library
|
|
15
16
|
# ---------------------------------------------------------------------------
|
|
16
17
|
import inspect as _inspect
|
|
17
18
|
import os
|
|
19
|
+
from collections.abc import Callable
|
|
18
20
|
from functools import partial
|
|
19
21
|
from textwrap import TextWrapper
|
|
20
22
|
from textwrap import shorten as text_shorten
|
|
21
|
-
from typing import Any, Literal, overload
|
|
23
|
+
from typing import Any, Literal, get_overloads, overload
|
|
22
24
|
|
|
23
25
|
from absfuyu.core.baseclass import (
|
|
24
26
|
AutoREPRMixin,
|
|
@@ -26,6 +28,7 @@ from absfuyu.core.baseclass import (
|
|
|
26
28
|
ShowAllMethodsMixin,
|
|
27
29
|
)
|
|
28
30
|
from absfuyu.dxt.listext import ListExt
|
|
31
|
+
from absfuyu.typings import P, R
|
|
29
32
|
from absfuyu.util.text_table import OneColumnTableMaker
|
|
30
33
|
|
|
31
34
|
|
|
@@ -71,6 +74,9 @@ class Inspector(AutoREPRMixin):
|
|
|
71
74
|
Maximum lines for the output's header (class, signature, repr).
|
|
72
75
|
Must be >= 1, by default ``8``
|
|
73
76
|
|
|
77
|
+
style : Literal["normal", "bold", "dashed", "double", "rounded"], optional
|
|
78
|
+
Style for the table, by default ``"normal"``
|
|
79
|
+
|
|
74
80
|
|
|
75
81
|
Example:
|
|
76
82
|
--------
|
|
@@ -96,6 +102,7 @@ class Inspector(AutoREPRMixin):
|
|
|
96
102
|
include_attribute: bool = True,
|
|
97
103
|
include_private: bool = False,
|
|
98
104
|
max_textwrap_lines: int = 8,
|
|
105
|
+
style: Literal["normal", "bold", "dashed", "double", "rounded"] = "normal",
|
|
99
106
|
) -> None: ...
|
|
100
107
|
|
|
101
108
|
def __init__(
|
|
@@ -114,6 +121,8 @@ class Inspector(AutoREPRMixin):
|
|
|
114
121
|
include_attribute: bool = True,
|
|
115
122
|
include_private: bool = False,
|
|
116
123
|
include_all: bool = False,
|
|
124
|
+
# Style
|
|
125
|
+
style: Literal["normal", "bold", "dashed", "double", "rounded"] = "normal",
|
|
117
126
|
) -> None:
|
|
118
127
|
"""
|
|
119
128
|
Inspect an object.
|
|
@@ -153,6 +162,9 @@ class Inspector(AutoREPRMixin):
|
|
|
153
162
|
Maximum lines for the output's header (class, signature, repr).
|
|
154
163
|
Must be >= 1, by default ``8``
|
|
155
164
|
|
|
165
|
+
style : Literal["normal", "bold", "dashed", "double", "rounded"], optional
|
|
166
|
+
Style for the table, by default ``"normal"``
|
|
167
|
+
|
|
156
168
|
|
|
157
169
|
Example:
|
|
158
170
|
--------
|
|
@@ -165,6 +177,7 @@ class Inspector(AutoREPRMixin):
|
|
|
165
177
|
self.include_property = include_property
|
|
166
178
|
self.include_attribute = include_attribute
|
|
167
179
|
self.include_private = include_private
|
|
180
|
+
self._style = style
|
|
168
181
|
|
|
169
182
|
if include_all:
|
|
170
183
|
self.include_docs = True
|
|
@@ -203,7 +216,9 @@ class Inspector(AutoREPRMixin):
|
|
|
203
216
|
|
|
204
217
|
# Support
|
|
205
218
|
def _long_list_terminal_size(self, long_list: list) -> list:
|
|
206
|
-
ll = ListExt(long_list).wrap_to_column(
|
|
219
|
+
ll = ListExt(long_list).wrap_to_column(
|
|
220
|
+
self._linelength, margin=4, transpose=True
|
|
221
|
+
)
|
|
207
222
|
return list(ll)
|
|
208
223
|
|
|
209
224
|
# Signature
|
|
@@ -240,12 +255,30 @@ class Inspector(AutoREPRMixin):
|
|
|
240
255
|
return None
|
|
241
256
|
return [str(x) for x in sig.parameters.values()]
|
|
242
257
|
|
|
258
|
+
def _get_func_signature(self, func: Callable[P, R]) -> list[str]:
|
|
259
|
+
overloads = list(get_overloads(func))
|
|
260
|
+
if len(overloads) < 1:
|
|
261
|
+
return [
|
|
262
|
+
f"{self._get_signature_prefix()} {func.__name__}{_inspect.signature(func)}"
|
|
263
|
+
]
|
|
264
|
+
return [
|
|
265
|
+
f"{self._get_signature_prefix()} {x.__name__}{_inspect.signature(x)}"
|
|
266
|
+
for x in overloads
|
|
267
|
+
]
|
|
268
|
+
|
|
243
269
|
def _make_signature(self) -> list[str]:
|
|
244
270
|
"""
|
|
245
271
|
Inspector's workflow:
|
|
246
272
|
02. Make signature
|
|
247
273
|
"""
|
|
248
274
|
try:
|
|
275
|
+
# if isinstance(self.obj, Callable):
|
|
276
|
+
if _inspect.isfunction(self.obj):
|
|
277
|
+
funcs = [
|
|
278
|
+
self._text_wrapper.wrap(x)
|
|
279
|
+
for x in self._get_func_signature(self.obj)
|
|
280
|
+
]
|
|
281
|
+
return ListExt(funcs).flatten()
|
|
249
282
|
return self._text_wrapper.wrap(
|
|
250
283
|
f"{self._get_signature_prefix()} {self.obj.__name__}{_inspect.signature(self.obj)}"
|
|
251
284
|
)
|
|
@@ -392,7 +425,7 @@ class Inspector(AutoREPRMixin):
|
|
|
392
425
|
|
|
393
426
|
# Output
|
|
394
427
|
def _make_output(self) -> OneColumnTableMaker:
|
|
395
|
-
table = OneColumnTableMaker(self._linelength)
|
|
428
|
+
table = OneColumnTableMaker(self._linelength, style=self._style)
|
|
396
429
|
body: list[str] = []
|
|
397
430
|
|
|
398
431
|
# Signature
|
|
@@ -419,7 +452,9 @@ class Inspector(AutoREPRMixin):
|
|
|
419
452
|
|
|
420
453
|
# Method & Property
|
|
421
454
|
try:
|
|
422
|
-
method_n_properties =
|
|
455
|
+
method_n_properties = (
|
|
456
|
+
self._get_method_property().flatten_value().pack().sort()
|
|
457
|
+
)
|
|
423
458
|
if self.include_method:
|
|
424
459
|
ml = [
|
|
425
460
|
text_shorten(f"- {x}", self._linelength - 4)
|
absfuyu/tools/keygen.py
CHANGED
absfuyu/tools/obfuscator.py
CHANGED
absfuyu/tools/passwordlib.py
CHANGED
absfuyu/tools/shutdownizer.py
CHANGED
absfuyu/tools/web.py
CHANGED
absfuyu/typings.py
CHANGED
|
@@ -3,8 +3,8 @@ Absfuyu: Core
|
|
|
3
3
|
-------------
|
|
4
4
|
Pre-defined typing
|
|
5
5
|
|
|
6
|
-
Version: 5.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.4.0
|
|
7
|
+
Date updated: 21/03/2025 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Module Package
|
|
@@ -14,6 +14,8 @@ __all__ = [
|
|
|
14
14
|
"T",
|
|
15
15
|
"T_co",
|
|
16
16
|
"T_contra",
|
|
17
|
+
"KT",
|
|
18
|
+
"VT",
|
|
17
19
|
"P",
|
|
18
20
|
"R",
|
|
19
21
|
"_CALLABLE",
|
|
@@ -48,6 +50,9 @@ T_co = TypeVar("T_co", covariant=True) # Type covariant
|
|
|
48
50
|
# with a more general type without causing errors
|
|
49
51
|
T_contra = TypeVar("T_contra", contravariant=True) # Type contravariant
|
|
50
52
|
|
|
53
|
+
KT = TypeVar("KT")
|
|
54
|
+
VT = TypeVar("VT")
|
|
55
|
+
|
|
51
56
|
# Callable
|
|
52
57
|
P = ParamSpec("P") # Parameter type
|
|
53
58
|
R = TypeVar("R") # Return type - Can be anything
|
absfuyu/util/__init__.py
CHANGED
|
@@ -3,26 +3,33 @@ Absufyu: Utilities
|
|
|
3
3
|
------------------
|
|
4
4
|
Some random utilities
|
|
5
5
|
|
|
6
|
-
Version: 5.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.4.0
|
|
7
|
+
Date updated: 21/03/2025 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Module Package
|
|
11
11
|
# ---------------------------------------------------------------------------
|
|
12
12
|
__all__ = [
|
|
13
|
+
# util
|
|
13
14
|
"get_installed_package",
|
|
14
15
|
"set_min",
|
|
15
16
|
"set_max",
|
|
16
17
|
"set_min_max",
|
|
17
18
|
"stop_after_day",
|
|
19
|
+
"convert_to_raw_unicode",
|
|
20
|
+
# shorten number
|
|
21
|
+
"Decimal",
|
|
18
22
|
]
|
|
19
23
|
|
|
24
|
+
|
|
20
25
|
# Library
|
|
21
26
|
# ---------------------------------------------------------------------------
|
|
22
27
|
import pkgutil
|
|
23
28
|
from datetime import datetime
|
|
29
|
+
from string import printable
|
|
24
30
|
|
|
25
|
-
from absfuyu.core import deprecated, versionadded, versionchanged
|
|
31
|
+
from absfuyu.core.docstring import deprecated, versionadded, versionchanged
|
|
32
|
+
from absfuyu.util.shorten_number import Decimal
|
|
26
33
|
|
|
27
34
|
|
|
28
35
|
# Function
|
|
@@ -192,3 +199,50 @@ def stop_after_day(
|
|
|
192
199
|
result = end_date - now
|
|
193
200
|
if result.days < 0:
|
|
194
201
|
raise SystemExit("End of time")
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
@versionadded("5.4.0")
|
|
205
|
+
def convert_to_raw_unicode(text: str, partial: bool = True) -> str:
|
|
206
|
+
r"""
|
|
207
|
+
Convert text to raw unicode variant.
|
|
208
|
+
|
|
209
|
+
Parameters
|
|
210
|
+
----------
|
|
211
|
+
text : str
|
|
212
|
+
Text to convert
|
|
213
|
+
|
|
214
|
+
partial : bool, optional
|
|
215
|
+
Only convert characters that not in ``string.printable``,
|
|
216
|
+
by default ``True``
|
|
217
|
+
|
|
218
|
+
Returns
|
|
219
|
+
-------
|
|
220
|
+
str
|
|
221
|
+
Converted text.
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
Example:
|
|
225
|
+
--------
|
|
226
|
+
>>> convert_to_raw_unicode("résumé")
|
|
227
|
+
r\u00E9sum\u00E9
|
|
228
|
+
|
|
229
|
+
>>> convert_to_raw_unicode("résumé", partial=False)
|
|
230
|
+
\u0072\u00E9\u0073\u0075\u006D\u00E9
|
|
231
|
+
"""
|
|
232
|
+
|
|
233
|
+
character_set = printable
|
|
234
|
+
|
|
235
|
+
def _convert(character: str) -> str:
|
|
236
|
+
"""Get unicode value"""
|
|
237
|
+
# ord(c): Returns the Unicode code point for a one-character string c.
|
|
238
|
+
_ord = ord(character)
|
|
239
|
+
# f"\\u{_ord:04X}": Formats the Unicode code point as a four-digit
|
|
240
|
+
# hexadecimal number for code points less than 0x10000.
|
|
241
|
+
# f"\\U{_ord:08X}": Formats the Unicode code point as an eight-digit
|
|
242
|
+
# hexadecimal number for code points greater than or equal to 0x10000.
|
|
243
|
+
return f"\\u{_ord:04X}" if _ord < 0x10000 else f"\\U{_ord:08X}"
|
|
244
|
+
|
|
245
|
+
return "".join(
|
|
246
|
+
character if character in character_set and partial else _convert(character)
|
|
247
|
+
for character in text
|
|
248
|
+
)
|
absfuyu/util/api.py
CHANGED
absfuyu/util/json_method.py
CHANGED
absfuyu/util/lunar.py
CHANGED
absfuyu/util/path.py
CHANGED
|
@@ -3,8 +3,8 @@ Absfuyu: Path
|
|
|
3
3
|
-------------
|
|
4
4
|
Path related
|
|
5
5
|
|
|
6
|
-
Version: 5.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.4.0
|
|
7
|
+
Date updated: 21/03/2025 (dd/mm/yyyy)
|
|
8
8
|
|
|
9
9
|
Feature:
|
|
10
10
|
--------
|
|
@@ -46,6 +46,128 @@ from absfuyu.core.decorator import add_subclass_methods_decorator
|
|
|
46
46
|
from absfuyu.core.docstring import deprecated, versionadded, versionchanged
|
|
47
47
|
from absfuyu.logger import logger
|
|
48
48
|
|
|
49
|
+
# Template
|
|
50
|
+
# ---------------------------------------------------------------------------
|
|
51
|
+
ORGANIZE_TEMPLATE: dict[str, list[str]] = {
|
|
52
|
+
"Code": [".ps1", ".py", ".rs", ".js", ".c", ".h", ".cpp", ".r", ".cmd", ".bat"],
|
|
53
|
+
"Comic": [".cbz", ".cbr", ".cb7", ".cbt", ".cba"],
|
|
54
|
+
"Compressed": [
|
|
55
|
+
".7z",
|
|
56
|
+
".zip",
|
|
57
|
+
".rar",
|
|
58
|
+
".apk",
|
|
59
|
+
".cab",
|
|
60
|
+
".tar",
|
|
61
|
+
".tgz",
|
|
62
|
+
".txz",
|
|
63
|
+
".bz2",
|
|
64
|
+
".gz",
|
|
65
|
+
".lz",
|
|
66
|
+
".lz4",
|
|
67
|
+
".lzma",
|
|
68
|
+
".xz",
|
|
69
|
+
".zipx",
|
|
70
|
+
".zst",
|
|
71
|
+
],
|
|
72
|
+
"Documents": [".docx", ".doc", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt"],
|
|
73
|
+
"Ebook": [
|
|
74
|
+
".epub",
|
|
75
|
+
".mobi",
|
|
76
|
+
".prc",
|
|
77
|
+
".lrf",
|
|
78
|
+
".lrx",
|
|
79
|
+
".pdb",
|
|
80
|
+
".azw",
|
|
81
|
+
".azw3",
|
|
82
|
+
".kf8",
|
|
83
|
+
".kfx",
|
|
84
|
+
".opf",
|
|
85
|
+
],
|
|
86
|
+
"Music": [".mp3", ".flac", ".wav", ".m4a", ".wma", ".aac", ".alac", ".aiff"],
|
|
87
|
+
"OS": [".iso", ".dmg", ".wim"],
|
|
88
|
+
"Pictures": [
|
|
89
|
+
".jpg",
|
|
90
|
+
".jpeg",
|
|
91
|
+
".png",
|
|
92
|
+
".apng",
|
|
93
|
+
".avif",
|
|
94
|
+
".bmp",
|
|
95
|
+
".gif",
|
|
96
|
+
".jfif",
|
|
97
|
+
".pjpeg",
|
|
98
|
+
".pjp",
|
|
99
|
+
".svg",
|
|
100
|
+
".ico",
|
|
101
|
+
".cur",
|
|
102
|
+
".tif",
|
|
103
|
+
".tiff",
|
|
104
|
+
".webp",
|
|
105
|
+
],
|
|
106
|
+
"Programs": [".exe", ".msi"],
|
|
107
|
+
"Video": [
|
|
108
|
+
".3g2",
|
|
109
|
+
".3gp",
|
|
110
|
+
".avi",
|
|
111
|
+
".flv",
|
|
112
|
+
".m2ts",
|
|
113
|
+
".m4v",
|
|
114
|
+
".mkv",
|
|
115
|
+
".mov",
|
|
116
|
+
".mp4",
|
|
117
|
+
".mpeg",
|
|
118
|
+
".mpv",
|
|
119
|
+
".mts",
|
|
120
|
+
".ts",
|
|
121
|
+
".vob",
|
|
122
|
+
".webm",
|
|
123
|
+
],
|
|
124
|
+
"Raw pictures": [
|
|
125
|
+
".3fr",
|
|
126
|
+
".ari",
|
|
127
|
+
".arw",
|
|
128
|
+
".bay",
|
|
129
|
+
".braw",
|
|
130
|
+
".crw",
|
|
131
|
+
".cr2",
|
|
132
|
+
".cr3",
|
|
133
|
+
".cap",
|
|
134
|
+
".data",
|
|
135
|
+
".dcs",
|
|
136
|
+
".dcr",
|
|
137
|
+
".dng",
|
|
138
|
+
".drf",
|
|
139
|
+
".eip",
|
|
140
|
+
".erf",
|
|
141
|
+
".fff",
|
|
142
|
+
".gpr",
|
|
143
|
+
".iiq",
|
|
144
|
+
".k25",
|
|
145
|
+
".kdc",
|
|
146
|
+
".mdc",
|
|
147
|
+
".mef",
|
|
148
|
+
".mos",
|
|
149
|
+
".mrw",
|
|
150
|
+
".nef",
|
|
151
|
+
".nrw",
|
|
152
|
+
".obm",
|
|
153
|
+
".orf",
|
|
154
|
+
".pef",
|
|
155
|
+
".ptx",
|
|
156
|
+
".pxn",
|
|
157
|
+
".r3d",
|
|
158
|
+
".raf",
|
|
159
|
+
".raw",
|
|
160
|
+
".rwl",
|
|
161
|
+
".rw2",
|
|
162
|
+
".rwz",
|
|
163
|
+
".sr2",
|
|
164
|
+
".srf",
|
|
165
|
+
".srw",
|
|
166
|
+
".tif",
|
|
167
|
+
".x3f",
|
|
168
|
+
],
|
|
169
|
+
}
|
|
170
|
+
|
|
49
171
|
|
|
50
172
|
# Support Class
|
|
51
173
|
# ---------------------------------------------------------------------------
|
|
@@ -444,10 +566,42 @@ class DirectoryArchiverMixin(DirectoryBase):
|
|
|
444
566
|
|
|
445
567
|
class DirectoryOrganizerMixin(DirectoryBase):
|
|
446
568
|
"""
|
|
447
|
-
Directory - File organizer
|
|
569
|
+
Directory - File organizer
|
|
570
|
+
|
|
571
|
+
- Organize
|
|
448
572
|
"""
|
|
449
573
|
|
|
450
|
-
|
|
574
|
+
@versionadded("5.3.0")
|
|
575
|
+
def organize(self, dirtemplate: dict[str, list[str]] | None = None) -> None:
|
|
576
|
+
"""
|
|
577
|
+
Organize a directory.
|
|
578
|
+
|
|
579
|
+
Parameters
|
|
580
|
+
----------
|
|
581
|
+
dirtemplate : dict[str, Collection[str]] | None, optional
|
|
582
|
+
| Template to move file to, by default ``None``.
|
|
583
|
+
| Example: {"Documents": [".txt", ".pdf", ...]}
|
|
584
|
+
"""
|
|
585
|
+
if dirtemplate is None:
|
|
586
|
+
template = ORGANIZE_TEMPLATE
|
|
587
|
+
else:
|
|
588
|
+
template = dirtemplate
|
|
589
|
+
|
|
590
|
+
other_dir = self.source_path.joinpath("Others")
|
|
591
|
+
other_dir.mkdir(parents=True, exist_ok=True)
|
|
592
|
+
|
|
593
|
+
for path in self.source_path.iterdir():
|
|
594
|
+
if path.is_dir():
|
|
595
|
+
continue
|
|
596
|
+
|
|
597
|
+
for dir_name, suffixes in template.items():
|
|
598
|
+
if path.suffix.lower() in suffixes:
|
|
599
|
+
move_path = self.source_path.joinpath(dir_name)
|
|
600
|
+
move_path.mkdir(parents=True, exist_ok=True)
|
|
601
|
+
path.rename(move_path.joinpath(path.name))
|
|
602
|
+
break
|
|
603
|
+
else:
|
|
604
|
+
path.rename(other_dir.joinpath(path.name))
|
|
451
605
|
|
|
452
606
|
|
|
453
607
|
class DirectoryTreeMixin(DirectoryBase):
|
absfuyu/util/performance.py
CHANGED