Skip to content

Commit ef905fb

Browse files
authored
Merge pull request #2 from Tracks12/dev
Dev
2 parents 5bf6aa4 + abb3c24 commit ef905fb

File tree

6 files changed

+110
-76
lines changed

6 files changed

+110
-76
lines changed

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,43 @@ L'installation de **[Python 3](https://www.python.org/downloads/)** est recomman
4444

4545
## Utilisations
4646

47+
Exécution du script: `$ python main.py <arg>`
48+
49+
| Arguments | Valeur | Descriptions |
50+
| ---------------------------- | ----------------------- | ---------------------------------- |
51+
| `-l`, `--list` | - | Affiche la liste des outils python |
52+
| `-t <tool>`, `--tool <tool>` | `<tool>` nom de l'outil | Lance un outil |
53+
| `-h`, `--help` | - | Affiche le menu d'aide |
54+
| `-D`, `--debug` | - | Exécution en mode debuger |
55+
| `-v`, `--version` | - | Affiche la version du programme |
56+
57+
[Sommaire](#sommaire)
58+
4759
### Gestion des outils
4860

4961
[Sommaire](#sommaire)
5062

5163
### Gestion WSL avec WSLBuilder
5264

53-
[Sommaire](#sommaire)
65+
[Sommaire](#sommaire)
66+
67+
## Options & Configurations
68+
69+
La configuration du programme se fait depuis le fichier **[config.json](config.json)** au format **json**, dans ce fichier vous pouvez l'**encodage des caractères** ainsi que l'affichage du splash screen.
70+
71+
```json
72+
{
73+
"encoding": "utf-8",
74+
"splash": true
75+
}
76+
```
77+
78+
Vous pouvez le modifier directement (ce qui est peu conseiller) ou bien passer par le programme de configuration avec **tous les choix des paramètres possible à l'option "Paramètres" du menu principal**.
79+
80+
[Sommaire](#sommaire)
81+
82+
## Licence
83+
84+
Code sous license [GPL v3](LICENSE)
85+
86+
[Sommaire](#sommaire)

core/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
UNITS = tuple[str](("o", "ko", "Mo", "Go", "To"))
1919

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

2424
for i, command in enumerate(commands):
25-
c = int(1 if(i in range((len(commands)-4), (len(commands)-1))) else 0)
26-
c = int(2 if(i in range((len(commands)-1), (len(commands)))) else c)
27-
sep = str('\n' if(i in (len(commands)-5, len(commands)-2)) else '')
25+
c = int(1 if(i in range((len(commands)-4), (len(commands)-1))) else 0)
26+
c = int(2 if(i in range((len(commands)-1), (len(commands)))) else c)
27+
sep = str('\n' if(i in (len(commands)-5, len(commands)-2)) else '')
2828

2929
command = str(f" {colors[c]}{command[1]}{Colors.end}{sep}")
3030

@@ -45,9 +45,9 @@ def launch(tool: Tool, args: list[str]) -> bool:
4545
return(True)
4646

4747
def sortTools(tools: list[Tool]) -> list[Tool]:
48-
print(f"\n {' '*1}* Name{' '*(12-len('Name'))}Path")
48+
print(f"\n {' '*1}* Name{' '*(12-len('Name'))}Command{' '*(16-len('Command'))}Path")
4949
for i, tool in enumerate(tools, start=1):
50-
print(f" {' '*(2-len(str(i)))}{i}. {tool.name}{' '*(12-len(tool.name))}{tool.path}", end="\n"*(2 if(i == len(tools)) else 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))
5151

5252
return(tools)
5353

main.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def arg() -> bool:
2222
args = dict({
2323
"prefix": tuple[tuple[tuple[str], str]]((
2424
(("-l", "--list"), ""),
25-
(("-t", "--tool"), "<toolName>"),
25+
(("-t", "--tool"), "<tool>"),
2626
(("-h", "--help"), ""),
2727
(("-D", "--debug"), ""),
2828
(("-v", "--version"), "")
@@ -133,19 +133,13 @@ def config(cfg: Config) -> bool:
133133
return(True)
134134

135135
def main(cfg: Config) -> bool:
136-
commands = list[tuple]([
136+
commands = list[tuple]([ tool.command for tool in TOOLS ] + [
137137
(("settings", "set"), "(set)tings"),
138138
(("version", "ver"), "(ver)sion"),
139139
(("help", "h"), "(h)elp"),
140140
(("quit", "q"), "(q)uit")
141141
])
142142

143-
TOOLS.reverse()
144-
for tool in TOOLS:
145-
commands = [tool.command] + commands[:]
146-
147-
TOOLS.reverse()
148-
149143
if(cfg.getSplash()):
150144
splash()
151145

@@ -168,23 +162,24 @@ def main(cfg: Config) -> bool:
168162
except:
169163
print(f'{Icons.warn}"{command[0][0]}" not implemented !')
170164

171-
if(args[0] in commands[-4][0]):
172-
config(cfg)
165+
if(not f):
166+
if(args[0] in commands[-4][0]):
167+
config(cfg)
173168

174-
elif(args[0] in commands[-3][0]):
175-
version()
169+
elif(args[0] in commands[-3][0]):
170+
version()
176171

177-
elif(args[0] in commands[-2][0]):
178-
helper(commands)
172+
elif(args[0] in commands[-2][0]):
173+
helper(commands)
179174

180-
elif(args[0] in commands[-1][0]):
181-
break
175+
elif(args[0] in commands[-1][0]):
176+
break
182177

183-
elif((not args[0]) or f):
184-
pass
178+
elif((not args[0]) or f):
179+
pass
185180

186-
else:
187-
print(f"{Icons.warn}Uknown command !")
181+
else:
182+
print(f"{Icons.warn}Uknown command !")
188183

189184
return(True)
190185

tools/matrix.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
class Matrix(Tool):
1313
command = (("matrix", "mat"), "(mat)rix")
1414
name = "Matrix"
15-
path = __file__
15+
path = __file__
1616
version = "0.1a"
1717

18-
_args = [
19-
(("-n", "--new", "<x> <y>"), "Create a matrix with custom dimensions"),
20-
(("-r", "--random", "<x> <y> <i>"), "Create a matrix with placed random point")
21-
] + Tool._args[:]
22-
2318
def __init__(self, args: list[str]):
24-
Tool.__init__(self)
19+
super().__init__()
20+
21+
self._args = [
22+
(("-n", "--new", "<x> <y>"), "Create a matrix with custom dimensions"),
23+
(("-r", "--random", "<x> <y> <i>"), "Create a matrix with placed random point")
24+
] + self._args[:]
2525

2626
self._execs = [
2727
lambda x:self._new(x),

tools/shell.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
class Shell(Tool):
1111
command = (("shell", "sh"), "(sh)ell")
1212
name = "Shell"
13-
path = __file__
13+
path = __file__
1414
version = "0.1a"
1515

16-
_args = [
17-
(("-c", "--command", ""), "Run a bash command")
18-
] + Tool._args[:]
19-
2016
def __init__(self, args: list[str]):
21-
Tool.__init__(self)
17+
super().__init__()
18+
19+
self._args = [
20+
(("-c", "--command", ""), "Run a bash command")
21+
] + self._args[:]
2222

2323
self._execs = [
2424
lambda x:self._exec(x)

tools/wslBuilder.py

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,37 @@
44
from os import listdir, mkdir, remove, rmdir, system as shell
55
from os.path import abspath, dirname, getsize
66

7+
import re
8+
79
from core import UNITS
810
from core.icons import Icons
911
from core.tool import Tool
1012

13+
DISTRONAME_REGEX = str("(\\s)|([/:])")
14+
1115
class WslBuilder(Tool):
1216
command = (("wslbuilder", "wb"), "(wb)wslbuilder")
1317
name = "WSLBuilder"
14-
path = __file__
15-
version = "0.1a"
16-
17-
_args = [
18-
(("-c", "--create", "<name>"), "Create a wsl distribution"),
19-
(("-d", "--delete", "<name>"), "Remove a wsl distribution image and disk"),
20-
(("-D", "--full-delete", "<name>"), "Remove a wsl distribution image and disk with docker traces"),
21-
(("-e", "--export", "<name>"), "Remove a wsl distribution into a tar image"),
22-
(("-I", "--init", ""), "Init a wsl builder instance with docker"),
23-
(("-l", "--list", ""), "List all wsl distributions"),
24-
(("-s", "--start", "<name>"), "Launch a wsl instance"),
25-
] + Tool._args[:]
26-
27-
__path = str(abspath(f"{dirname(abspath(__file__))}/../{name}"))
18+
path = __file__
19+
version = "1.0"
2820

2921
def __init__(self, args: list[str]):
30-
Tool.__init__(self)
31-
32-
try:
33-
mkdir(self.__path)
34-
print(f"{Icons.info}Create path workspace for {self.name} tool at {self.__path}")
35-
36-
except FileExistsError:
37-
print(f"{Icons.info}Using {self.__path} for {self.name} workspace already exist")
38-
39-
except PermissionError:
40-
print(f"{Icons.warn}Permission denied: Unable to create '{self.__path}'.")
41-
42-
except Exception as e:
43-
print(f"{Icons.warn}An error occurred: {e}")
44-
45-
self._execs = [
22+
super().__init__()
23+
24+
self.__path = str(abspath(f"{dirname(abspath(__file__))}/../{self.name}"))
25+
self.__setup()
26+
27+
self._args = [
28+
(("-c", "--create", "<name>"), "Create a wsl distribution"),
29+
(("-d", "--delete", "<name>"), "Remove a wsl distribution image and disk"),
30+
(("-D", "--full-delete", "<name>"), "Remove a wsl distribution image and disk with docker traces"),
31+
(("-e", "--export", "<name>"), "Export a wsl distribution into a tar image"),
32+
(("-I", "--init", ""), "Init a wsl builder instance with docker"),
33+
(("-l", "--list", ""), "List all wsl distributions"),
34+
(("-s", "--start", "<name>"), "Launch a wsl instance"),
35+
] + self._args[:]
36+
37+
self._execs= [
4638
lambda x:self._create(x),
4739
lambda x:self._delete(x),
4840
lambda x:self._fullDelete(x),
@@ -56,9 +48,23 @@ def __init__(self, args: list[str]):
5648

5749
def __checkDockerStatus(self) -> bool:
5850
return bool(shell(f"wsl service docker status"))
51+
52+
def __setup(self) -> None:
53+
try:
54+
mkdir(self.__path)
55+
print(f"{Icons.info}Create path workspace for {self.name} tool at {self.__path}")
56+
57+
except FileExistsError:
58+
print(f"{Icons.info}Using {self.__path} for {self.name} workspace already exist")
59+
60+
except PermissionError:
61+
print(f"{Icons.warn}Permission denied: Unable to create '{self.__path}'.")
62+
63+
except Exception as e:
64+
print(f"{Icons.warn}An error occurred: {e}")
5965

6066
def _create(self, args: list[str]) -> None:
61-
__distroName = args[0].replace(':', '-')
67+
__distroName = re.sub(DISTRONAME_REGEX, "-", args[0])
6268
__distroPath = abspath(f"{self.__path}/{__distroName}")
6369

6470
try:
@@ -85,7 +91,7 @@ def _create(self, args: list[str]) -> None:
8591

8692
def _delete(self, args: list[str]) -> None:
8793
__distros = listdir(self.__path)
88-
__distroName = args[0].replace(':', '-')
94+
__distroName = re.sub(DISTRONAME_REGEX, "-", args[0])
8995
__distroPath = abspath(f"{self.__path}/{__distroName}")
9096

9197
try:
@@ -101,7 +107,7 @@ def _delete(self, args: list[str]) -> None:
101107
print(f"{Icons.warn}Wsl distribution doesn't exist on workspace")
102108

103109
def _fullDelete(self, args: list[str]) -> None:
104-
__distroName = args[0].replace(':', '-')
110+
__distroName = re.sub(DISTRONAME_REGEX, "-", args[0])
105111

106112
shell(f"wsl docker rm {__distroName}")
107113
shell(f"wsl docker rmi {args[0]}")
@@ -110,7 +116,7 @@ def _fullDelete(self, args: list[str]) -> None:
110116

111117
def _export(self, args: list[str]) -> None:
112118
__distros = listdir(self.__path)
113-
__distroName = args[0].replace(':', '-')
119+
__distroName = re.sub(DISTRONAME_REGEX, "-", args[0])
114120
__distroPath = abspath(f"{self.__path}/{__distroName}")
115121

116122
if(__distroName in __distros):
@@ -151,7 +157,7 @@ def _list(self) -> None:
151157

152158
def _start(self, args: list[str]) -> None:
153159
__distros = listdir(self.__path)
154-
__distroName = args[0].replace(':', '-')
160+
__distroName = re.sub(DISTRONAME_REGEX, "-", args[0])
155161

156162
if(__distroName in __distros):
157163
shell(f"wsl -d {__distroName}")

0 commit comments

Comments
 (0)