mfd-base-tool 0.1.0__py3-none-any.whl
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.
- mfd_base_tool/__init__.py +5 -0
- mfd_base_tool/exceptions.py +13 -0
- mfd_base_tool/mfd_base_tool.py +129 -0
- mfd_base_tool-0.1.0.dist-info/METADATA +67 -0
- mfd_base_tool-0.1.0.dist-info/RECORD +9 -0
- mfd_base_tool-0.1.0.dist-info/WHEEL +5 -0
- mfd_base_tool-0.1.0.dist-info/licenses/AUTHORS.md +7 -0
- mfd_base_tool-0.1.0.dist-info/licenses/LICENSE.md +8 -0
- mfd_base_tool-0.1.0.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright (C) 2025 Intel Corporation
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Module for exceptions."""
|
|
4
|
+
|
|
5
|
+
import subprocess
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ToolException(subprocess.CalledProcessError):
|
|
9
|
+
"""Handle tool exceptions."""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ToolNotAvailable(ToolException):
|
|
13
|
+
"""Handle tool not available exception."""
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Copyright (C) 2025 Intel Corporation
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Main module."""
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
import typing
|
|
7
|
+
from abc import ABC, abstractmethod
|
|
8
|
+
from pathlib import Path, PurePosixPath, PureWindowsPath
|
|
9
|
+
from typing import Optional, Union, Dict
|
|
10
|
+
from mfd_typing import OSType
|
|
11
|
+
from mfd_common_libs import add_logging_level, log_levels
|
|
12
|
+
|
|
13
|
+
if typing.TYPE_CHECKING:
|
|
14
|
+
from mfd_connect import Connection
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
add_logging_level("MODULE_DEBUG", log_levels.MODULE_DEBUG)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ToolTemplate(ABC):
|
|
21
|
+
"""
|
|
22
|
+
Class for abstraction for Tool.
|
|
23
|
+
|
|
24
|
+
eg.
|
|
25
|
+
>>>class MyTool(ToolTemplate):
|
|
26
|
+
...
|
|
27
|
+
...tool_executable_name = {OSType.WINDOWS : "samplew64e.exe", OSType.POSIX : "sample64e"}
|
|
28
|
+
or
|
|
29
|
+
>>>tool_executable_name = "sample64e"
|
|
30
|
+
... def __init__(self, *args, **kwargs):
|
|
31
|
+
... super().__init__(*args, **kwargs)
|
|
32
|
+
...
|
|
33
|
+
... def _get_tool_exec_factory(self) -> str:
|
|
34
|
+
... return self.tool_executable_name
|
|
35
|
+
...
|
|
36
|
+
... def check_if_available(self) -> None:
|
|
37
|
+
... if not "if statement for check":
|
|
38
|
+
... raise MyToolNotAvailable()
|
|
39
|
+
...
|
|
40
|
+
... def get_version(self) -> str:
|
|
41
|
+
... return "my read tool version"
|
|
42
|
+
...
|
|
43
|
+
... def my_tool_method(self):
|
|
44
|
+
... pass
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
tool_executable_name: Union[str, Dict] = None
|
|
48
|
+
|
|
49
|
+
def __init__(
|
|
50
|
+
self, *, connection: "Connection", absolute_path_to_binary_dir: Optional[Union[Path, str]] = None
|
|
51
|
+
) -> None:
|
|
52
|
+
"""
|
|
53
|
+
Initialize tool.
|
|
54
|
+
|
|
55
|
+
:param connection: Connection object
|
|
56
|
+
:param absolute_path_to_binary_dir: path to dir where binary of tool is stored
|
|
57
|
+
if None tool should be added to $PATH
|
|
58
|
+
"""
|
|
59
|
+
assert self.tool_executable_name is not None, "tool_executable_name must be defined."
|
|
60
|
+
self._connection = connection
|
|
61
|
+
self._tool_exec = self._get_tool_exec(absolute_path_to_binary_dir)
|
|
62
|
+
self.check_if_available()
|
|
63
|
+
|
|
64
|
+
logger.log(
|
|
65
|
+
level=log_levels.MODULE_DEBUG,
|
|
66
|
+
msg=f"{self.__class__.__name__} tool class uses {self._tool_exec}. Tool version: {self.get_version()}.",
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
@abstractmethod
|
|
70
|
+
def _get_tool_exec_factory(self) -> str:
|
|
71
|
+
"""
|
|
72
|
+
Get correct tool name.
|
|
73
|
+
|
|
74
|
+
Eg. depended by OSType via tool_executable_name
|
|
75
|
+
>>> return self.tool_executable_name
|
|
76
|
+
or
|
|
77
|
+
>>> return self.tool_executable_name[self._connection.get_os_type()]
|
|
78
|
+
|
|
79
|
+
:return: Tool exec name
|
|
80
|
+
"""
|
|
81
|
+
raise NotImplementedError
|
|
82
|
+
|
|
83
|
+
def _get_tool_exec(self, absolute_path_to_binary_dir: Optional[Union[Path, str]]) -> str:
|
|
84
|
+
"""
|
|
85
|
+
Create path to tool.
|
|
86
|
+
|
|
87
|
+
:param absolute_path_to_binary_dir: Path to binary directory
|
|
88
|
+
:return: Tool executable name
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
def _stringify_path_with_executable() -> str:
|
|
92
|
+
try:
|
|
93
|
+
os_type = self._connection.get_os_type()
|
|
94
|
+
except NotImplementedError as e:
|
|
95
|
+
raise TypeError("Type of connection not supported.") from e
|
|
96
|
+
|
|
97
|
+
if os_type == OSType.POSIX:
|
|
98
|
+
return str(PurePosixPath(absolute_path_to_binary_dir) / executable_name)
|
|
99
|
+
else:
|
|
100
|
+
return str(PureWindowsPath(absolute_path_to_binary_dir) / executable_name)
|
|
101
|
+
|
|
102
|
+
executable_name = self._get_tool_exec_factory()
|
|
103
|
+
if absolute_path_to_binary_dir:
|
|
104
|
+
return _stringify_path_with_executable()
|
|
105
|
+
else:
|
|
106
|
+
return executable_name
|
|
107
|
+
|
|
108
|
+
@abstractmethod
|
|
109
|
+
def check_if_available(self) -> None:
|
|
110
|
+
"""
|
|
111
|
+
Check if tool is available in system.
|
|
112
|
+
|
|
113
|
+
eg.
|
|
114
|
+
>>> _ = self._connection.execute_command(f"{self._tool_exec} /help", custom_exception = ToolNotAvailable)
|
|
115
|
+
:raises ToolNotAvailable when tool not available.
|
|
116
|
+
"""
|
|
117
|
+
raise NotImplementedError
|
|
118
|
+
|
|
119
|
+
@abstractmethod
|
|
120
|
+
def get_version(self) -> str:
|
|
121
|
+
"""
|
|
122
|
+
Get version of tool.
|
|
123
|
+
|
|
124
|
+
eg.
|
|
125
|
+
>>> return self._connection.execute_command(f"{self._tool_exec} /version").stdout
|
|
126
|
+
|
|
127
|
+
:return: Version of tool
|
|
128
|
+
"""
|
|
129
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mfd-base-tool
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Module that contains abstraction of tool in Modular Framework Design (MFD).
|
|
5
|
+
Project-URL: Homepage, https://github.com/intel/mfd
|
|
6
|
+
Project-URL: Repository, https://github.com/intel/mfd-tool
|
|
7
|
+
Project-URL: Issues, https://github.com/intel/mfd-tool/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/intel/mfd-tool/blob/main/CHANGELOG.md
|
|
9
|
+
Requires-Python: <3.14,>=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE.md
|
|
12
|
+
License-File: AUTHORS.md
|
|
13
|
+
Requires-Dist: mfd-typing<2,>=1.23.0
|
|
14
|
+
Requires-Dist: mfd-common-libs<2,>=1.11.0
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
> [!IMPORTANT]
|
|
18
|
+
> This project is under development. All source code and features on the main branch are for the purpose of testing or evaluation and not production ready.
|
|
19
|
+
|
|
20
|
+
# MFD Base Tool
|
|
21
|
+
Module for abstraction of tool (wrappers).
|
|
22
|
+
|
|
23
|
+
ToolTemplate has got 3 main methods:
|
|
24
|
+
|
|
25
|
+
* `_get_tool_exec_factory(self) -> str` - responsible to return correct tool execute name according to e.g. OS. Should use `tool_executable_name` structure as store for names.
|
|
26
|
+
* `check_if_available(self) -> None` - responsible for checking, if tool is available and executable in system. Should raise exception if not
|
|
27
|
+
* `get_version(self) -> str` - responsible for getting version of tool.
|
|
28
|
+
|
|
29
|
+
All methods and `tool_executable_name` variable in class must be implemented in developed tool.
|
|
30
|
+
Arguments in public methods must be forced as named arguments:
|
|
31
|
+
`__init__(self, *, arg1, arg2)` etc.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
Example implementation using ToolTemplate:
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from mfd_base_tool import ToolTemplate
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class MyTool(ToolTemplate):
|
|
41
|
+
tool_executable_name = "my tool name"
|
|
42
|
+
def __init__(self, *args, **kwargs):
|
|
43
|
+
super().__init__(*args, **kwargs)
|
|
44
|
+
|
|
45
|
+
def _get_tool_exec_factory(self) -> str:
|
|
46
|
+
return self.tool_executable_name
|
|
47
|
+
|
|
48
|
+
def check_if_available(self) -> None:
|
|
49
|
+
if not "if statement for check":
|
|
50
|
+
raise MyToolNotAvailable()
|
|
51
|
+
|
|
52
|
+
def get_version(self) -> str:
|
|
53
|
+
return "my read tool version"
|
|
54
|
+
|
|
55
|
+
def my_tool_method(self):
|
|
56
|
+
pass
|
|
57
|
+
```
|
|
58
|
+
## OS supported:
|
|
59
|
+
* LNX
|
|
60
|
+
* WINDOWS
|
|
61
|
+
* ESXI
|
|
62
|
+
* FREEBSD
|
|
63
|
+
* EFI shell support
|
|
64
|
+
|
|
65
|
+
## Issue reporting
|
|
66
|
+
|
|
67
|
+
If you encounter any bugs or have suggestions for improvements, you're welcome to contribute directly or open an issue [here](https://github.com/intel/mfd-base-tool/issues).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
mfd_base_tool/__init__.py,sha256=xA0rBR4kE0gpkyRR3HtuoBEpjMEDj5TkOsnURByX3tQ,143
|
|
2
|
+
mfd_base_tool/exceptions.py,sha256=_SO0qziZntIZ0aroB2ogiKJo6ePxik28KspVI2X337w,294
|
|
3
|
+
mfd_base_tool/mfd_base_tool.py,sha256=EmVQW5PRQBXZnIWpIARfwqkw-GgkzDetJaRjNaITUxE,4132
|
|
4
|
+
mfd_base_tool-0.1.0.dist-info/licenses/AUTHORS.md,sha256=J4h6eTr4h150r7TOQljn8TLgtQRV1A7CSw_LhYLNC3s,255
|
|
5
|
+
mfd_base_tool-0.1.0.dist-info/licenses/LICENSE.md,sha256=WOf_4_WDB4iXqQS77WHhRCKATy-GRxRwYwgTMDGZQdM,1089
|
|
6
|
+
mfd_base_tool-0.1.0.dist-info/METADATA,sha256=bsKqnm7meSW1EQoSLLWwi7EOKvoSPrn1DYDP7XTRfk0,2335
|
|
7
|
+
mfd_base_tool-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
8
|
+
mfd_base_tool-0.1.0.dist-info/top_level.txt,sha256=BG5lYVNJsR2M6YfFl1jZILEfj40pHAjVptAvaQXb6Gw,19
|
|
9
|
+
mfd_base_tool-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
Copyright © 2025 Intel Corporation
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|