Skip to content
New issue

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

Load built-in signatures #76

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/73.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added Built-In option in import dialog to load the built-in config
12 changes: 12 additions & 0 deletions libcobblersignatures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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!")

Expand Down
10 changes: 7 additions & 3 deletions libcobblersignatures/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions libcobblersignatures/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading