-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: mulhern <[email protected]>
- Loading branch information
Showing
3 changed files
with
64 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[build-system] | ||
requires = ["setuptools"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.pylint] | ||
good-names="Manager" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2023 Red Hat, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" | ||
Dynamic class generation | ||
""" | ||
# isort: STDLIB | ||
import os | ||
import xml.etree.ElementTree as ET # nosec B405 | ||
from enum import Enum | ||
|
||
# isort: FIRSTPARTY | ||
from dbus_python_client_gen import DPClientGenerationError, make_class | ||
|
||
from .._errors import StratisCliGenerationError | ||
from ._constants import MANAGER_INTERFACE | ||
from ._environment import get_timeout | ||
from ._introspect import SPECS | ||
|
||
DBUS_TIMEOUT_SECONDS = 120 | ||
|
||
TIMEOUT = get_timeout( | ||
os.environ.get("STRATIS_DBUS_TIMEOUT", DBUS_TIMEOUT_SECONDS * 1000) | ||
) | ||
|
||
|
||
class ClassKey(Enum): | ||
""" | ||
Keys for dynamically generated classes. | ||
""" | ||
|
||
MANAGER = ("Manager", MANAGER_INTERFACE) | ||
|
||
|
||
def make_dyn_class(key): | ||
""" | ||
Dynamically generate a class from introspection specification. | ||
""" | ||
try: | ||
return make_class( | ||
key.value[0], ET.fromstring(SPECS[key.value[1]]), TIMEOUT # nosec B314 | ||
) | ||
except DPClientGenerationError as err: # pragma: no cover | ||
raise StratisCliGenerationError( | ||
"Failed to generate some class needed for invoking dbus-python methods" | ||
) from err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters