Skip to content

Commit 989a622

Browse files
authored
Merge pull request #12 from Tracks12/dev
0.2a
2 parents 70b7038 + 24aeaaf commit 989a622

File tree

15 files changed

+556
-72
lines changed

15 files changed

+556
-72
lines changed

.gitignore

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
.vscode/
1+
# Config
2+
.vscode
23

3-
__pycache__/
4+
# Builds
5+
/build
6+
/dist
7+
__pycache__
48
*.pyc
59

10+
# Packages
611
/libs/wslbuilder
12+
/Shell/
13+
/Translator/
714
/WSLBuilder/
815
*.vhdx

CONTRIBUTING.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
This document defines the best development practices to follow when contributing to the project.
88

9-
---
10-
119
### 📁 Project Structure
1210

1311
- `main.py`: Main entry point.
@@ -17,8 +15,6 @@ This document defines the best development practices to follow when contributing
1715
- `dev`: Continuous development branch.
1816
- `master`: Stable branch only.
1917

20-
---
21-
2218
### 🧱 Tool Writing Convention
2319

2420
- Each tool must:

README.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ A multi-tool with a generic template for developing management tools like WSLBui
55
## Summary
66

77
- [**ToolsManager.py**](#toolsmanagerpy)
8-
- [Summary](#summary)
9-
- [I. Preview](#i-preview)
10-
- [II. Prerequisites](#ii-prerequisites)
11-
- [II.1 Dependencies](#ii1-dependencies)
12-
- [III. Uses](#iii-uses)
13-
- [III.1 Command Prompt](#iii1-command-prompt)
14-
- [III.2 Main Program](#iii2-main-program)
15-
- [IV. Tool Management](#iv-tool-management)
16-
- [IV.1 Tool Structure](#iv1-tool-structure)
17-
- [IV.2 Tools Registry](#iv2-tools-registry)
18-
- [IV.3 Tools Index](#iv3-tools-index)
19-
- [V. Options \& Configurations](#v-options--configurations)
20-
- [VI. Contributing](#vi-contributing)
21-
- [VII. License](#vii-license)
8+
- [Summary](#summary)
9+
- [I. Preview](#i-preview)
10+
- [II. Prerequisites](#ii-prerequisites)
11+
- [II.1 Dependencies](#ii1-dependencies)
12+
- [III. Uses](#iii-uses)
13+
- [III.1 Command Prompt](#iii1-command-prompt)
14+
- [III.2 Main Program](#iii2-main-program)
15+
- [IV. Tool Management](#iv-tool-management)
16+
- [IV.1 Tool Structure](#iv1-tool-structure)
17+
- [IV.2 Tools Registry](#iv2-tools-registry)
18+
- [IV.3 Tools Index](#iv3-tools-index)
19+
- [V. Options \& Configurations](#v-options--configurations)
20+
- [VI. Contributing](#vi-contributing)
21+
- [VII. License](#vii-license)
2222

2323
## I. Preview
2424

@@ -59,6 +59,8 @@ To use the tool manager, you need to open a terminal prompt and run the python s
5959
> [!Important]
6060
> Some tools present in the registry have dependencies contained in the [`libs/`](libs/) folder in the form of a `*.rar` file, you must unzip them by typing the command `$ python setup.py`
6161
62+
[Summary](#summary)
63+
6264
### III.1 Command Prompt
6365

6466
Usage: `$ python main.py <argument>`
@@ -167,9 +169,11 @@ class Hello(Tool):
167169

168170
### IV.3 Tools Index
169171

170-
| Tool | Version |
171-
| -------------------------------- | ------- |
172-
| [WSLBuilder](docs/WSLBuilder.md) | v0.1a |
172+
| Tool | Version | Description |
173+
| -------------------------------- | ------- | ------------------------------------------ |
174+
| [Shell](docs/Shell.md) | v1.0 | Prompt interface with custom schedules |
175+
| [Translator](docs/Translator.md) | v1.0 | Translation tool manager |
176+
| [WSLBuilder](docs/WSLBuilder.md) | v1.1 | Managing Docker images compatible with WSL |
173177

174178
[Summary](#summary)
175179

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"colors": false,
2+
"colors": true,
33
"encoding": "utf-8",
44
"splash": true
55
}

core/__init__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ def helper(commands: tuple) -> None:
4949
c = int(2 if(i in range((len(commands)-1), (len(commands)))) else c)
5050
sep = str('\n' if(i in (len(commands)-5, len(commands)-2)) else '')
5151

52-
command = str(f"{colors[c]}{command[1]}{Colors.end}{sep}")
53-
54-
screen.append(command)
52+
screen.append(f"{colors[c]}{command[1]}{Colors.end}{sep}")
5553

5654
print(("\n").join([ f" {s}" for s in screen ]), end="\n\n")
5755

@@ -68,11 +66,18 @@ def launch(tool: Tool, args: list[str]) -> bool:
6866
return(True)
6967

7068
def sortTools(tools: list[Tool]) -> list[Tool]:
71-
table = list[str]([ f" * Name{' '*(14-len('Name'))}Command{' '*(16-len('Command'))}Path" ])
69+
table = list[str]([ f" * Name{' '*(14-len('Name'))}Version{' '*(9-len('Version'))}Command{' '*(16-len('Command'))}Path" ])
7270
for i, tool in enumerate(tools, start=1):
73-
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}")
74-
75-
print(f"\n{'\n'.join([f" {t}" for t in table])}", end="\n"*2)
71+
table.append("".join([
72+
f"{' '*(2-len(str(i)))}{Colors.green}{i}{Colors.end}.",
73+
f"{' '*1}{tool.name}",
74+
f"{' '*(14-len(tool.name))}{Colors.purple}{tool.version}{Colors.end}"
75+
f"{' '*(9-len(tool.version))}{Colors.cyan}{tool.command[1]}{Colors.end}"
76+
f"{' '*(16-len(tool.command[1]))}{Colors.yellow}{tool.path}{Colors.end}"
77+
]))
78+
79+
_ = "\n".join([ f" {t}" for t in table ])
80+
print(f"\n{_}", end="\n"*2)
7681
return(tools)
7782

7883
def splash(spacing: int = 2) -> None:

core/tool.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ def _helper(self, jumps: list[int] = []) -> None:
115115

116116
for i, a in enumerate(self._args):
117117
l = f"{a[0][0]}, {a[0][1]} {a[0][2]}"
118-
table.append(f"{l}{' '*(34-len(l))}{a[1]}{"\n"*(1 if(i in jumps) else 0)}")
118+
table.append("".join([
119+
f"{l}{' '*(34-len(l))}{a[1]}",
120+
'\n'*(1 if(i in jumps) else 0)
121+
]))
119122

120123
print("\n".join([ f" {t}" for t in table ]))
121124

docs/Shell.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# **Shell**
2+
3+
[Back to index](../README.md)
4+
5+
## Summary
6+
7+
- [**Shell**](#shell)
8+
- [Summary](#summary)
9+
- [I. Preview](#i-preview)
10+
11+
## I. Preview
12+
13+
[Summary](#summary)
14+
15+
[Back to index](../README.md)

docs/Translator.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# **Translator**
2+
3+
[Back to index](../README.md)
4+
5+
## Summary
6+
7+
- [**Translator**](#translator)
8+
- [Summary](#summary)
9+
- [I. Preview](#i-preview)
10+
11+
## I. Preview
12+
13+
[Summary](#summary)
14+
15+
[Back to index](../README.md)

main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
try:
55
# --- Importing external dependencies ---
66
from os import system as shell
7+
from os.path import basename
78
from platform import system
89
from re import split
910
from sys import argv, version_info
@@ -84,14 +85,17 @@ def arg(cfg: Config) -> bool:
8485
__table = list[str]([
8586
f"{INFO['name']} by {INFO['author']}",
8687
f"Github: {INFO['github']}\n",
87-
"Usage: python main.py <argument>\n",
88+
f"Usage: python {basename(__file__)} <argument>\n",
8889
f"Arguments:{' '*(34-len('Arguments:'))}Descriptions:"
8990
])
9091

9192
for i, arg in enumerate(__args["prefix"]):
9293
__left = f"{arg[0][0]}, {arg[0][1]} {arg[1]}"
9394
__desc = f"\n{' '*35}* ".join(__args['desc'][i]) if(isinstance(__args['desc'][i], tuple)) else __args['desc'][i]
94-
__table.append(f"{__left}{' '*(34-len(__left))}{__desc}{"\n"*(1 if(i in (len(__args['desc'])-4, len(__args['desc'])-1)) else 0)}")
95+
__table.append("".join([
96+
f"{__left}{' '*(34-len(__left))}{__desc}",
97+
"\n"*(1 if(i in (len(__args['desc'])-4, len(__args['desc'])-1)) else 0)
98+
]))
9599

96100
print("\n".join([ f" {t}" for t in __table ]))
97101

setup.py

Lines changed: 101 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22
# -*- coding: utf-8 -*-
33

44
from os import listdir
5-
from os.path import abspath, isdir
5+
from os.path import abspath, basename, isdir
66
from shutil import rmtree
7+
from sys import argv
78

89
from core.rarfile import RarFile
910

1011
LIBS_REGISTRY = list[str]([
1112
"wslbuilder"
1213
])
1314

15+
EXTRACT_PATH = abspath("libs/")
16+
17+
def ask(msg: str = "Are you sure ?") -> bool:
18+
return(bool((input(f"{msg} [y/N] ").lower() or "n") == "y"))
19+
1420
def clearLibs(paths: list[str]) -> None:
1521
for p in paths:
1622
try:
@@ -19,22 +25,34 @@ def clearLibs(paths: list[str]) -> None:
1925
except(FileNotFoundError):
2026
pass
2127

22-
def setup() -> bool:
23-
__extractPath = abspath("libs/")
24-
__rarPaths = [ abspath(f"{__extractPath}/{m}.rar") for m in LIBS_REGISTRY ]
25-
__libsPath = [ abspath(f"{__extractPath}/{m}") for m in LIBS_REGISTRY ]
28+
def install(registry: list[str]) -> bool:
29+
__rarPaths = [ abspath(f"{EXTRACT_PATH}/{m}.rar") for m in registry ]
30+
__libsPath = [ abspath(f"{EXTRACT_PATH}/{m}") for m in registry ]
31+
__checkExists = [ lib for lib in listdir(EXTRACT_PATH) if isdir(abspath(f"{EXTRACT_PATH}/{lib}")) if lib in registry ]
32+
33+
if(len(__checkExists)):
34+
for ce in __checkExists:
35+
print(f" (-) {ce}")
36+
37+
if(not ask("Did you want to uninstall these packages ?")):
38+
print("[ CANCEL ]: Abort reinstallation !")
39+
return(False)
2640

27-
if(len([ d for d in listdir(__extractPath) if isdir(abspath(f"{__extractPath}/{d}")) ])):
2841
print("[ INFO ]: Clearing installation ...")
2942
clearLibs(__libsPath)
43+
print("[ INFO ]: Installation cleared !")
3044

3145
for i, rp in enumerate(__rarPaths):
3246
try:
3347
with RarFile(rp) as __rf:
3448
print(f" ( ) Unpacking {rp} ... [{i}/{len(__rarPaths)}]", end="\r")
35-
__rf.extractall(__extractPath)
49+
__rf.extractall(EXTRACT_PATH)
3650
print(f" (*) {rp} Unpacked{' '*16}")
3751

52+
except(FileNotFoundError):
53+
print(f"[ ERROR ]: {rp} not found{' '*(16+len(rp))}")
54+
pass
55+
3856
except(Exception) as e:
3957
clearLibs(__libsPath)
4058
print(f"\n[ ERROR ]: {e}{' '*(16+len(rp))}")
@@ -43,5 +61,80 @@ def setup() -> bool:
4361
print("[ OK ]: Installation finished !")
4462
return(True)
4563

64+
def uninstall(registry: list[str]) -> bool:
65+
__libsPath = [ abspath(f"{EXTRACT_PATH}/{m}") for m in registry ]
66+
__checkExists = [ lib for lib in listdir(EXTRACT_PATH) if isdir(abspath(f"{EXTRACT_PATH}/{lib}")) if lib in registry ]
67+
68+
if(len(__checkExists)):
69+
for ce in __checkExists:
70+
print(f" (-) {ce}")
71+
72+
if(not ask("Did you want to uninstall these packages ?")):
73+
print("[ CANCEL ]: Abort uninstallation !")
74+
return(False)
75+
76+
print("[ INFO ]: Uninstallation finished !")
77+
clearLibs(__libsPath)
78+
79+
return(True)
80+
81+
def arg() -> bool:
82+
__args = dict({
83+
"prefix": tuple[tuple[tuple[str], str]]((
84+
(("-i", "--install"), "<lib>"),
85+
(("-p", "--purge"), ""),
86+
(("-r", "--registry"), ""),
87+
(("-u", "--uninstall"), "<lib>"),
88+
(("-h", "--help"), "")
89+
)),
90+
"desc": tuple[str | tuple[str]]((
91+
"Install a dependency",
92+
"Purge all dependencies",
93+
"Show libs registry",
94+
"Uninstall a dependency",
95+
"Show the helper commands menu"
96+
))
97+
})
98+
99+
try:
100+
if(argv[1] in __args["prefix"][0][0]): # -i, --install
101+
install([ argv[2] ])
102+
103+
elif(argv[1] in __args["prefix"][1][0]): # -p, --purge
104+
uninstall(LIBS_REGISTRY)
105+
106+
elif(argv[1] in __args["prefix"][2][0]): # -r, --registry
107+
print("[ INFO ]: Listing the package registry:")
108+
for i, lib in enumerate(LIBS_REGISTRY, 1):
109+
print(f" {' '*(3-len(str(i)))}{i}. {lib} -> {abspath(f'{EXTRACT_PATH}/{lib}.rar')}")
110+
111+
elif(argv[1] in __args["prefix"][3][0]): # -u, --uninstall
112+
uninstall([ argv[2] ])
113+
114+
elif(argv[1] in __args["prefix"][-1][0]): # -h, --help
115+
__table = list[str]([
116+
f"Usage: python {basename(__file__)} <argument>\n",
117+
f"Arguments:{' '*(34-len('Arguments:'))}Descriptions:"
118+
])
119+
120+
for i, arg in enumerate(__args["prefix"]):
121+
__left = f"{arg[0][0]}, {arg[0][1]} {arg[1]}"
122+
__desc = f"\n{' '*35}* ".join(__args['desc'][i]) if(isinstance(__args['desc'][i], tuple)) else __args['desc'][i]
123+
__table.append("".join([
124+
f"{__left}{' '*(34-len(__left))}{__desc}",
125+
"\n"*(1 if(i in (len(__args['desc'])-2, len(__args['desc'])-1)) else 0)
126+
]))
127+
128+
print("\n".join([ f" {t}" for t in __table ]))
129+
130+
except(IndexError, KeyError):
131+
print(f"/!\\ - Insufficient arguments !")
132+
return(False)
133+
134+
return(True)
135+
136+
def setup() -> bool:
137+
return(install(LIBS_REGISTRY))
138+
46139
if(__name__ == "__main__"):
47-
setup()
140+
arg() if(len(argv) > 1) else setup()

0 commit comments

Comments
 (0)