[REF] script: add type hints to execute and i18n
Improve code maintainability and IDE support by adding type annotations to function signatures and instance variables in execute.py and todo_i18n.py. Also let Black simplify unnecessary parentheses. Generated by Claude Code 2.1.72 model claude-sonnet-4-6 Co-Authored-By: Mathieu Benoit <mathben@technolibre.ca>
This commit is contained in:
parent
2dde5467db
commit
4a46ebbf4c
2 changed files with 27 additions and 31 deletions
|
|
@ -35,9 +35,9 @@ _logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Execute:
|
class Execute:
|
||||||
def __init__(self):
|
def __init__(self) -> None:
|
||||||
self.cmd_source_erplibre = ""
|
self.cmd_source_erplibre: str = ""
|
||||||
self.cmd_source_default = ""
|
self.cmd_source_default: str = ""
|
||||||
exec_path_gnome_terminal = shutil.which("gnome-terminal")
|
exec_path_gnome_terminal = shutil.which("gnome-terminal")
|
||||||
if exec_path_gnome_terminal:
|
if exec_path_gnome_terminal:
|
||||||
self.cmd_source_erplibre = (
|
self.cmd_source_erplibre = (
|
||||||
|
|
@ -61,17 +61,22 @@ class Execute:
|
||||||
|
|
||||||
def exec_command_live(
|
def exec_command_live(
|
||||||
self,
|
self,
|
||||||
command,
|
command: str,
|
||||||
source_erplibre=True,
|
source_erplibre: bool = True,
|
||||||
quiet=False,
|
quiet: bool = False,
|
||||||
single_source_erplibre=False,
|
single_source_erplibre: bool = False,
|
||||||
new_window=False,
|
new_window: bool = False,
|
||||||
single_source_odoo=False,
|
single_source_odoo: bool = False,
|
||||||
source_odoo="",
|
source_odoo: str = "",
|
||||||
new_env=None,
|
new_env: dict | None = None,
|
||||||
return_status_and_command=False,
|
return_status_and_command: bool = False,
|
||||||
return_status_and_output=False,
|
return_status_and_output: bool = False,
|
||||||
return_status_and_output_and_command=False,
|
return_status_and_output_and_command: bool = False,
|
||||||
|
) -> (
|
||||||
|
int
|
||||||
|
| tuple[int, str]
|
||||||
|
| tuple[int, list[str]]
|
||||||
|
| tuple[int, str, list[str]]
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Execute a command and display its output live.
|
Execute a command and display its output live.
|
||||||
|
|
@ -95,9 +100,7 @@ class Execute:
|
||||||
command = self.cmd_source_erplibre % command
|
command = self.cmd_source_erplibre % command
|
||||||
# os.system(f"./script/terminal/open_terminal.sh {command}")
|
# os.system(f"./script/terminal/open_terminal.sh {command}")
|
||||||
elif single_source_erplibre:
|
elif single_source_erplibre:
|
||||||
command = (
|
command = f"source ./{VENV_ERPLIBRE}/bin/activate && %s" % command
|
||||||
f"source ./{VENV_ERPLIBRE}/bin/activate && %s" % command
|
|
||||||
)
|
|
||||||
elif single_source_odoo:
|
elif single_source_odoo:
|
||||||
if not source_odoo and os.path.exists("./.erplibre-version"):
|
if not source_odoo and os.path.exists("./.erplibre-version"):
|
||||||
with open("./.erplibre-version") as f:
|
with open("./.erplibre-version") as f:
|
||||||
|
|
@ -107,9 +110,7 @@ class Execute:
|
||||||
f"You cannot execute Odoo command if no version is installed. Command : {command}"
|
f"You cannot execute Odoo command if no version is installed. Command : {command}"
|
||||||
)
|
)
|
||||||
return -1
|
return -1
|
||||||
command = (
|
command = f"source ./.venv.{source_odoo}/bin/activate && {command}"
|
||||||
f"source ./.venv.{source_odoo}/bin/activate && {command}"
|
|
||||||
)
|
|
||||||
if new_window and self.cmd_source_default:
|
if new_window and self.cmd_source_default:
|
||||||
command = self.cmd_source_default % command
|
command = self.cmd_source_default % command
|
||||||
|
|
||||||
|
|
@ -151,10 +152,7 @@ class Execute:
|
||||||
process.wait()
|
process.wait()
|
||||||
exit_code = process.returncode
|
exit_code = process.returncode
|
||||||
if process.returncode != 0 and not quiet:
|
if process.returncode != 0 and not quiet:
|
||||||
print(
|
print("Command returned error code:" f" {process.returncode}")
|
||||||
"Command returned error code:"
|
|
||||||
f" {process.returncode}"
|
|
||||||
)
|
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
|
|
@ -164,9 +162,7 @@ class Execute:
|
||||||
" not found."
|
" not found."
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print(
|
print(f"Error: Command '{command}' not found.")
|
||||||
f"Error: Command '{command}' not found."
|
|
||||||
)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print(f"An error occurred: {e}")
|
print(f"An error occurred: {e}")
|
||||||
|
|
|
||||||
|
|
@ -554,7 +554,7 @@ TRANSLATIONS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_lang():
|
def get_lang() -> str:
|
||||||
global _current_lang
|
global _current_lang
|
||||||
if _current_lang is not None:
|
if _current_lang is not None:
|
||||||
return _current_lang
|
return _current_lang
|
||||||
|
|
@ -586,7 +586,7 @@ def get_lang():
|
||||||
return _current_lang
|
return _current_lang
|
||||||
|
|
||||||
|
|
||||||
def set_lang(lang):
|
def set_lang(lang: str) -> None:
|
||||||
global _current_lang
|
global _current_lang
|
||||||
_current_lang = lang
|
_current_lang = lang
|
||||||
|
|
||||||
|
|
@ -614,7 +614,7 @@ def set_lang(lang):
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
|
|
||||||
def lang_is_configured():
|
def lang_is_configured() -> bool:
|
||||||
"""Check if a language has been explicitly set."""
|
"""Check if a language has been explicitly set."""
|
||||||
if os.path.exists(ENV_VAR_FILE):
|
if os.path.exists(ENV_VAR_FILE):
|
||||||
try:
|
try:
|
||||||
|
|
@ -626,7 +626,7 @@ def lang_is_configured():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def t(key):
|
def t(key: str) -> str:
|
||||||
entry = TRANSLATIONS.get(key)
|
entry = TRANSLATIONS.get(key)
|
||||||
if entry is None:
|
if entry is None:
|
||||||
return key
|
return key
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue