mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-05 04:08:21 +02:00
compacted _tools_run, _tools_run_popen and _tools_run_dict by creating a get function returning the shortcut function for every module from the tools_path
This commit is contained in:
parent
804c9f38f6
commit
d9ec57a04c
6 changed files with 42 additions and 84 deletions
|
@ -1,6 +1,7 @@
|
|||
import subprocess
|
||||
from pathlib import Path
|
||||
import os
|
||||
from typing import Callable
|
||||
|
||||
|
||||
class WTError(Exception):
|
||||
|
@ -53,7 +54,7 @@ def better_wt_error(tools_path: Path | str):
|
|||
return decorator
|
||||
|
||||
|
||||
def _run(tools_path: Path | str, *args) -> bytes:
|
||||
def _run(tools_path: Path | str, *args, **kwargs) -> bytes:
|
||||
"""
|
||||
Run a command and return the output
|
||||
:param args: command arguments
|
||||
|
@ -67,7 +68,16 @@ def _run(tools_path: Path | str, *args) -> bytes:
|
|||
).stdout
|
||||
|
||||
|
||||
def _run_dict(tools_path: Path | str, *args) -> dict:
|
||||
def get_tools_run_function(tools_path: Path | str) -> Callable:
|
||||
"""
|
||||
Return a new function with the tool argument already entered
|
||||
:param tools_path: path to the tool
|
||||
:return: new function
|
||||
"""
|
||||
return lambda *args, **kwargs: better_wt_error(tools_path)(_run)(tools_path, *args, **kwargs)
|
||||
|
||||
|
||||
def _run_dict(tools_path: Path | str, *args, **kwargs) -> dict:
|
||||
"""
|
||||
Return a dictionary of a command that return value associated to a key with a equal sign
|
||||
:param tools_path: tools to use
|
||||
|
@ -92,6 +102,15 @@ def _run_dict(tools_path: Path | str, *args) -> dict:
|
|||
return d
|
||||
|
||||
|
||||
def get_tools_run_dict_function(tools_path: Path | str) -> Callable:
|
||||
"""
|
||||
Return a new function with the tool argument already entered
|
||||
:param tools_path: path to the tool
|
||||
:return: new function
|
||||
"""
|
||||
return lambda *args, **kwargs: better_wt_error(tools_path)(_run_dict)(tools_path, *args, **kwargs)
|
||||
|
||||
|
||||
def _run_popen(tools_path: Path | str, *args, universal_newlines=False) -> subprocess.Popen:
|
||||
"""
|
||||
Run a command and return the process
|
||||
|
@ -106,3 +125,12 @@ def _run_popen(tools_path: Path | str, *args, universal_newlines=False) -> subpr
|
|||
bufsize=1 if universal_newlines else None,
|
||||
universal_newlines=universal_newlines,
|
||||
)
|
||||
|
||||
|
||||
def get_tools_run_popen_function(tools_path: Path | str) -> Callable:
|
||||
"""
|
||||
Return a new function with the tool argument already entered
|
||||
:param tools_path: path to the tool
|
||||
:return: new function
|
||||
"""
|
||||
return lambda *args, **kwargs: _run_popen(tools_path, *args, **kwargs)
|
||||
|
|
|
@ -1,26 +1,10 @@
|
|||
from source.wt import *
|
||||
from source.wt import _run, _run_popen
|
||||
|
||||
tools_path = tools_szs_dir / ("wimgt.exe" if system == "win64" else "wimgt")
|
||||
|
||||
|
||||
@better_wt_error(tools_path)
|
||||
def _tools_run(*args) -> bytes:
|
||||
"""
|
||||
Return a command with wbmgt and return the output
|
||||
:param args: command arguments
|
||||
:return: the output of the command
|
||||
"""
|
||||
return _run(tools_path, *args)
|
||||
|
||||
|
||||
def _tools_run_popen(*args, **kwargs) -> subprocess.Popen:
|
||||
"""
|
||||
Return a popen of command with wbmgt
|
||||
:param args: command arguments
|
||||
:return: the process of the command
|
||||
"""
|
||||
return _run_popen(tools_path, *args, **kwargs)
|
||||
_tools_run = get_tools_run_function(tools_path)
|
||||
_tools_run_popen = get_tools_run_popen_function(tools_path)
|
||||
|
||||
|
||||
class BMGPath:
|
||||
|
|
|
@ -1,26 +1,10 @@
|
|||
from source.wt import *
|
||||
from source.wt import _run, _run_popen
|
||||
|
||||
tools_path = tools_szs_dir / ("wimgt.exe" if system == "win64" else "wimgt")
|
||||
|
||||
|
||||
@better_wt_error(tools_path)
|
||||
def _tools_run(*args) -> bytes:
|
||||
"""
|
||||
Return a command with wimgt and return the output
|
||||
:param args: command arguments
|
||||
:return: the output of the command
|
||||
"""
|
||||
return _run(tools_path, *args)
|
||||
|
||||
|
||||
def _tools_run_popen(*args) -> subprocess.Popen:
|
||||
"""
|
||||
Return a popen of command with wimgt
|
||||
:param args: command arguments
|
||||
:return: the process of the command
|
||||
"""
|
||||
return _run_popen(tools_path, *args)
|
||||
_tools_run = get_tools_run_function(tools_path)
|
||||
_tools_run_popen = get_tools_run_popen_function(tools_path)
|
||||
|
||||
|
||||
@better_wt_error(tools_path)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
from source.wt import *
|
||||
|
||||
tools_path = tools_szs_dir / ("wstrt.exe" if system == "win64" else "wstrt")
|
|
@ -4,24 +4,8 @@ from source.wt import _run, _run_dict
|
|||
tools_path = tools_szs_dir / ("wszst.exe" if system == "win64" else "wszst")
|
||||
|
||||
|
||||
@better_wt_error(tools_path)
|
||||
def _tools_run(*args) -> bytes:
|
||||
"""
|
||||
Return a command with wszst and return the output
|
||||
:param args: command arguments
|
||||
:return: the output of the command
|
||||
"""
|
||||
return _run(tools_path, *args)
|
||||
|
||||
|
||||
@better_wt_error(tools_path)
|
||||
def _tools_run_dict(*args) -> dict:
|
||||
"""
|
||||
Return a dictionary of a command that return value associated to a key with a equal sign
|
||||
:param args: others arguments
|
||||
:return: the dictionary
|
||||
"""
|
||||
return _run_dict(tools_path, *args)
|
||||
_tools_run = get_tools_run_function(tools_path)
|
||||
_tools_run_dict = get_tools_run_dict_function(tools_path)
|
||||
|
||||
|
||||
@better_wt_error(tools_path)
|
||||
|
|
|
@ -4,38 +4,13 @@ import shutil
|
|||
from typing import Generator
|
||||
|
||||
from source.wt import *
|
||||
from source.wt import _run, _run_dict, _run_popen
|
||||
|
||||
tools_path = tools_wit_dir / ("wit.exe" if system == "win64" else "wit")
|
||||
|
||||
|
||||
@better_wt_error(tools_path)
|
||||
def _tools_run(*args) -> bytes:
|
||||
"""
|
||||
Return a command with wit and return the output
|
||||
:param args: command arguments
|
||||
:return: the output of the command
|
||||
"""
|
||||
return _run(tools_path, *args)
|
||||
|
||||
|
||||
def _tools_run_popen(*args, **kwargs) -> subprocess.Popen:
|
||||
"""
|
||||
Return a command with wit and return the output
|
||||
:param args: command arguments
|
||||
:return: the output of the command
|
||||
"""
|
||||
return _run_popen(tools_path, *args, **kwargs)
|
||||
|
||||
|
||||
@better_wt_error(tools_path)
|
||||
def _tools_run_dict(*args) -> dict:
|
||||
"""
|
||||
Return a dictionary of a command that return value associated to a key with a equal sign
|
||||
:param args: others arguments
|
||||
:return: the dictionary
|
||||
"""
|
||||
return _run_dict(tools_path, *args)
|
||||
_tools_run = get_tools_run_function(tools_path)
|
||||
_tools_run_dict = get_tools_run_dict_function(tools_path)
|
||||
_tools_run_popen = get_tools_run_popen_function(tools_path)
|
||||
|
||||
|
||||
class Extension(enum.Enum):
|
||||
|
|
Loading…
Reference in a new issue