kopitools 0.2.2__tar.gz → 2.1.0__tar.gz
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 kopitools might be problematic. Click here for more details.
- kopitools-2.1.0/PKG-INFO +5 -0
- kopitools-2.1.0/pyproject.toml +17 -0
- kopitools-2.1.0/src/kopitools/__init__.py +10 -0
- kopitools-2.1.0/src/kopitools/args/__init__.py +3 -0
- kopitools-2.1.0/src/kopitools/args/exceptions.py +5 -0
- kopitools-2.1.0/src/kopitools/args/option.py +37 -0
- kopitools-2.1.0/src/kopitools/args/registry.py +40 -0
- kopitools-2.1.0/src/kopitools/logs/__init__.py +3 -0
- kopitools-2.1.0/src/kopitools/logs/logs.py +103 -0
- kopitools-2.1.0/src/kopitools/paint/__init__.py +3 -0
- kopitools-2.1.0/src/kopitools/paint/paint.py +85 -0
- kopitools-2.1.0/tests/tests.py +4 -0
- kopitools-0.2.2/PKG-INFO +0 -5
- kopitools-0.2.2/pyproject.toml +0 -9
- kopitools-0.2.2/setup.cfg +0 -4
- kopitools-0.2.2/src/kopitools/__init__.py +0 -0
- kopitools-0.2.2/src/kopitools/colors/__init__.py +0 -1
- kopitools-0.2.2/src/kopitools/colors/paint.py +0 -74
- kopitools-0.2.2/src/kopitools/utils/__init__.py +0 -1
- kopitools-0.2.2/src/kopitools/utils/clear.py +0 -6
- kopitools-0.2.2/src/kopitools.egg-info/PKG-INFO +0 -5
- kopitools-0.2.2/src/kopitools.egg-info/SOURCES.txt +0 -12
- kopitools-0.2.2/src/kopitools.egg-info/dependency_links.txt +0 -1
- kopitools-0.2.2/src/kopitools.egg-info/top_level.txt +0 -1
- kopitools-0.2.2/tests/test.py +0 -11
- {kopitools-0.2.2 → kopitools-2.1.0}/README.md +0 -0
kopitools-2.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = [
|
|
3
|
+
"hatchling >= 1.26",
|
|
4
|
+
]
|
|
5
|
+
build-backend = "hatchling.build"
|
|
6
|
+
|
|
7
|
+
[project]
|
|
8
|
+
name = "kopitools"
|
|
9
|
+
version = "2.1.0"
|
|
10
|
+
description = "Logs, painted strings, system arguments..."
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
dependencies = []
|
|
14
|
+
|
|
15
|
+
[tool.kuvy.run]
|
|
16
|
+
main = "src/kopilogs/main.py"
|
|
17
|
+
tests = "tests/tests.py"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from kopitools.args.exceptions import ArgError
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
class Option:
|
|
5
|
+
def __init__(
|
|
6
|
+
self,
|
|
7
|
+
name: str,
|
|
8
|
+
receives: Any,
|
|
9
|
+
default: Any,
|
|
10
|
+
attribute: str,
|
|
11
|
+
):
|
|
12
|
+
self.name = name
|
|
13
|
+
self.receives = receives
|
|
14
|
+
self.default = default
|
|
15
|
+
self.attribute = attribute
|
|
16
|
+
|
|
17
|
+
def get(self, remaining: list[str]) -> Any:
|
|
18
|
+
try:
|
|
19
|
+
key = remaining.index(self.name)
|
|
20
|
+
except ValueError:
|
|
21
|
+
return self.default
|
|
22
|
+
|
|
23
|
+
if self.receives is None:
|
|
24
|
+
return not self.default
|
|
25
|
+
|
|
26
|
+
try:
|
|
27
|
+
value = remaining[key + 1]
|
|
28
|
+
except IndexError:
|
|
29
|
+
raise ValueError(f"Missing value for: {self.name}")
|
|
30
|
+
|
|
31
|
+
del remaining[key:key + 2]
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
return self.receives(value)
|
|
35
|
+
except ValueError:
|
|
36
|
+
message = f"[{self.name}] could not convert \"{value}\" to {self.receives}"
|
|
37
|
+
raise ArgError(message)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from kopitools.args.option import Option
|
|
2
|
+
from kopitools.args.exceptions import EntryPointNotFoundError
|
|
3
|
+
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
class Args:
|
|
7
|
+
def __init__(self, args: dict[str, Any]):
|
|
8
|
+
self._args = args
|
|
9
|
+
|
|
10
|
+
def __getitem__(self, key: str) -> Any:
|
|
11
|
+
return self._args.get(key, None)
|
|
12
|
+
|
|
13
|
+
class Registry:
|
|
14
|
+
def __init__(self, argv: list[str], entry_point: None | str = None):
|
|
15
|
+
self.options: list[Option] = []
|
|
16
|
+
self.argv = argv
|
|
17
|
+
|
|
18
|
+
if entry_point is not None:
|
|
19
|
+
if entry_point not in self.argv:
|
|
20
|
+
message = f"Entry point: [{entry_point}] not in \"args\"!"
|
|
21
|
+
raise EntryPointNotFoundError(message)
|
|
22
|
+
|
|
23
|
+
def option(
|
|
24
|
+
self,
|
|
25
|
+
name: str,
|
|
26
|
+
receives: Any,
|
|
27
|
+
default: Any,
|
|
28
|
+
attribute: str,
|
|
29
|
+
):
|
|
30
|
+
self.options.append(Option(name, receives, default, attribute))
|
|
31
|
+
|
|
32
|
+
def collect(self) -> Args:
|
|
33
|
+
remaining = self.argv.copy()
|
|
34
|
+
args = {}
|
|
35
|
+
|
|
36
|
+
for opt in self.options:
|
|
37
|
+
value = opt.get(remaining)
|
|
38
|
+
args[opt.attribute] = value
|
|
39
|
+
|
|
40
|
+
return Args(args)
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
from kopitools.paint import paint
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
class Log:
|
|
6
|
+
icons = True
|
|
7
|
+
text = False
|
|
8
|
+
|
|
9
|
+
def __init__(self, args: tuple[Any]):
|
|
10
|
+
self.args = args
|
|
11
|
+
|
|
12
|
+
def success(self):
|
|
13
|
+
icon = "SUCCESS" if Log.text else "&"
|
|
14
|
+
|
|
15
|
+
flag = paint(
|
|
16
|
+
paint("[").bold(),
|
|
17
|
+
paint(icon).bold().green(),
|
|
18
|
+
paint("]").bold(),
|
|
19
|
+
sep=""
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
paint(
|
|
23
|
+
paint(flag).bold(),
|
|
24
|
+
paint(*self.args)
|
|
25
|
+
).show()
|
|
26
|
+
|
|
27
|
+
def error(self):
|
|
28
|
+
icon = "ERROR" if Log.text else "X"
|
|
29
|
+
|
|
30
|
+
flag = paint(
|
|
31
|
+
paint("[").bold(),
|
|
32
|
+
paint(icon).bold().red(),
|
|
33
|
+
paint("]").bold(),
|
|
34
|
+
sep=""
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
paint(
|
|
38
|
+
paint(flag).bold(),
|
|
39
|
+
paint(*self.args)
|
|
40
|
+
).show()
|
|
41
|
+
|
|
42
|
+
def warning(self):
|
|
43
|
+
icon = "WARNING" if Log.text else "!"
|
|
44
|
+
|
|
45
|
+
flag = paint(
|
|
46
|
+
paint("[").bold(),
|
|
47
|
+
paint(icon).bold().yellow(),
|
|
48
|
+
paint("]").bold(),
|
|
49
|
+
sep=""
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
paint(
|
|
53
|
+
paint(flag).bold(),
|
|
54
|
+
paint(*self.args)
|
|
55
|
+
).show()
|
|
56
|
+
|
|
57
|
+
def critical(self):
|
|
58
|
+
icon = "CRITICAL" if Log.text else "#"
|
|
59
|
+
|
|
60
|
+
flag = paint(
|
|
61
|
+
paint("[").bold(),
|
|
62
|
+
paint(icon).bold().red(),
|
|
63
|
+
paint("]").bold(),
|
|
64
|
+
sep=""
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
paint(
|
|
68
|
+
paint(flag).bold(),
|
|
69
|
+
paint(*self.args)
|
|
70
|
+
).show()
|
|
71
|
+
|
|
72
|
+
def unknown(self):
|
|
73
|
+
icon = "UNKNOWN" if Log.text else "?"
|
|
74
|
+
|
|
75
|
+
flag = paint(
|
|
76
|
+
paint("[").bold(),
|
|
77
|
+
paint(icon).bold().magenta(),
|
|
78
|
+
paint("]").bold(),
|
|
79
|
+
sep=""
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
paint(
|
|
83
|
+
paint(flag).bold(),
|
|
84
|
+
paint(*self.args)
|
|
85
|
+
).show()
|
|
86
|
+
|
|
87
|
+
def info(self):
|
|
88
|
+
icon = "INFO" if Log.text else "^"
|
|
89
|
+
|
|
90
|
+
flag = paint(
|
|
91
|
+
paint("[").bold(),
|
|
92
|
+
paint(icon).bold().blue(),
|
|
93
|
+
paint("]").bold(),
|
|
94
|
+
sep=""
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
paint(
|
|
98
|
+
paint(flag).bold(),
|
|
99
|
+
paint(*self.args)
|
|
100
|
+
).show()
|
|
101
|
+
|
|
102
|
+
def log(*args: Any) -> Log:
|
|
103
|
+
return Log(args)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
class Paint:
|
|
4
|
+
def __init__(
|
|
5
|
+
self,
|
|
6
|
+
parsed_string: str,
|
|
7
|
+
end: str,
|
|
8
|
+
):
|
|
9
|
+
self.parsed_string = parsed_string
|
|
10
|
+
self.end = end
|
|
11
|
+
self.codes = []
|
|
12
|
+
|
|
13
|
+
self.BLACK = "\033[30m"
|
|
14
|
+
self.RED = "\033[31m"
|
|
15
|
+
self.GREEN = "\033[32m"
|
|
16
|
+
self.YELLOW = "\033[33m"
|
|
17
|
+
self.BLUE = "\033[34m"
|
|
18
|
+
self.MAGENTA = "\033[35m"
|
|
19
|
+
self.CYAN = "\033[36m"
|
|
20
|
+
self.WHITE = "\033[37m"
|
|
21
|
+
|
|
22
|
+
self.BOLD = "\033[1m"
|
|
23
|
+
self.ITALIC = "\033[3m"
|
|
24
|
+
self.UNDERLINE = "\033[4m"
|
|
25
|
+
|
|
26
|
+
self.RESET = "\033[0m"
|
|
27
|
+
|
|
28
|
+
def show(self):
|
|
29
|
+
print(self, end=self.end)
|
|
30
|
+
|
|
31
|
+
def black(self):
|
|
32
|
+
self.codes.append(self.BLACK)
|
|
33
|
+
return self
|
|
34
|
+
|
|
35
|
+
def red(self):
|
|
36
|
+
self.codes.append(self.RED)
|
|
37
|
+
return self
|
|
38
|
+
|
|
39
|
+
def green(self):
|
|
40
|
+
self.codes.append(self.GREEN)
|
|
41
|
+
return self
|
|
42
|
+
|
|
43
|
+
def yellow(self):
|
|
44
|
+
self.codes.append(self.YELLOW)
|
|
45
|
+
return self
|
|
46
|
+
|
|
47
|
+
def blue(self):
|
|
48
|
+
self.codes.append(self.BLUE)
|
|
49
|
+
return self
|
|
50
|
+
|
|
51
|
+
def magenta(self):
|
|
52
|
+
self.codes.append(self.MAGENTA)
|
|
53
|
+
return self
|
|
54
|
+
|
|
55
|
+
def cyan(self):
|
|
56
|
+
self.codes.append(self.CYAN)
|
|
57
|
+
return self
|
|
58
|
+
|
|
59
|
+
def white(self):
|
|
60
|
+
self.codes.append(self.WHITE)
|
|
61
|
+
return self
|
|
62
|
+
|
|
63
|
+
def bold(self):
|
|
64
|
+
self.codes.append(self.BOLD)
|
|
65
|
+
return self
|
|
66
|
+
|
|
67
|
+
def underline(self):
|
|
68
|
+
self.codes.append(self.UNDERLINE)
|
|
69
|
+
return self
|
|
70
|
+
|
|
71
|
+
def italic(self):
|
|
72
|
+
self.codes.append(self.ITALIC)
|
|
73
|
+
return self
|
|
74
|
+
|
|
75
|
+
def __str__(self) -> str:
|
|
76
|
+
self.codes.extend([self.parsed_string, self.RESET])
|
|
77
|
+
return "".join(self.codes)
|
|
78
|
+
|
|
79
|
+
def paint(
|
|
80
|
+
*args: Any,
|
|
81
|
+
sep: str = " ",
|
|
82
|
+
end: str = "\n"
|
|
83
|
+
) -> Paint:
|
|
84
|
+
parsed_string = sep.join([str(arg) for arg in args])
|
|
85
|
+
return Paint(parsed_string, end)
|
kopitools-0.2.2/PKG-INFO
DELETED
kopitools-0.2.2/pyproject.toml
DELETED
kopitools-0.2.2/setup.cfg
DELETED
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .paint import paint
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
3
|
-
class Paint:
|
|
4
|
-
RED = "\033[31m"
|
|
5
|
-
GREEN = "\033[32m"
|
|
6
|
-
YELLOW = "\033[33m"
|
|
7
|
-
BLUE = "\033[34m"
|
|
8
|
-
PURPLE = "\033[35m"
|
|
9
|
-
CYAN = "\033[36m"
|
|
10
|
-
LIGHT_GRAY = "\033[37m"
|
|
11
|
-
|
|
12
|
-
RESET = "\033[0m"
|
|
13
|
-
BOLD = "\033[1m"
|
|
14
|
-
ITALIC = "\033[3m"
|
|
15
|
-
UNDERLINE = "\033[4m"
|
|
16
|
-
|
|
17
|
-
def __init__(self, texts, sep, end):
|
|
18
|
-
self.texts = texts
|
|
19
|
-
self.codes = []
|
|
20
|
-
self.sep = sep
|
|
21
|
-
self.end = end
|
|
22
|
-
|
|
23
|
-
def show(self):
|
|
24
|
-
print(self, end = self.end)
|
|
25
|
-
|
|
26
|
-
def red(self):
|
|
27
|
-
self.codes.append(Paint.RED)
|
|
28
|
-
return self
|
|
29
|
-
|
|
30
|
-
def green(self):
|
|
31
|
-
self.codes.append(Paint.GREEN)
|
|
32
|
-
return self
|
|
33
|
-
|
|
34
|
-
def yellow(self):
|
|
35
|
-
self.codes.append(Paint.YELLOW)
|
|
36
|
-
return self
|
|
37
|
-
|
|
38
|
-
def blue(self):
|
|
39
|
-
self.codes.append(Paint.BLUE)
|
|
40
|
-
return self
|
|
41
|
-
|
|
42
|
-
def purple(self):
|
|
43
|
-
self.codes.append(Paint.PURPLE)
|
|
44
|
-
return self
|
|
45
|
-
|
|
46
|
-
def cyan(self):
|
|
47
|
-
self.codes.append(Paint.CYAN)
|
|
48
|
-
return self
|
|
49
|
-
|
|
50
|
-
def gray(self):
|
|
51
|
-
self.codes.append(Paint.LIGHT_GRAY)
|
|
52
|
-
return self
|
|
53
|
-
|
|
54
|
-
def bold(self):
|
|
55
|
-
self.codes.append(Paint.BOLD)
|
|
56
|
-
return self
|
|
57
|
-
|
|
58
|
-
def italic(self):
|
|
59
|
-
self.codes.append(Paint.ITALIC)
|
|
60
|
-
return self
|
|
61
|
-
|
|
62
|
-
def underline(self):
|
|
63
|
-
self.codes.append(Paint.UNDERLINE)
|
|
64
|
-
return self
|
|
65
|
-
|
|
66
|
-
def __str__(self):
|
|
67
|
-
COLORS = "".join(self.codes)
|
|
68
|
-
STRING = self.sep.join(str(text) for text in self.texts)
|
|
69
|
-
RESET = Paint.RESET
|
|
70
|
-
|
|
71
|
-
return f"{COLORS}{STRING}{RESET}"
|
|
72
|
-
|
|
73
|
-
def paint(*texts: Any, sep = "", end = "\n") -> Paint:
|
|
74
|
-
return Paint(texts, sep, end)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .clear import clear
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
README.md
|
|
2
|
-
pyproject.toml
|
|
3
|
-
src/kopitools/__init__.py
|
|
4
|
-
src/kopitools.egg-info/PKG-INFO
|
|
5
|
-
src/kopitools.egg-info/SOURCES.txt
|
|
6
|
-
src/kopitools.egg-info/dependency_links.txt
|
|
7
|
-
src/kopitools.egg-info/top_level.txt
|
|
8
|
-
src/kopitools/colors/__init__.py
|
|
9
|
-
src/kopitools/colors/paint.py
|
|
10
|
-
src/kopitools/utils/__init__.py
|
|
11
|
-
src/kopitools/utils/clear.py
|
|
12
|
-
tests/test.py
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
kopitools
|
kopitools-0.2.2/tests/test.py
DELETED
|
File without changes
|