We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Currently it behaves/is a module type to allow for easy attribute access, but this is annoying when attributes may or may not exist yet. For example:
dissect.target/dissect/target/helpers/cache.py
Line 85 in 98d33d0
Ideally it behaves like a magic dictionary with the nice methods of a dictionary, but the magic attribute access like a module.
https://github.com/fox-it/dissect.target/blob/main/dissect/target/helpers/config.py
The text was updated successfully, but these errors were encountered:
Is it acceptable to invoke the config as follows?
foo = target._config.get("FOO")
Because in that case the following patch should suffice:
diff --git a/dissect/target/helpers/config.py b/dissect/target/helpers/config.py index 7a1cc3f..3a1868a 100644 --- a/dissect/target/helpers/config.py +++ b/dissect/target/helpers/config.py @@ -6,6 +6,7 @@ import importlib.util import logging from pathlib import Path from types import ModuleType +from typing import Any log = logging.getLogger(__name__) @@ -26,6 +27,10 @@ def load(paths: list[Path | str] | Path | str | None) -> ModuleType: config_values = _parse_ast(config_file.read_bytes()) config.__dict__.update(config_values) + def get(self, value: str) -> Any | None: + return getattr(self, value, None) + config.get = get.__get__(config) + return config
Sorry, something went wrong.
No branches or pull requests
Currently it behaves/is a module type to allow for easy attribute access, but this is annoying when attributes may or may not exist yet. For example:
dissect.target/dissect/target/helpers/cache.py
Line 85 in 98d33d0
Ideally it behaves like a magic dictionary with the nice methods of a dictionary, but the magic attribute access like a module.
https://github.com/fox-it/dissect.target/blob/main/dissect/target/helpers/config.py
The text was updated successfully, but these errors were encountered: