Early support for symbol themes.

This commit is contained in:
grossmj committed 2019-03-12 18:13:33 +07:00
1 parent bae3fb84b9
commit cf91e904f7
6 files changed
+62 -16

No files matched your search

+22 -2
View File
@@ -74,7 +74,7 @@ class ApplianceManager:
os.makedirs(appliances_path, exist_ok=True)
return appliances_path
def load_appliances(self):
def load_appliances(self, symbol_theme="Classic"):
"""
Loads appliance files from disk.
"""
@@ -90,13 +90,33 @@ class ApplianceManager:
try:
with open(path, 'r', encoding='utf-8') as f:
appliance = Appliance(appliance_id, json.load(f), builtin=builtin)
appliance.__json__() # Check if loaded without error
json_data = appliance.__json__() # Check if loaded without error
if appliance.status != 'broken':
self._appliances[appliance.id] = appliance
if not appliance.symbol or appliance.symbol.startswith(":/symbols/"):
# apply a default symbol if the appliance has none or a default symbol
default_symbol = self._get_default_symbol(json_data, symbol_theme)
if default_symbol:
appliance.symbol = default_symbol
except (ValueError, OSError, KeyError) as e:
log.warning("Cannot load appliance file '%s': %s", path, str(e))
continue
def _get_default_symbol(self, appliance, symbol_theme):
"""
Returns the default symbol for a given appliance.
"""
from . import Controller
controller = Controller.instance()
category = appliance["category"]
if category == "guest":
if "docker" in appliance:
return controller.symbols.get_default_symbol("docker_guest", symbol_theme)
elif "qemu" in appliance:
return controller.symbols.get_default_symbol("qemu_guest", symbol_theme)
return controller.symbols.get_default_symbol(category, symbol_theme)
async def download_custom_symbols(self):
"""
Download custom appliance symbols from our GitHub registry repository.