|
1 |
| -# **toolsManager.py** |
2 |
| - |
3 |
| -Un multi-outils disposant de modèle générique permettant de développer des outils de gestion comme WSLBuilder pour la gestion des instances WSL construite à l'aide d'images exportés depuis Docker |
4 |
| - |
5 |
| -## Sommaire |
6 |
| - |
7 |
| -1. [Aperçu](#aperçu) |
8 |
| -2. [Pré-requis](#pré-requis) |
9 |
| - - [Dépendances](#dépendances) |
10 |
| - - [WSL / Docker](#wsl--docker) |
11 |
| -3. [Utilisations](#utilisations) |
12 |
| - - [Gestion des outils](#gestion-des-outils) |
13 |
| - - [Gestion WSL avec WSLBuilder](#gestion-des-images-wsl) |
14 |
| -4. [Options & Configurations](#options--configurations) |
15 |
| -6. [Licence](#licence) |
16 |
| - |
17 |
| -## Aperçu |
| 1 | +# **ToolsManager.py** |
| 2 | + |
| 3 | +A multi-tool with a generic template for developing management tools like WSLBuilder for managing WSL instances built using images exported from Docker. |
| 4 | + |
| 5 | +## Summary |
| 6 | + |
| 7 | +- [**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) |
| 22 | + |
| 23 | +## I. Preview |
18 | 24 |
|
19 | 25 | 
|
20 | 26 |
|
21 |
| -[Sommaire](#sommaire) |
| 27 | +[Summary](#summary) |
22 | 28 |
|
23 |
| -## Pré-requis |
| 29 | +## II. Prerequisites |
24 | 30 |
|
25 |
| -L'installation de **[Python 3](https://www.python.org/downloads/)** est recommandé pour l'éxécution du script sur windows |
| 31 | +> [!Important] |
| 32 | +> Installing **[Python 3](https://www.python.org/downloads/)** is recommended to run this script on Windows. |
26 | 33 |
|
27 |
| -[Sommaire](#sommaire) |
| 34 | +[Summary](#summary) |
28 | 35 |
|
29 |
| -### Dépendances |
| 36 | +### II.1 Dependencies |
30 | 37 |
|
31 | 38 | - [base64.b64decode](https://docs.python.org/3/library/base64.html#base64.b64decode), [base64.b64encode](https://docs.python.org/3/library/base64.html#base64.b64encode)
|
32 | 39 | - [json.loads](https://docs.python.org/3/library/json.html#json.loads), [json.dumps](https://docs.python.org/3/library/json.html#json.dumps), [json.load](https://docs.python.org/3/library/json.html#json.load), [json.dump](https://docs.python.org/3/library/json.html#json.dump)
|
33 |
| -- [os.listdir](https://docs.python.org/3/library/os.html#os.listdir), [os.system](https://docs.python.org/3/library/os.html#os.system) |
| 40 | +- [os.listdir](https://docs.python.org/3/library/os.html#os.listdir), [os.mkdir](https://docs.python.org/3/library/os.html#os.mkdir), [os.remove](https://docs.python.org/3/library/os.html#os.remove), [os.rmdir](https://docs.python.org/3/library/os.html#os.rmdir), [os.system](https://docs.python.org/3/library/os.html#os.system), [os.path](https://docs.python.org/3/library/os.path.html#os.path) |
34 | 41 | - [platform.system](https://docs.python.org/3/library/platform.html#platform.system)
|
| 42 | +- [re.split](https://docs.python.org/3/library/re.html#re.split) |
35 | 43 | - [random.shuffle](https://docs.python.org/3/library/random.html#random.shuffle)
|
| 44 | +- [readline](https://docs.python.org/3/library/readline.html) |
| 45 | +- [shutil.rmtree](https://docs.python.org/3/library/shutil.html#shutil.rmtree) |
36 | 46 | - [sys.argv](https://docs.python.org/3/library/sys.html#sys.argv), [sys.version_info](https://docs.python.org/3/library/sys.html#sys.version_info)
|
37 | 47 | - [time.sleep](https://docs.python.org/3/library/time.html#time.sleep)
|
| 48 | +- [traceback.format_exc](https://docs.python.org/3/library/traceback.html#traceback.format_exc) |
| 49 | + |
| 50 | +> [!Note] |
| 51 | +> [readline](https://docs.python.org/3/library/readline.html) is for multiline finder in linux system |
| 52 | +
|
| 53 | +[Summary](#summary) |
| 54 | + |
| 55 | +## III. Uses |
| 56 | + |
| 57 | +To use the tool manager, you need to open a terminal prompt and run the python script at the root of the project |
| 58 | + |
| 59 | +> [!Important] |
| 60 | +> 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` |
| 61 | +
|
| 62 | +### III.1 Command Prompt |
| 63 | + |
| 64 | +Usage: `$ python main.py <argument>` |
| 65 | + |
| 66 | +| Arguments | Values | Descriptions | |
| 67 | +| --------------------- | ------------------- | ------------------------------------------- | |
| 68 | +| `-g`, `--generate` | - | Generate a tool with interactive inputs | |
| 69 | +| `-l`, `--list` | - | Display the list of Python tools | |
| 70 | +| `-s`, `--set` | `<prop>`, `<value>` | Apply new configuration value to a property | |
| 71 | +| `-t`, `--tool` | `<tool>` | Launch a tool | |
| 72 | +| `-h`, `--help` | - | Display the help menu | |
| 73 | +| `-D`, `--debug` | - | Run in debugger mode | |
| 74 | +| `-v`, `--version` | - | Display the program version | |
| 75 | + |
| 76 | +[Summary](#summary) |
| 77 | + |
| 78 | +### III.2 Main Program |
| 79 | + |
| 80 | +Usage: `$ python main.py` |
| 81 | + |
| 82 | +``` |
| 83 | + _ _ __ __ |
| 84 | + | | | | | \/ | |
| 85 | + | |_ ___ ___ | | _|_\ / | __ _ _ __ __ _ __ _ ___ _ __ |
| 86 | + | __/ _ \ / _ \| |/ _/|\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '__| |
| 87 | + | || (_) | (_) | _\ \ | | | (_| | | | | (_| | (_| | __/ | |
| 88 | + \__\___/ \___/|/___/_| |_|\__,_|_| |_|\__,_|\__, |\___|_| |
| 89 | + version: 0.1 |___/ |
| 90 | +
|
| 91 | + List of commands: |
| 92 | +
|
| 93 | + (mat)rix |
| 94 | + (sh)ell |
| 95 | + (wb)wslbuilder |
| 96 | +
|
| 97 | + (s)ettings |
| 98 | + (v)ersion |
| 99 | + (h)elp |
38 | 100 |
|
39 |
| -[Sommaire](#sommaire) |
| 101 | + (q)uit |
40 | 102 |
|
41 |
| -### WSL / Docker |
| 103 | +(toolsManager.py)> |
| 104 | +``` |
| 105 | + |
| 106 | +[Summary](#summary) |
| 107 | + |
| 108 | +## IV. Tool Management |
| 109 | + |
| 110 | +[Summary](#summary) |
| 111 | + |
| 112 | +### IV.1 Tool Structure |
| 113 | + |
| 114 | +Here you will find a typical example of a tool structure: |
| 115 | + |
| 116 | +```python |
| 117 | +#!/usr/bin/env python3 |
| 118 | +# -*- coding: utf-8 -*- |
| 119 | + |
| 120 | +# tools/hello.py |
| 121 | + |
| 122 | +# Importation of the tool model |
| 123 | +from core.tool import Tool |
| 124 | + |
| 125 | +class Hello(Tool): |
| 126 | + """ Say hello to the user |
| 127 | + """ |
42 | 128 |
|
43 |
| -[Sommaire](#sommaire) |
| 129 | + command = (("hello", "hel"), "(hel)lo") # The launch command control by name or alias |
| 130 | + name = "Hello" # Tool name |
| 131 | + path = __file__ # Path of tool file |
| 132 | + version = "0.1a" # Tool version |
44 | 133 |
|
45 |
| -## Utilisations |
| 134 | + def __init__(self, args: list[str]): |
| 135 | + # Initialization of Tool |
| 136 | + super().__init__() |
46 | 137 |
|
47 |
| -Exécution du script: `$ python main.py <arg>` |
| 138 | + # Argument registry corresponding to lamdba registry index |
| 139 | + self._args = [ |
| 140 | + (("-s", "--say-hello", ""), "Say a hello world") |
| 141 | + ] + self._args[:] |
48 | 142 |
|
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 | |
| 143 | + # Lamdba registry corresponding to argument registry index |
| 144 | + self._execs = [ |
| 145 | + lambda x:self._sayHello(x) |
| 146 | + ] + self._execs[:] |
56 | 147 |
|
57 |
| -[Sommaire](#sommaire) |
| 148 | + # _run(args) method to lauch method in lambda registry with arguments |
| 149 | + # tips: you can rewrite the methode if you want to put some exception or rules to launch |
| 150 | + self._run(args) |
58 | 151 |
|
59 |
| -### Gestion des outils |
| 152 | + def _sayHello(self, args: list[str]) -> bool: |
| 153 | + print(f"Hello world :D") |
| 154 | + return(True) |
60 | 155 |
|
61 |
| -[Sommaire](#sommaire) |
| 156 | + # ... |
| 157 | +``` |
| 158 | + |
| 159 | +> [!Tip] |
| 160 | +> Since the last update, you can create you own tool by typing `$ python main.py -g` |
| 161 | +
|
| 162 | +[Summary](#summary) |
| 163 | + |
| 164 | +### IV.2 Tools Registry |
| 165 | + |
| 166 | +[Summary](#summary) |
62 | 167 |
|
63 |
| -### Gestion WSL avec WSLBuilder |
| 168 | +### IV.3 Tools Index |
64 | 169 |
|
65 |
| -[Sommaire](#sommaire) |
| 170 | +| Tool | Version | |
| 171 | +| -------------------------------- | ------- | |
| 172 | +| [WSLBuilder](docs/WSLBuilder.md) | v0.1a | |
66 | 173 |
|
67 |
| -## Options & Configurations |
| 174 | +[Summary](#summary) |
68 | 175 |
|
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. |
| 176 | +## V. Options & Configurations |
| 177 | + |
| 178 | +The program is configured from the **[config.json](config.json)** file in **json** format. In this file, you can set the **character encoding** and the splash screen display. |
70 | 179 |
|
71 | 180 | ```json
|
72 | 181 | {
|
| 182 | + "colors": false, |
73 | 183 | "encoding": "utf-8",
|
74 | 184 | "splash": true
|
75 | 185 | }
|
76 | 186 | ```
|
77 | 187 |
|
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**. |
| 188 | +You can modify it directly (which is not recommended) or use the configuration program with **all possible parameter choices in the "Settings" option in the main menu**. |
| 189 | + |
| 190 | +> [!Note] |
| 191 | +> You can manage settings with cli command `$ python main.py -s encoding utf-8` inside a shell |
| 192 | +> |
| 193 | +> Or directly in main config index by typing `settings` & `set encoding utf-8` inside the program |
| 194 | +
|
| 195 | +[Summary](#summary) |
| 196 | + |
| 197 | +## VI. Contributing |
| 198 | + |
| 199 | +If you to contribute to the project, you access to the coding guideline at [CONTRIBUTING.md](CONTRIBUTING.md) |
79 | 200 |
|
80 |
| -[Sommaire](#sommaire) |
| 201 | +[Summary](#summary) |
81 | 202 |
|
82 |
| -## Licence |
| 203 | +## VII. License |
83 | 204 |
|
84 |
| -Code sous license [GPL v3](LICENSE) |
| 205 | +Code licensed under [GPL v3](LICENSE) |
85 | 206 |
|
86 |
| -[Sommaire](#sommaire) |
| 207 | +[Summary](#summary) |
0 commit comments