A multi-tool with a generic template for developing management tools like WSLBuilder for managing WSL instances built using images exported from Docker.
Important
Installing Python 3 is recommended to run this script on Windows.
- base64.b64decode, base64.b64encode
- json.loads, json.dumps, json.load, json.dump
- os.listdir, os.mkdir, os.remove, os.rmdir, os.system, os.path
- platform.system
- random.shuffle
- re.split
- readline
- requests
- shutil.rmtree
- sys.argv, sys.version_info
- time.sleep
- traceback.format_exc
[!Note] > readline is for multiline finder in linux system
To use the tool manager, you need to open a terminal prompt and run the python script at the root of the project
Important
Some tools present in the registry have dependencies contained in the libs/
folder in the form of a *.rar
file, you must unzip them by typing the command $ python setup.py
Usage: $ python main.py <argument>
Arguments | Values | Descriptions |
---|---|---|
-g , --generate |
- | Generate a tool with interactive inputs |
-l , --list |
- | Display the list of Python tools |
-s , --set |
<prop> , <value> |
Apply new configuration value to a property |
-t , --tool |
<tool> |
Launch a tool |
-h , --help |
- | Display the help menu |
-D , --debug |
- | Run in debugger mode |
-v , --version |
- | Display the program version |
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
_ _ __ __
| | | | | \/ |
| |_ ___ ___ | | _|_\ / | __ _ _ __ __ _ __ _ ___ _ __
| __/ _ \ / _ \| |/ _/|\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '__|
| || (_) | (_) | _\ \ | | | (_| | | | | (_| | (_| | __/ |
\__\___/ \___/|/___/_| |_|\__,_|_| |_|\__,_|\__, |\___|_|
version: 0.3 |___/
List of commands:
(mat)rix
(sh)ell
(tr)anslator
(wb)wslbuilder
(s)ettings
(v)ersion
(h)elp
(q)uit
(toolsManager.py)>
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
Once the tool is declared in the tools registry, you can call it in the main program or as a command argument with -t
To recognize a tool, it is imperative to follow the Tool class nomenclature, while providing the following metadata for proper management:
command
: a tuple that references the tool's command and main alias, along with its acronym for display in the main menuname
: a string representing the tool's namepath
: the absolute path to the tool's file (usually declared with the constant__file__
)version
: a string representing the tool's version (e.g., 0.1a, 1.0, 2.0)
Here you will find a typical example of a tool structure:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# tools/hello.py
# Importation of the tool model
from core.tool import Tool
class Hello(Tool):
""" Say hello to the user
"""
command = (("hello", "hel"), "(hel)lo") # The launch command control by name or alias
name = "Hello" # Tool name
path = __file__ # Path of tool file
version = "0.1a" # Tool version
def __init__(self, args: list[str]):
# Argument registry corresponding to lamdba registry index
self._args = [
(("-s", "--say-hello", ""), "Say a hello world")
]
# Lamdba registry corresponding to argument registry index
self._execs = [
lambda x:self._sayHello(x)
]
# Initialization of Tool
super().__init__()
# _run(args) method to lauch method in lambda registry with arguments
# tips: you can rewrite the methode if you want to put some exception or rules to launch
self._run(args)
def _sayHello(self, args: list[str]) -> bool:
print(f"Hello world :D")
return(True)
# ...
Tip
Since the last update, you can create you own tool by typing $ python main.py -g
To use the tool you just created, you must declare it in the tool registry by importing it into the tools/__init__.py
file and declaring it in the TOOLS
constant
from core.tool import Tool
from tools.matrix import Matrix # Tool importation
...
TOOLS: tuple[Tool] = (
Matrix, # Tool declaration
...
)
""" Tools registry """
Note
Eventually, this method of tool declaration will be automated in the tool generation script
Tool | Version | Description |
---|---|---|
Shell | v1.0 | Prompt interface with custom schedules |
Translator | v1.1 | Translation tool manager |
WSLBuilder | v1.1 | Managing Docker images compatible with WSL |
The program is configured from the config.json file in json format. In this file, you can set the character encoding and the splash screen display.
{
"colors": false,
"encoding": "utf-8",
"splash": true
}
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.
Note
You can manage settings with cli command $ python main.py -s encoding utf-8
inside a shell
Or directly in main config index by typing settings
& set encoding utf-8
inside the program
If you to contribute to the project, you access to the coding guideline at CONTRIBUTING.md
Code licensed under GPL v3