Skip to content

Commit 40cd2f2

Browse files
authored
Merge pull request #3 from Tracks12:dev
Final version of builder tool & libs optimizations process
2 parents ef905fb + d95c239 commit 40cd2f2

19 files changed

+3826
-117
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
/WSLBuilder/
2-
__pycache__/
1+
.vscode/
32

3+
__pycache__/
44
*.pyc
5+
6+
/libs/wslbuilder
7+
/WSLBuilder/
58
*.vhdx

core/__init__.py

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
#!/bin/python3
1+
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4+
r""" Package initialization for `core`.
5+
6+
This module initializes the `core` package by defining essential functions and variables,
7+
such as `get_config()` for loading configurations and `initialize_logger()` for setting up logging.
8+
It ensures that the core components are ready for use when the package is imported.
9+
10+
Constants:
11+
- INFO: Contains application information such as version, git commit hash, and other metadata.
12+
- REGEX_ARGS: A regular expression pattern used to parse and split argument strings into lists.
13+
- UNITS: Units of measurement for bytes, including KB, MB, GB, TB, etc., to facilitate size conversions.
14+
15+
"""
16+
417
from time import sleep
518
from traceback import format_exc
619

@@ -10,45 +23,48 @@
1023
from core.tool import Tool
1124

1225
INFO = dict[str, str]({
26+
"author": "Florian Cardinal",
27+
"github": "https://github.com/Tracks12/toolsManager.py",
1328
"name": "toolsManager.py",
14-
"version": "0.1"
29+
"version": "0.2",
1530
})
1631

1732
REGEX_ARGS = str("\\s(?=(?:[^\"'`]*[\"'`][^\"'`]*[\"'`])*[^\"'`]*$)")
1833
UNITS = tuple[str](("o", "ko", "Mo", "Go", "To"))
1934

2035
def helper(commands: tuple) -> None:
2136
colors = tuple[str]((Colors.cyan, Colors.yellow, Colors.red))
22-
screen = list[str]([ " List of commands:\n" ])
37+
screen = list[str]([ "List of commands:\n" ])
2338

2439
for i, command in enumerate(commands):
2540
c = int(1 if(i in range((len(commands)-4), (len(commands)-1))) else 0)
2641
c = int(2 if(i in range((len(commands)-1), (len(commands)))) else c)
2742
sep = str('\n' if(i in (len(commands)-5, len(commands)-2)) else '')
2843

29-
command = str(f" {colors[c]}{command[1]}{Colors.end}{sep}")
44+
command = str(f"{colors[c]}{command[1]}{Colors.end}{sep}")
3045

3146
screen.append(command)
3247

33-
print(("\n").join(screen), end="\n\n")
48+
print(("\n").join([ f" {s}" for s in screen ]), end="\n\n")
3449

3550
def launch(tool: Tool, args: list[str]) -> bool:
3651
try:
3752
print(f'{Icons.play}Starting "{tool.name}" ...')
3853
tool(args)
39-
40-
except Exception:
41-
print(f"{Icons.warn}{format_exc()}")
54+
55+
except(Exception):
56+
print(f"{Icons.err}{format_exc()}")
4257

4358
finally:
4459
print()
4560
return(True)
4661

4762
def sortTools(tools: list[Tool]) -> list[Tool]:
48-
print(f"\n {' '*1}* Name{' '*(12-len('Name'))}Command{' '*(16-len('Command'))}Path")
63+
table = list[str]([ f" * Name{' '*(14-len('Name'))}Command{' '*(16-len('Command'))}Path" ])
4964
for i, tool in enumerate(tools, start=1):
50-
print(f" {' '*(2-len(str(i)))}{i}. {tool.name}{' '*(12-len(tool.name))}{tool.command[1]}{' '*(16-len(tool.command[1]))}{tool.path}", end="\n"*(2 if(i == len(tools)) else 1))
65+
table.append(f"{' '*(2-len(str(i)))}{Colors.green}{i}{Colors.end}. {tool.name}{' '*(14-len(tool.name))}{Colors.cyan}{tool.command[1]}{Colors.end}{' '*(16-len(tool.command[1]))}{Colors.yellow}{tool.path}{Colors.end}")
5166

