mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-09 21:14:15 +02:00
restart is not required when changing enabled gems
This commit is contained in:
@@ -12,8 +12,8 @@ FILE_PATH = '{}/config.json'.format(CONFIG_PATH)
|
||||
|
||||
class Configuration:
|
||||
|
||||
def __init__(self, gems: List[str] = None, style: str = None):
|
||||
self.gems = gems
|
||||
def __init__(self, enabled_gems: List[str] = None, style: str = None):
|
||||
self.enabled_gems = enabled_gems
|
||||
self.style = style
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ def read() -> Configuration:
|
||||
|
||||
return Configuration(**json.loads(config_file))
|
||||
|
||||
return Configuration(gems=None)
|
||||
return Configuration()
|
||||
|
||||
|
||||
def save(config: Configuration):
|
||||
|
||||
@@ -16,11 +16,15 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
super(GenericSoftwareManager, self).__init__(context=context)
|
||||
self.managers = managers
|
||||
self.map = {t: m for m in self.managers for t in m.get_managed_types()}
|
||||
self._enabled_map = {} if app_args.check_packaging_once else None
|
||||
self._available_map = {} if app_args.check_packaging_once else None
|
||||
self.thread_prepare = None
|
||||
self.i18n = context.i18n
|
||||
self.disk_loader_factory = context.disk_loader_factory
|
||||
|
||||
def reset_cache(self):
|
||||
if self._available_map is not None:
|
||||
self._available_map = {}
|
||||
|
||||
def _sort(self, apps: List[SoftwarePackage], word: str) -> List[SoftwarePackage]:
|
||||
|
||||
exact_name_matches, contains_name_matches, others = [], [], []
|
||||
@@ -42,21 +46,21 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
|
||||
return res
|
||||
|
||||
def _is_enabled(self, man: SoftwareManager):
|
||||
def _can_work(self, man: SoftwareManager):
|
||||
|
||||
if self._enabled_map is not None:
|
||||
enabled = self._enabled_map.get(man.get_managed_types())
|
||||
if self._available_map is not None:
|
||||
enabled = self._available_map.get(man.get_managed_types())
|
||||
|
||||
if enabled is None:
|
||||
enabled = man.is_enabled()
|
||||
self._enabled_map[man.get_managed_types()] = enabled
|
||||
enabled = man.is_enabled() and man.can_work()
|
||||
self._available_map[man.get_managed_types()] = enabled
|
||||
|
||||
return enabled
|
||||
else:
|
||||
return man.is_enabled()
|
||||
return man.is_enabled() and man.can_work()
|
||||
|
||||
def _search(self, word: str, man: SoftwareManager, disk_loader, res: SearchResult):
|
||||
if self._is_enabled(man):
|
||||
if self._can_work(man):
|
||||
apps_found = man.search(words=word, disk_loader=disk_loader)
|
||||
res.installed.extend(apps_found.installed)
|
||||
res.new.extend(apps_found.new)
|
||||
@@ -95,6 +99,12 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
self.thread_prepare.join()
|
||||
self.thread_prepare = None
|
||||
|
||||
def set_enabled(self, enabled: bool):
|
||||
pass
|
||||
|
||||
def can_work(self) -> bool:
|
||||
return True
|
||||
|
||||
def read_installed(self, disk_loader: DiskCacheLoader = None, limit: int = -1, only_apps: bool = False, pkg_types: Set[Type[SoftwarePackage]] = None) -> SearchResult:
|
||||
self._wait_to_be_ready()
|
||||
|
||||
@@ -104,7 +114,7 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
|
||||
if not pkg_types: # any type
|
||||
for man in self.managers:
|
||||
if self._is_enabled(man):
|
||||
if self._can_work(man):
|
||||
if not disk_loader:
|
||||
disk_loader = self.disk_loader_factory.new()
|
||||
disk_loader.start()
|
||||
@@ -117,7 +127,7 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
|
||||
for t in pkg_types:
|
||||
man = self.map.get(t)
|
||||
if man and (man not in man_already_used) and self._is_enabled(man):
|
||||
if man and (man not in man_already_used) and self._can_work(man):
|
||||
|
||||
if not disk_loader:
|
||||
disk_loader = self.disk_loader_factory.new()
|
||||
@@ -185,7 +195,7 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
|
||||
def _get_manager_for(self, app: SoftwarePackage) -> SoftwareManager:
|
||||
man = self.map[app.__class__]
|
||||
return man if man and self._is_enabled(man) else None
|
||||
return man if man and self._can_work(man) else None
|
||||
|
||||
def cache_to_disk(self, app: SoftwarePackage, icon_bytes: bytes, only_icon: bool):
|
||||
if self.context.disk_cache and app.supports_disk_cache():
|
||||
@@ -211,7 +221,7 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
def _prepare(self):
|
||||
if self.managers:
|
||||
for man in self.managers:
|
||||
if self._is_enabled(man):
|
||||
if self._can_work(man):
|
||||
man.prepare()
|
||||
|
||||
def prepare(self):
|
||||
@@ -225,7 +235,7 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
|
||||
if self.managers:
|
||||
for man in self.managers:
|
||||
if self._is_enabled(man):
|
||||
if self._can_work(man):
|
||||
man_updates = man.list_updates()
|
||||
if man_updates:
|
||||
updates.extend(man_updates)
|
||||
@@ -248,7 +258,7 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
return warnings
|
||||
|
||||
def _fill_suggestions(self, suggestions: list, man: SoftwareManager, limit: int):
|
||||
if self._is_enabled(man):
|
||||
if self._can_work(man):
|
||||
man_sugs = man.list_suggestions(limit)
|
||||
|
||||
if man_sugs:
|
||||
|
||||
@@ -19,11 +19,11 @@ def find_manager(member):
|
||||
return manager_found
|
||||
|
||||
|
||||
def load_managers(locale: str, context: ApplicationContext, names: List[str] = None) -> List[SoftwareManager]:
|
||||
def load_managers(locale: str, context: ApplicationContext, enabled_gems: List[str] = None) -> List[SoftwareManager]:
|
||||
managers = []
|
||||
|
||||
for f in os.scandir(ROOT_DIR + '/gems'):
|
||||
if f.is_dir() and f.name != '__pycache__' and (not names or f.name in names):
|
||||
if f.is_dir() and f.name != '__pycache__':
|
||||
module = pkgutil.find_loader('bauh.gems.{}.controller'.format(f.name)).load_module()
|
||||
|
||||
manager_class = find_manager(module)
|
||||
@@ -35,7 +35,12 @@ def load_managers(locale: str, context: ApplicationContext, names: List[str] = N
|
||||
if os.path.exists(locale_path):
|
||||
context.i18n.update(util.get_locale_keys(locale, locale_path))
|
||||
|
||||
managers.append(manager_class(context=context))
|
||||
man = manager_class(context=context)
|
||||
|
||||
if enabled_gems is not None and f.name not in enabled_gems:
|
||||
man.set_enabled(False)
|
||||
|
||||
managers.append(man)
|
||||
|
||||
return managers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user