Skip to content

Commit a80a16c

Browse files
authored
Merge pull request #14 from Tracks12/dev
v0.3
2 parents 989a622 + 2ae2f16 commit a80a16c

18 files changed

+508
-188
lines changed

CONTRIBUTING.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,15 @@ class Hello(Tool):
4545
version = "0.1a"
4646

4747
def __init__(self, args: list[str]):
48-
super().__init__()
49-
5048
self._args = [
5149
(("-s", "--say-hello", "<user>"), "Say hello to the user")
52-
] + self._args[:]
50+
]
5351

5452
self._execs = [
5553
lambda x:self._sayHello(x)
56-
] + self._execs[:]
54+
]
5755

56+
super().__init__()
5857
self._run(args)
5958

6059
def _sayHello(self, args: list[str]) -> bool:
@@ -75,7 +74,7 @@ class Hello:
7574
# ❌ Missing Tool porperties command, name, path & version
7675

7776
def __init__(self, a: list[str]): # ❌ Naming mistake on args parameters
78-
super().__init__()
77+
super().__init__() # ❌ Bad super init position
7978

8079
# ❌ Missing init properties _args & _execs
8180

@@ -106,6 +105,11 @@ class Hello:
106105

107106
- Each new tool or feature must start from a dedicated branch from dev.
108107
- Branches must be named `feature/tool-name` or `hotfix/issue`.
108+
- Commit must be named like these:
109+
- `doc(scope): ...` for documentation updates
110+
- `feat(scope): ...` for feature developed
111+
- `fix(scope): ...` for fix applied
112+
- `refacto(scope): ...` for refactoring or code optimization
109113
- Always rebase before merging to dev.
110114
- The master branch should only receive tested and stable code.
111115
- Each merge to master must be accompanied by a versioned tag (v1.2.0, etc.).

README.md

Lines changed: 65 additions & 35 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