67+
print(f"\n{'\n'.join([f" {t}" for t in table])}", end="\n"*2)
5268
return(tools)
5369

5470
def splash(spacing: int = 2) -> None:
@@ -64,6 +80,17 @@ def splash(spacing: int = 2) -> None:
6480
print(f"{' '*spacing}{row}", end="\n"*(2 if(i == 6) else 1))
6581
sleep(.025)
6682

83+
def stringSize(size: int) -> str:
84+
size = [size, UNITS[0]]
85+
86+
for i in range(1, len(UNITS)):
87+
size[0] /= 1000
88+
size[1] = UNITS[i]
89+
if(size[0] < 1024):
90+
break
91+
92+
return(f"{round(size[0], 2)} {size[1]}")
93+
6794
def version() -> dict[str, str]:
6895
print(f" {INFO['name']} {INFO['version']}", end="\n"*2)
6996
return(INFO)

core/colors.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
#!/bin/python3
1+
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4+
r""" Abstract base class for color handling.
5+
6+
Defines abstract classes and interfaces to standardize color management
7+
across tools. It provides a foundation for implementing color schemes
8+
and palettes compatible with different output formats.
9+
10+
"""
11+
412
from platform import system
513

614
class Colors:
@@ -20,4 +28,4 @@ class Colors:
2028

2129
else:
2230
bold = italic = end = str("")
23-
red = green = yellow = blue = purple = cyan = white = str("")
31+
red = green = yellow = blue = purple = cyan = white = str("")

core/config.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
#!/bin/python3
1+
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4+
r""" Configuration management for tools.
5+
6+
This module provides functions to load, validate, and access configuration parameters essential
7+
for the proper operation of tools. It supports various configuration formats and allows centralized
8+
management of settings.
9+
10+
"""
11+
412
from json import dump, load
513
from os.path import abspath
614

@@ -25,7 +33,7 @@ def __load(self) -> bool:
2533
self.__splash = bool(_["splash"])
2634

2735
except Exception:
28-
print(f"{Icons.warn}Config file loading failed")
36+
print(f"{Icons.err}Config file loading failed")
2937
return(False)
3038

3139
return(True)
@@ -41,15 +49,21 @@ def __save(self) -> bool:
4149
dump(dict(_), cfgFile, sort_keys=True, indent=2)
4250

4351
except Exception:
44-
print(f"{Icons.warn}Config file saving failed")
52+
print(f"{Icons.err}Config file saving failed")
4553
return(False)
4654

4755
return(True)
4856

4957
def getEncoding(self) -> str:
58+
""" Returns the encoding state, e.g. "ascii", "utf-8", "utf-16" or "utf-32"
59+
"""
60+
5061
return(self.__encoding)
5162

5263
def getSplash(self) -> bool:
64+
""" Returns the splash display state, e.g. True or False.
65+
"""
66+
5367
return(self.__splash)
5468

5569
def setEncoding(self, encoding: str = "utf-8") -> bool:

core/icons.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
#!/bin/python3
1+
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4+
r""" Abstract base class for icon handling.
5+
6+
Defines abstract classes to represent icons used in tools.
7+
Provides a structure for consistent icon management and allows
8+
extension for various icon sets or formats.
9+
10+
"""
11+
412
from core.colors import Colors
513

614
class Icons:
7-
warn: str = f" {Colors.bold}{Colors.red}[!]{Colors.end} - "
15+
err: str = f" {Colors.bold}{Colors.red}[!]{Colors.end} - "
16+
warn: str = f" {Colors.bold}{Colors.yellow}/!\\{Colors.end} - "
817
info: str = f" {Colors.bold}{Colors.blue}(i){Colors.end} - "
918
tips: str = f" {Colors.bold}{Colors.green}(?){Colors.end} - "
1019
play: str = f" {Colors.bold}{Colors.green}(>){Colors.end} - "

0 commit comments

Comments
 (0)