phobos-templates-utils 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- phobos_templates_utils-0.0.1/PKG-INFO +23 -0
- phobos_templates_utils-0.0.1/README.md +5 -0
- phobos_templates_utils-0.0.1/phobos_templates_utils.egg-info/PKG-INFO +23 -0
- phobos_templates_utils-0.0.1/phobos_templates_utils.egg-info/SOURCES.txt +15 -0
- phobos_templates_utils-0.0.1/phobos_templates_utils.egg-info/dependency_links.txt +1 -0
- phobos_templates_utils-0.0.1/phobos_templates_utils.egg-info/requires.txt +5 -0
- phobos_templates_utils-0.0.1/phobos_templates_utils.egg-info/top_level.txt +1 -0
- phobos_templates_utils-0.0.1/pyproject.toml +32 -0
- phobos_templates_utils-0.0.1/setup.cfg +4 -0
- phobos_templates_utils-0.0.1/torizon_templates_utils/__init__.py +0 -0
- phobos_templates_utils-0.0.1/torizon_templates_utils/animations.py +67 -0
- phobos_templates_utils-0.0.1/torizon_templates_utils/args.py +83 -0
- phobos_templates_utils-0.0.1/torizon_templates_utils/colors.py +56 -0
- phobos_templates_utils-0.0.1/torizon_templates_utils/debug.py +22 -0
- phobos_templates_utils-0.0.1/torizon_templates_utils/errors.py +58 -0
- phobos_templates_utils-0.0.1/torizon_templates_utils/network.py +35 -0
- phobos_templates_utils-0.0.1/torizon_templates_utils/tasks.py +941 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: phobos-templates-utils
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Package with utilities for Phobos Templates scripts
|
|
5
|
+
Author-email: Matheus Castello <matheus@castello.eng.br>
|
|
6
|
+
Project-URL: Homepage, https://github.com/gaiaBuildSystem/vscode-phobos-templates
|
|
7
|
+
Project-URL: Issues, https://github.com/gaiaBuildSystem/vscode-phobos-templates/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: torizon-io-api
|
|
14
|
+
Requires-Dist: requests
|
|
15
|
+
Requires-Dist: pyyaml
|
|
16
|
+
Requires-Dist: debugpy
|
|
17
|
+
Requires-Dist: pkginfo>=1.12
|
|
18
|
+
|
|
19
|
+
# Phobos Templates Utils
|
|
20
|
+
|
|
21
|
+
This package contains a set of utilities to help the scripts that generate the Torizon OS applications and containers.
|
|
22
|
+
|
|
23
|
+
If you want to know more about check [Toradex developer website](https://developer.toradex.com/torizon/application-development/ide-extension/).
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Phobos Templates Utils
|
|
2
|
+
|
|
3
|
+
This package contains a set of utilities to help the scripts that generate the Torizon OS applications and containers.
|
|
4
|
+
|
|
5
|
+
If you want to know more about check [Toradex developer website](https://developer.toradex.com/torizon/application-development/ide-extension/).
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: phobos-templates-utils
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Package with utilities for Phobos Templates scripts
|
|
5
|
+
Author-email: Matheus Castello <matheus@castello.eng.br>
|
|
6
|
+
Project-URL: Homepage, https://github.com/gaiaBuildSystem/vscode-phobos-templates
|
|
7
|
+
Project-URL: Issues, https://github.com/gaiaBuildSystem/vscode-phobos-templates/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: torizon-io-api
|
|
14
|
+
Requires-Dist: requests
|
|
15
|
+
Requires-Dist: pyyaml
|
|
16
|
+
Requires-Dist: debugpy
|
|
17
|
+
Requires-Dist: pkginfo>=1.12
|
|
18
|
+
|
|
19
|
+
# Phobos Templates Utils
|
|
20
|
+
|
|
21
|
+
This package contains a set of utilities to help the scripts that generate the Torizon OS applications and containers.
|
|
22
|
+
|
|
23
|
+
If you want to know more about check [Toradex developer website](https://developer.toradex.com/torizon/application-development/ide-extension/).
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
phobos_templates_utils.egg-info/PKG-INFO
|
|
4
|
+
phobos_templates_utils.egg-info/SOURCES.txt
|
|
5
|
+
phobos_templates_utils.egg-info/dependency_links.txt
|
|
6
|
+
phobos_templates_utils.egg-info/requires.txt
|
|
7
|
+
phobos_templates_utils.egg-info/top_level.txt
|
|
8
|
+
torizon_templates_utils/__init__.py
|
|
9
|
+
torizon_templates_utils/animations.py
|
|
10
|
+
torizon_templates_utils/args.py
|
|
11
|
+
torizon_templates_utils/colors.py
|
|
12
|
+
torizon_templates_utils/debug.py
|
|
13
|
+
torizon_templates_utils/errors.py
|
|
14
|
+
torizon_templates_utils/network.py
|
|
15
|
+
torizon_templates_utils/tasks.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
torizon_templates_utils
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=70.0", "pkginfo>=1.12"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "phobos-templates-utils"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Matheus Castello", email="matheus@castello.eng.br" },
|
|
10
|
+
]
|
|
11
|
+
description = "Package with utilities for Phobos Templates scripts"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: POSIX :: Linux",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"torizon-io-api",
|
|
21
|
+
"requests",
|
|
22
|
+
"pyyaml",
|
|
23
|
+
"debugpy",
|
|
24
|
+
"pkginfo>=1.12"
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[tool.setuptools]
|
|
28
|
+
license-files = []
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/gaiaBuildSystem/vscode-phobos-templates"
|
|
32
|
+
Issues = "https://github.com/gaiaBuildSystem/vscode-phobos-templates/issues"
|
|
File without changes
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import time
|
|
3
|
+
import threading
|
|
4
|
+
from itertools import cycle
|
|
5
|
+
|
|
6
|
+
def run_command_with_wait_animation(call, *args):
|
|
7
|
+
anima_frames = ["🕐", "🕑", "🕒", "🕓", "🕔", "🕕", "🕖", "🕗", "🕘", "🕙", "🕚", "🕛"]
|
|
8
|
+
|
|
9
|
+
def animate():
|
|
10
|
+
for frame in cycle(anima_frames):
|
|
11
|
+
if not running[0]:
|
|
12
|
+
break
|
|
13
|
+
sys.stdout.write(f"\r{frame} :: RUNNING PLEASE WAIT :: {frame}")
|
|
14
|
+
sys.stdout.flush()
|
|
15
|
+
time.sleep(0.1)
|
|
16
|
+
|
|
17
|
+
# Clear the line
|
|
18
|
+
sys.stdout.write("\r\x1b[2K")
|
|
19
|
+
|
|
20
|
+
if running[1]:
|
|
21
|
+
sys.stdout.write("❌ :: TASK FAILED :: ❌\n")
|
|
22
|
+
else:
|
|
23
|
+
sys.stdout.write("✅ :: TASK COMPLETED :: ✅\n")
|
|
24
|
+
|
|
25
|
+
# clear anything the command printed below the animation line
|
|
26
|
+
# while it was pinned (e.g. the scan live device list)
|
|
27
|
+
sys.stdout.write("\x1b[J")
|
|
28
|
+
sys.stdout.flush()
|
|
29
|
+
|
|
30
|
+
def target():
|
|
31
|
+
nonlocal output
|
|
32
|
+
try:
|
|
33
|
+
output = call(*args)
|
|
34
|
+
except Exception as e:
|
|
35
|
+
output = e
|
|
36
|
+
running[1] = True
|
|
37
|
+
finally:
|
|
38
|
+
running[0] = False
|
|
39
|
+
|
|
40
|
+
# [0] is if it's running [1] if it has failed
|
|
41
|
+
running = [True, False]
|
|
42
|
+
output = None
|
|
43
|
+
|
|
44
|
+
animation_thread = threading.Thread(target=animate)
|
|
45
|
+
command_thread = threading.Thread(target=target)
|
|
46
|
+
|
|
47
|
+
animation_thread.start()
|
|
48
|
+
command_thread.start()
|
|
49
|
+
|
|
50
|
+
command_thread.join()
|
|
51
|
+
animation_thread.join()
|
|
52
|
+
|
|
53
|
+
if isinstance(output, Exception):
|
|
54
|
+
raise output
|
|
55
|
+
|
|
56
|
+
return output
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# # Example usage
|
|
60
|
+
# def example_script(duration):
|
|
61
|
+
# time.sleep(duration)
|
|
62
|
+
# return "Task finished"
|
|
63
|
+
|
|
64
|
+
# if __name__ == "__main__":
|
|
65
|
+
# print("LET'S RUN A SCRIPT THAT TAKES 5 SECONDS TO FINISH")
|
|
66
|
+
# result = run_command_in_background_with_wait_animation(example_script, 5)
|
|
67
|
+
# print(result)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
|
|
2
|
+
import sys
|
|
3
|
+
from typing import TypeVar, Type
|
|
4
|
+
from torizon_templates_utils.errors import Error, Error_Out
|
|
5
|
+
|
|
6
|
+
T = TypeVar('T')
|
|
7
|
+
|
|
8
|
+
def get_arg_not_empty(index: int) -> str:
|
|
9
|
+
"""
|
|
10
|
+
Get an argument from the command line.
|
|
11
|
+
If the argument is an empty string, an error is raised.
|
|
12
|
+
"""
|
|
13
|
+
_arg = sys.argv[index]
|
|
14
|
+
|
|
15
|
+
if _arg == "":
|
|
16
|
+
Error_Out(
|
|
17
|
+
"Error: Argument cannot be empty",
|
|
18
|
+
Error.EUSER
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
return _arg
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_optional_arg(index: int, default: T) -> T | bool | str:
|
|
25
|
+
"""
|
|
26
|
+
Get an optional argument from the command line.
|
|
27
|
+
If the argument is not provided, the default value is returned.
|
|
28
|
+
"""
|
|
29
|
+
if len(sys.argv) > index:
|
|
30
|
+
# sys.argv return string
|
|
31
|
+
# we need to return T
|
|
32
|
+
# FIXME: this only convert string to bool for now
|
|
33
|
+
if type(default) is bool:
|
|
34
|
+
if sys.argv[index] == "True" or sys.argv[index] == "true" or sys.argv[index] == "1":
|
|
35
|
+
return True
|
|
36
|
+
else:
|
|
37
|
+
return False
|
|
38
|
+
|
|
39
|
+
return sys.argv[index]
|
|
40
|
+
|
|
41
|
+
return default
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_arg_iterative(
|
|
45
|
+
index: int, prompt: str, default_type: Type, default: T | None = None, iterative: bool = False
|
|
46
|
+
) -> T | None | bool | str:
|
|
47
|
+
"""
|
|
48
|
+
Get an argument from the command line.
|
|
49
|
+
If the argument is not provided, an error is raised.
|
|
50
|
+
"""
|
|
51
|
+
if len(sys.argv) > index:
|
|
52
|
+
if default_type is bool:
|
|
53
|
+
if sys.argv[index] == "True":
|
|
54
|
+
return True
|
|
55
|
+
else:
|
|
56
|
+
return False
|
|
57
|
+
|
|
58
|
+
return sys.argv[index]
|
|
59
|
+
elif default != None:
|
|
60
|
+
return default
|
|
61
|
+
elif iterative:
|
|
62
|
+
_input = input(prompt)
|
|
63
|
+
if _input == "":
|
|
64
|
+
Error_Out(
|
|
65
|
+
"Error: Argument cannot be empty",
|
|
66
|
+
Error.EUSER
|
|
67
|
+
)
|
|
68
|
+
else:
|
|
69
|
+
if default_type is bool:
|
|
70
|
+
if _input == "True":
|
|
71
|
+
return True
|
|
72
|
+
else:
|
|
73
|
+
return False
|
|
74
|
+
|
|
75
|
+
return _input
|
|
76
|
+
|
|
77
|
+
else:
|
|
78
|
+
Error_Out(
|
|
79
|
+
f"Error: Argument for prompt [{prompt}] not provided",
|
|
80
|
+
Error.EUSER
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
return default
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
|
|
2
|
+
import builtins
|
|
3
|
+
import enum
|
|
4
|
+
|
|
5
|
+
class Color(enum.IntEnum):
|
|
6
|
+
NONE = 0
|
|
7
|
+
BLACK = 30
|
|
8
|
+
RED = 31
|
|
9
|
+
GREEN = 32
|
|
10
|
+
YELLOW = 33
|
|
11
|
+
BLUE = 34
|
|
12
|
+
MAGENTA = 35
|
|
13
|
+
CYAN = 36
|
|
14
|
+
WHITE = 37
|
|
15
|
+
|
|
16
|
+
class BgColor(enum.IntEnum):
|
|
17
|
+
NONE = 0
|
|
18
|
+
BLACK = 40
|
|
19
|
+
RED = 41
|
|
20
|
+
BRIGTH_RED = 101
|
|
21
|
+
GREEN = 42
|
|
22
|
+
BRIGTH_GREEN = 102
|
|
23
|
+
YELLOW = 43
|
|
24
|
+
BRIGTH_YELLOW = 103
|
|
25
|
+
BLUE = 44
|
|
26
|
+
BRIGTH_BLUE = 104
|
|
27
|
+
MAGENTA = 45
|
|
28
|
+
BRIGTH_MAGENTA = 105
|
|
29
|
+
CYAN = 46
|
|
30
|
+
BRIGTH_CYAN = 106
|
|
31
|
+
WHITE = 47
|
|
32
|
+
BRIGTH_WHITE = 107
|
|
33
|
+
|
|
34
|
+
# override print to have color and background color
|
|
35
|
+
def print(
|
|
36
|
+
*args,
|
|
37
|
+
color: Color = Color.NONE,
|
|
38
|
+
bg_color: BgColor = BgColor.NONE,
|
|
39
|
+
**kwargs
|
|
40
|
+
) -> None:
|
|
41
|
+
_color: int = color.value
|
|
42
|
+
_bg_color: int = bg_color.value
|
|
43
|
+
|
|
44
|
+
start_escape = ""
|
|
45
|
+
|
|
46
|
+
if _color != 0 and _bg_color != 0:
|
|
47
|
+
start_escape += f"\033[{_color};{_bg_color}m"
|
|
48
|
+
elif _color != 0:
|
|
49
|
+
start_escape += f"\033[{_color}m"
|
|
50
|
+
elif _bg_color != 0:
|
|
51
|
+
start_escape += f"\033[{_bg_color}m"
|
|
52
|
+
|
|
53
|
+
end_escape = "\033[0m"
|
|
54
|
+
|
|
55
|
+
text = ' '.join(map(str, args))
|
|
56
|
+
builtins.print(f'{start_escape}{text}{end_escape}', **kwargs)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# pylint: disable=missing-function-docstring
|
|
2
|
+
# pylint: disable=missing-module-docstring
|
|
3
|
+
import debugpy # type: ignore[import-untyped]
|
|
4
|
+
|
|
5
|
+
DEBUG_INITIALIZED = False
|
|
6
|
+
|
|
7
|
+
def vscode_prepare(port: int = 5679) -> None:
|
|
8
|
+
global DEBUG_INITIALIZED
|
|
9
|
+
|
|
10
|
+
if DEBUG_INITIALIZED:
|
|
11
|
+
return
|
|
12
|
+
|
|
13
|
+
print("__debugpy__")
|
|
14
|
+
debugpy.listen(("0.0.0.0", port))
|
|
15
|
+
print("__debugpy__ go")
|
|
16
|
+
debugpy.wait_for_client()
|
|
17
|
+
print(f"__debugpy__ is connected [{debugpy.is_client_connected()}]")
|
|
18
|
+
|
|
19
|
+
DEBUG_INITIALIZED = True
|
|
20
|
+
|
|
21
|
+
def breakpoint() -> None:
|
|
22
|
+
debugpy.breakpoint()
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
import sys
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from torizon_templates_utils.colors import Color, BgColor, print
|
|
5
|
+
|
|
6
|
+
class _error_struct:
|
|
7
|
+
code: int
|
|
8
|
+
message: str
|
|
9
|
+
|
|
10
|
+
def __init__(self, code: int, message: str):
|
|
11
|
+
self.code = code
|
|
12
|
+
self.message = message
|
|
13
|
+
|
|
14
|
+
# Standard Unix errors. There may be other standard error codes also:
|
|
15
|
+
# https://github.com/kaushalparikh/nuttx/blob/master/include/errno.h
|
|
16
|
+
class Error(Enum):
|
|
17
|
+
ENOCONF = _error_struct(
|
|
18
|
+
1, "Not configured"
|
|
19
|
+
)
|
|
20
|
+
EINVAL = _error_struct(
|
|
21
|
+
22, "Invalid argument"
|
|
22
|
+
)
|
|
23
|
+
ENOPKG = _error_struct(
|
|
24
|
+
65, "Package not installed"
|
|
25
|
+
)
|
|
26
|
+
EUSER = _error_struct(
|
|
27
|
+
69, "User fault"
|
|
28
|
+
)
|
|
29
|
+
EABORT = _error_struct(
|
|
30
|
+
170, "Abort"
|
|
31
|
+
)
|
|
32
|
+
ETASKEXEC = _error_struct(
|
|
33
|
+
310, "Task execution error"
|
|
34
|
+
)
|
|
35
|
+
ENOFOUND = _error_struct(
|
|
36
|
+
404, "Not found"
|
|
37
|
+
)
|
|
38
|
+
EFAIL = _error_struct(
|
|
39
|
+
500, "Failed"
|
|
40
|
+
)
|
|
41
|
+
EUNKNOWN = _error_struct(
|
|
42
|
+
666, "Unknown error"
|
|
43
|
+
)
|
|
44
|
+
ETOMCRUISE = _error_struct(
|
|
45
|
+
999, "Impossible condition"
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def Error_Out(msg: str, error: Error) -> None:
|
|
50
|
+
print(f"\n{msg}", color=Color.RED)
|
|
51
|
+
print(f"Error cause: {error.value.message}\n", color=Color.RED)
|
|
52
|
+
sys.exit(error.value.code)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def last_return_code() -> int:
|
|
56
|
+
# we are ignoring the type here because this will get the current
|
|
57
|
+
# xonsh shell instance
|
|
58
|
+
return __xonsh__.last.returncode # type: ignore
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
import os
|
|
3
|
+
import re
|
|
4
|
+
import subprocess
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def get_host_ip():
|
|
8
|
+
if 'WSL_DISTRO_NAME' in os.environ and os.environ['WSL_DISTRO_NAME'] != '':
|
|
9
|
+
command = ["/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe", "-c", '(Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias (Get-NetRoute -DestinationPrefix "0.0.0.0/0").InterfaceAlias).IPAddress']
|
|
10
|
+
|
|
11
|
+
# if inside a container we need to run the command in the host
|
|
12
|
+
if "APOLLOX_CONTAINER" in os.environ:
|
|
13
|
+
command = [
|
|
14
|
+
"sudo", "nsenter", "-t", "1", "-m", "-u", "-n", "-i",
|
|
15
|
+
"--",
|
|
16
|
+
"/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe", "-c", '(Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias (Get-NetRoute -DestinationPrefix "0.0.0.0/0").InterfaceAlias).IPAddress'
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
result = subprocess.run(command, capture_output=True, text=True)
|
|
20
|
+
ip_address = re.search(r'((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])', result.stdout)
|
|
21
|
+
if ip_address:
|
|
22
|
+
return ip_address.group(0)
|
|
23
|
+
else:
|
|
24
|
+
command = ["hostname", "-I"]
|
|
25
|
+
|
|
26
|
+
# if inside a container we need to run the command in the host
|
|
27
|
+
if "APOLLOX_CONTAINER" in os.environ:
|
|
28
|
+
command = [
|
|
29
|
+
"sudo", "nsenter", "-t", "1", "-m", "-u", "-n", "-i",
|
|
30
|
+
"--",
|
|
31
|
+
"hostname", "-I"
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
result = subprocess.run(command, capture_output=True, text=True)
|
|
35
|
+
return result.stdout.split()[0]
|