@@ -39,16 +39,16 @@ A multi-tool with a generic template for developing management tools like WSLBui
3939
- [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)
4040
- [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)
4141
- [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)
4342
- [random.shuffle](https://docs.python.org/3/library/random.html#random.shuffle)
43+
- [re.split](https://docs.python.org/3/library/re.html#re.split)
4444
- [readline](https://docs.python.org/3/library/readline.html)
45+
- [requests](https://pypi.org/project/requests/)
4546
- [shutil.rmtree](https://docs.python.org/3/library/shutil.html#shutil.rmtree)
4647
- [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)
4748
- [time.sleep](https://docs.python.org/3/library/time.html#time.sleep)
4849
- [traceback.format_exc](https://docs.python.org/3/library/traceback.html#traceback.format_exc)
4950

50-
> [!Note]
51-
> [readline](https://docs.python.org/3/library/readline.html) is for multiline finder in linux system
51+
> [!Note] > [readline](https://docs.python.org/3/library/readline.html) is for multiline finder in linux system
5252
5353
[Summary](#summary)
5454

@@ -65,21 +65,21 @@ To use the tool manager, you need to open a terminal prompt and run the python s
6565

6666
Usage: `$ python main.py <argument>`
6767

68-
| Arguments | Values ​ | Descriptions |
69-
| --------------------- | ------------------- | ------------------------------------------- |
70-
| `-g`, `--generate` | - | Generate a tool with interactive inputs |
71-
| `-l`, `--list` | - | Display the list of Python tools |
72-
| `-s`, `--set` | `<prop>`, `<value>` | Apply new configuration value to a property |
73-
| `-t`, `--tool` | `<tool>` | Launch a tool |
74-
| `-h`, `--help` | - | Display the help menu |
75-
| `-D`, `--debug` | - | Run in debugger mode |
76-
| `-v`, `--version` | - | Display the program version |
68+
| Arguments | Values ​ | Descriptions |
69+
| ------------------ | ------------------- | ------------------------------------------- |
70+
| `-g`, `--generate` | - | Generate a tool with interactive inputs |
71+
| `-l`, `--list` | - | Display the list of Python tools |
72+
| `-s`, `--set` | `<prop>`, `<value>` | Apply new configuration value to a property |
73+
| `-t`, `--tool` | `<tool>` | Launch a tool |
74+
| `-h`, `--help` | - | Display the help menu |
75+
| `-D`, `--debug` | - | Run in debugger mode |
76+
| `-v`, `--version` | - | Display the program version |
7777

7878
[Summary](#summary)
7979

8080
### III.2 Main Program
8181

82-
Usage: `$ python main.py`
82+
Execute the main script at the root of project folder with `$ python main.py`, when you arrived at the main menu, you can run directly all tools in registry
8383

8484
```
8585
_ _ __ __
@@ -88,12 +88,13 @@ Usage: `$ python main.py`
8888
| __/ _ \ / _ \| |/ _/|\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '__|
8989
| || (_) | (_) | _\ \ | | | (_| | | | | (_| | (_| | __/ |
9090
\__\___/ \___/|/___/_| |_|\__,_|_| |_|\__,_|\__, |\___|_|
91-
version: 0.1 |___/
91+
version: 0.3 |___/
9292
9393
List of commands:
9494
9595
(mat)rix
9696
(sh)ell
97+
(tr)anslator
9798
(wb)wslbuilder
9899
99100
(s)ettings
@@ -109,6 +110,17 @@ Usage: `$ python main.py`
109110

110111
## IV. Tool Management
111112

113+
All tools can be created with `$ python main.py -g`, after that, the program ask you 3 questions about the new tool you want to create, once the tool was created, you must import it and enter it in the tool registry at [`tools/__init__.py`](tools/__init__.py)
114+
115+
Once the tool is declared in the [tools registry](#iv2-tools-registry), you can call it in the main program or as a command argument with `-t`
116+
117+
To recognize a tool, it is imperative to follow the Tool class nomenclature, while providing the following metadata for proper management:
118+
119+
- `command`: a tuple that references the tool's command and main alias, along with its acronym for display in the main menu
120+
- `name`: a string representing the tool's name
121+
- `path`: the absolute path to the tool's file (usually declared with the constant `__file__`)
122+
- `version`: a string representing the tool's version (e.g., 0.1a, 1.0, 2.0)
123+
112124
[Summary](#summary)
113125

114126
### IV.1 Tool Structure
@@ -134,18 +146,18 @@ class Hello(Tool):
134146
version = "0.1a" # Tool version
135147

136148
def __init__(self, args: list[str]):
137-
# Initialization of Tool
138-
super().__init__()
139-
140149
# Argument registry corresponding to lamdba registry index
141150
self._args = [
142151
(("-s", "--say-hello", ""), "Say a hello world")
143-
] + self._args[:]
152+
]
144153

145154
# Lamdba registry corresponding to argument registry index
146155
self._execs = [
147156
lambda x:self._sayHello(x)
148-
] + self._execs[:]
157+
]
158+
159+
# Initialization of Tool
160+
super().__init__()
149161

150162
# _run(args) method to lauch method in lambda registry with arguments
151163
# tips: you can rewrite the methode if you want to put some exception or rules to launch
@@ -165,14 +177,32 @@ class Hello(Tool):
165177

166178
### IV.2 Tools Registry
167179

180+
To use the tool you just created, you must declare it in the tool registry by importing it into the [`tools/__init__.py`](tools/__init__.py) file and declaring it in the `TOOLS` constant
181+
182+
```python
183+
from core.tool import Tool
184+
185+
from tools.matrix import Matrix # Tool importation
186+
...
187+
188+
TOOLS: tuple[Tool] = (
189+
Matrix, # Tool declaration
190+
...
191+
)
192+
""" Tools registry """
193+
```
194+
195+
> [!note]
196+
> Eventually, this method of tool declaration will be automated in the tool generation script
197+
168198
[Summary](#summary)
169199

170200
### IV.3 Tools Index
171201

172202
| Tool | Version | Description |
173203
| -------------------------------- | ------- | ------------------------------------------ |
174204
| [Shell](docs/Shell.md) | v1.0 | Prompt interface with custom schedules |
175-
| [Translator](docs/Translator.md) | v1.0 | Translation tool manager |
205+
| [Translator](docs/Translator.md) | v1.1 | Translation tool manager |
176206
| [WSLBuilder](docs/WSLBuilder.md) | v1.1 | Managing Docker images compatible with WSL |
177207

178208
[Summary](#summary)
@@ -193,7 +223,7 @@ You can modify it directly (which is not recommended) or use the configuration p
193223

194224
> [!Note]
195225
> You can manage settings with cli command `$ python main.py -s encoding utf-8` inside a shell
196-
>
226+
>
197227
> Or directly in main config index by typing `settings` & `set encoding utf-8` inside the program
198228
199229
[Summary](#summary)

core/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from core.colors import Colors
2121
from core.config import ACCEPT_ENCODING, Config, getConfig, setConfig
22+
from core.exceptions import RequestError, ToolInitError, ValidationError
2223
from core.generate import Generate
2324
from core.icons import Icons
2425
from core.tool import Tool
@@ -27,7 +28,7 @@
2728
"author": "Florian Cardinal",
2829
"github": "https://github.com/Tracks12/toolsManager.py",
2930
"name": "toolsManager.py",
30-
"version": "0.1",
31+
"version": "0.3",
3132
})
3233
""" Contains application information such as version, git commit hash, and other metadata
3334
"""

core/exceptions.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
r""" Custom exception classes for application-level error handling.
5+
6+
This module provides a centralized place to define and manage reusable
7+
exceptions across the codebase. These exceptions are intended to replace
8+
standard Python or third-party exceptions with more meaningful, context-aware
9+
errors suited to the specific needs of the application.
10+
11+
Can include (but is not limited to):
12+
- Request/HTTP errors
13+
- Validation or input errors
14+
- Configuration errors
15+
16+
"""
17+
18+
class RequestError(Exception):
19+
20+
""" Raised when an HTTP request fails or returns an unexpected response.
21+
22+
Attributes:
23+
message (str): Description of the error.
24+
url (str): URL that triggered the exception.
25+
status_code (int): HTTP status code (if available).
26+
27+
"""
28+
29+
def __init__(self, message: str, url: str = None, status_code: int = None):
30+
super().__init__(message)
31+
32+
self.message = str(message)
33+
self.url = str(url)
34+
self.status_code = int(status_code)
35+
36+
def __str__(self) -> str:
37+
parts = list[str]([ f"RequestError: {self.message}" ])
38+
39+
if(self.url):
40+
parts.append(f"URL: {self.url}")
41+
42+
if(self.status_code):
43+
parts.append(f"Status: {self.status_code}")
44+
45+
return("\n\t| ".join(parts))
46+
47+
class ToolInitError(Exception):
48+
49+
""" Raised when a tool fails to initialize properly.
50+
51+
Attributes:
52+
tool_name (str): Name of the tool.
53+
details (str): Explanation of the failure.
54+
55+
"""
56+
57+
def __init__(self, tool_name: str, details: str):
58+
super().__init__(f"Failed to initialize tool '{tool_name}': {details}")
59+
60+
self.tool_name = str(tool_name)
61+
self.details = str(details)
62+
63+
class ValidationError(Exception):
64+
65+
""" Raised when an input or configuration value is invalid.
66+
67+
Attributes:
68+
field (str): Name of the field or parameter in error.
69+
reason (str): Explanation of why the value is invalid.
70+
71+
"""
72+
73+
def __init__(self, field: str, reason: str):
74+
super().__init__(f"Validation failed for '{field}': {reason}")
75+
76+
self.field = str(field)
77+
self.reason = str(reason)

core/generate.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,15 @@ class {classname}(Tool):
3434
version = "0.1a"
3535
3636
def __init__(self, args: list[str]):
37-
super().__init__()
38-
3937
self._args = [
4038
(("-s", "--say-hello", ""), "Say a hello world")
41-
] + self._args[:]
39+
]
4240
4341
self._execs = [
4442
lambda x:self._sayHello(x)
45-
] + self._execs[:]
43+
]
4644
45+
super().__init__()
4746
self._run(args)
4847
4948
def _sayHello(self, args: list[str]) -> bool:

0 commit comments

Comments
 (0)