kopitools 1.0.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.
kopitools/__init__.py ADDED
@@ -0,0 +1,10 @@
1
+ from kopitools.logs import (
2
+ log, Log
3
+ )
4
+ from kopitools.paint import (
5
+ paint, Paint
6
+ )
7
+ from kopitools.args import (
8
+ Registry, Option, Args,
9
+ ArgError, EntryPointNotFoundError,
10
+ )
@@ -0,0 +1,3 @@
1
+ from kopitools.args.registry import Registry, Args
2
+ from kopitools.args.option import Option
3
+ from kopitools.args.exceptions import ArgError, EntryPointNotFoundError
@@ -0,0 +1,5 @@
1
+ class ArgError(Exception):
2
+ pass
3
+
4
+ class EntryPointNotFoundError(Exception):
5
+ pass
@@ -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,3 @@
1
+ from kopitools.logs.logs import (
2
+ Log, log
3
+ )
kopitools/logs/logs.py ADDED
@@ -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,3 @@
1
+ from kopitools.paint.paint import (
2
+ Paint, paint
3
+ )
@@ -0,0 +1,88 @@
1
+ from typing import Any
2
+
3
+ class Paint:
4
+ def __init__(
5
+ self,
6
+ parsed_string: str,
7
+ end: str,
8
+ flush: bool,
9
+ ):
10
+ self.parsed_string = parsed_string
11
+ self.end = end
12
+ self.codes = []
13
+ self.flush = flush
14
+
15
+ self.BLACK = "\033[30m"
16
+ self.RED = "\033[31m"
17
+ self.GREEN = "\033[32m"
18
+ self.YELLOW = "\033[33m"
19
+ self.BLUE = "\033[34m"
20
+ self.MAGENTA = "\033[35m"
21
+ self.CYAN = "\033[36m"
22
+ self.WHITE = "\033[37m"
23
+
24
+ self.BOLD = "\033[1m"
25
+ self.ITALIC = "\033[3m"
26
+ self.UNDERLINE = "\033[4m"
27
+
28
+ self.RESET = "\033[0m"
29
+
30
+ def show(self):
31
+ print(self, end=self.end, flush=True)
32
+
33
+ def black(self):
34
+ self.codes.append(self.BLACK)
35
+ return self
36
+
37
+ def red(self):
38
+ self.codes.append(self.RED)
39
+ return self
40
+
41
+ def green(self):
42
+ self.codes.append(self.GREEN)
43
+ return self
44
+
45
+ def yellow(self):
46
+ self.codes.append(self.YELLOW)
47
+ return self
48
+
49
+ def blue(self):
50
+ self.codes.append(self.BLUE)
51
+ return self
52
+
53
+ def magenta(self):
54
+ self.codes.append(self.MAGENTA)
55
+ return self
56
+
57
+ def cyan(self):
58
+ self.codes.append(self.CYAN)
59
+ return self
60
+
61
+ def white(self):
62
+ self.codes.append(self.WHITE)
63
+ return self
64
+
65
+ def bold(self):
66
+ self.codes.append(self.BOLD)
67
+ return self
68
+
69
+ def underline(self):
70
+ self.codes.append(self.UNDERLINE)
71
+ return self
72
+
73
+ def italic(self):
74
+ self.codes.append(self.ITALIC)
75
+ return self
76
+
77
+ def __str__(self) -> str:
78
+ self.codes.extend([self.parsed_string, self.RESET])
79
+ return "".join(self.codes)
80
+
81
+ def paint(
82
+ *args: Any,
83
+ sep: str = " ",
84
+ end: str = "\n",
85
+ flush: bool = False,
86
+ ) -> Paint:
87
+ parsed_string = sep.join([str(arg) for arg in args])
88
+ return Paint(parsed_string, end, flush)
@@ -0,0 +1,5 @@
1
+ Metadata-Version: 2.5
2
+ Name: kopitools
3
+ Version: 1.0.0
4
+ Summary: Logs, painted strings, system arguments...
5
+ Requires-Python: >=3.9
@@ -0,0 +1,12 @@
1
+ kopitools/__init__.py,sha256=_r8exNX21kB4rjMSyQEUF0vlMLwVKoYTAeKJ-gwDhh4,191
2
+ kopitools/args/__init__.py,sha256=D6is6KRejlaw3lQAwOLX1lyXKiJD84Bz_W7WAEyeDtM,164
3
+ kopitools/args/exceptions.py,sha256=yAY-jJDZDVjIJs1IFLPPrdtI_GbtI1NMxJMH8gKlcrM,88
4
+ kopitools/args/option.py,sha256=pqT8x2WhB8Sqfk0RV4DDOQd0RQrcZMWCrq1TSG2-xRQ,958
5
+ kopitools/args/registry.py,sha256=BF5kW29DjVwr5RjKIDdZzXi383nuFni9E3Bd3eR297E,1090
6
+ kopitools/logs/__init__.py,sha256=vuxBTm-H1ZEPtVNMDCEKElqNFoOLViyO3oIgbCRNZyo,49
7
+ kopitools/logs/logs.py,sha256=0CV7VUI17qLC0AVRfR5p9ANsztIfTy1KjL4PwSjD390,2126
8
+ kopitools/paint/__init__.py,sha256=7g4JB1I2Lb0_SUqn-gTaxYLIPrAOya0C0J1PJMRPnKE,55
9
+ kopitools/paint/paint.py,sha256=Ox0ta6UCUFdQL6IE7jXbOc6uwvY_pL30Nf5G02RkRhU,1977
10
+ kopitools-1.0.0.dist-info/METADATA,sha256=n-gHuhNmbdGgm3TqIgFzvFehP-FgL7OHZoDKELNXlNQ,128
11
+ kopitools-1.0.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
12
+ kopitools-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any