-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
105 additions
and
55 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
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
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
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,14 +1,65 @@ | ||
import pkg_resources | ||
import platform | ||
|
||
from zedenv.lib.logger import ZELogger | ||
|
||
|
||
# Import plugins | ||
def get_plugins(): | ||
# https://packaging.python.org/guides/packaging-namespace-packages/ | ||
# https://packaging.python.org/guides/creating-and-discovering-plugins/ | ||
|
||
plugins = dict() | ||
plugins = {} | ||
|
||
for entry_point in pkg_resources.iter_entry_points('zedenv.plugins'): | ||
plugins[entry_point.name] = entry_point.load() | ||
|
||
return plugins | ||
|
||
|
||
def get_bootloader(boot_environment: str, | ||
old_boot_environment: str, | ||
bootloader: str, | ||
verbose: bool, | ||
noconfirm: bool, | ||
noop: bool, | ||
be_root: str): | ||
bootloader_plugin = None | ||
if bootloader: | ||
plugins = get_plugins() | ||
if bootloader in plugins: | ||
ZELogger.verbose_log({ | ||
"level": "INFO", | ||
"message": ("Configuring boot environment " | ||
f"bootloader with {bootloader}\n") | ||
}, verbose) | ||
if platform.system().lower() in plugins[bootloader].systems_allowed: | ||
try: | ||
bootloader_plugin = plugins[bootloader]({ | ||
'boot_environment': boot_environment, | ||
'old_boot_environment': old_boot_environment, | ||
'bootloader': bootloader, | ||
'verbose': verbose, | ||
'noconfirm': noconfirm, | ||
'noop': noop, | ||
'boot_environment_root': be_root | ||
}) | ||
except ValueError as e: | ||
ZELogger.log({ | ||
"level": "EXCEPTION", | ||
"message": f"Failed to run plugin {bootloader}\n{e}\n" | ||
}, exit_on_error=True) | ||
else: | ||
ZELogger.log({ | ||
"level": "EXCEPTION", | ||
"message": (f"The plugin {bootloader} is " | ||
f"not valid for {platform.system().lower()}\n") | ||
}, exit_on_error=True) | ||
else: | ||
ZELogger.log({ | ||
"level": "EXCEPTION", | ||
"message": f"bootloader type {bootloader} does not exist\n" | ||
"Check available plugins with 'zedenv --plugins'\n" | ||
}, exit_on_error=True) | ||
|
||
return bootloader_plugin |
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