Skip to content

Commit

Permalink
Merge pull request #76 from quinilo/build-in-update
Browse files Browse the repository at this point in the history
Load built-in signatures
  • Loading branch information
SchoolGuy authored Apr 19, 2024
2 parents 242adf3 + 13ac0f2 commit 4d78638
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
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

0 comments on commit 4d78638

Please sign in to comment.