diff --git a/changelog.d/73.added b/changelog.d/73.added new file mode 100644 index 0000000..b1cbdc3 --- /dev/null +++ b/changelog.d/73.added @@ -0,0 +1 @@ +Added Built-In option in import dialog to load the built-in config \ No newline at end of file diff --git a/libcobblersignatures/__init__.py b/libcobblersignatures/__init__.py index 51ad074..b0a88e0 100644 --- a/libcobblersignatures/__init__.py +++ b/libcobblersignatures/__init__.py @@ -11,6 +11,11 @@ from libcobblersignatures.models.osbreed import OsBreed from libcobblersignatures.models.osversion import Osversion +try: + from importlib.resources import files +except ImportError: + from importlib_resources import files + __version__ = "0.1.0" @@ -87,6 +92,13 @@ def importsignatures(self, import_type: ImportTypes, source: str): self._importsignaturesurl(source) elif import_type == ImportTypes.STRING: self.signaturesjson = source + elif import_type == ImportTypes.BUILT_IN: + self.signaturesjson = ( + files("libcobblersignatures.data") + .joinpath("distro_signatures.json") + .open("r", encoding="utf-8") + .read() + ) else: raise ValueError("Please use on of the four given options for the source!") diff --git a/libcobblersignatures/cli.py b/libcobblersignatures/cli.py index fadad08..57ae4fe 100644 --- a/libcobblersignatures/cli.py +++ b/libcobblersignatures/cli.py @@ -19,7 +19,7 @@ import_menu_questions = questionary.select( "What is your desired source of input?", - choices=["URL", "String", "File", "Go back"], + choices=["URL", "String", "File", "Built-In", "Go back"], ) import_menu_questions2 = questionary.path( @@ -424,14 +424,18 @@ def import_menu(): Second level menu with the purpose to catch all functionality related to importing the data from a source. """ choice_import_menu = import_menu_questions.ask() - if choice_import_menu in ["URL", "File", "String"]: - result_import_menu_2 = import_menu_questions2.ask() + if choice_import_menu in ["URL", "File", "String", "Built-In"]: + result_import_menu_2 = "unknown" + if choice_import_menu != "Built-In": + result_import_menu_2 = import_menu_questions2.ask() if choice_import_menu == "URL": import_type = ImportTypes.URL elif choice_import_menu == "File": import_type = ImportTypes.FILE elif choice_import_menu == "String": import_type = ImportTypes.STRING + elif choice_import_menu == "Built-In": + import_type = ImportTypes.BUILT_IN else: return input_import_source = result_import_menu_2 diff --git a/libcobblersignatures/enums.py b/libcobblersignatures/enums.py index cb7ca7a..75b67e3 100644 --- a/libcobblersignatures/enums.py +++ b/libcobblersignatures/enums.py @@ -74,6 +74,10 @@ class ImportTypes(Enum): This value shall be given when the content shall be imported from a string. This string shall not contain any linebreaks. """ + BUILT_IN = 3 + """ + This value shall be given when the content shall be imported from the built in file in data/v2/distro_signature.json + """ class ExportTypes(Enum):