mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 02:24:16 +02:00
[config] finished moving
This commit is contained in:
@@ -12,67 +12,52 @@ from bauh.commons.config import read_config as read
|
||||
CONFIG_PATH = '{}/.config/{}'.format(Path.home(), __app_name__)
|
||||
FILE_PATH = '{}/config.yml'.format(CONFIG_PATH)
|
||||
|
||||
# TODO stopped here
|
||||
class UpdatesSettings:
|
||||
|
||||
def __init__(self, check_interval: int, **kwargs):
|
||||
self.check_interval = check_interval
|
||||
|
||||
|
||||
class CacheSettings:
|
||||
|
||||
def __init__(self, data_expiration: int, icon_expiration: int, **kwargs):
|
||||
self.data_expiration = data_expiration
|
||||
self.icon_expiration = icon_expiration
|
||||
|
||||
|
||||
class Configuration:
|
||||
|
||||
def __init__(self, gems: List[str], style: str, cache: dict, locale: str,
|
||||
updates: dict, system_notifications: bool, disk_cache: bool, download_icons: bool,
|
||||
check_packaging_once: bool, suggestions: bool, max_displayed: int, download_mthread: bool,
|
||||
**kwargs):
|
||||
self.gems = gems
|
||||
self.style = style
|
||||
self.cache = CacheSettings(**cache)
|
||||
self.locale = locale
|
||||
self.updates = UpdatesSettings(**updates)
|
||||
self.system_notifications = system_notifications
|
||||
self.disk_cache = disk_cache
|
||||
self.download_icons = download_icons
|
||||
self.check_packaging_once = check_packaging_once
|
||||
self.suggestions = suggestions
|
||||
self.max_displayed = max_displayed
|
||||
self.download_mthread = download_mthread
|
||||
|
||||
|
||||
def read_config(update_file: bool = False) -> Configuration:
|
||||
def read_config(update_file: bool = False) -> dict:
|
||||
default = {
|
||||
'gems': None,
|
||||
'style': None,
|
||||
'cache_exp': 60 * 60,
|
||||
'icon_exp': 60 * 5,
|
||||
'memory_cache': {
|
||||
'data_expiration': 60 * 60,
|
||||
'icon_expiration': 60 * 5
|
||||
},
|
||||
'locale': None,
|
||||
'updates': {
|
||||
'check_interval': 60
|
||||
'check_interval': 30
|
||||
},
|
||||
'system_notifications': True,
|
||||
'disk_cache': True,
|
||||
'download_icons': True,
|
||||
'check_packaging_once': False,
|
||||
'suggestions': True,
|
||||
'max_displayed': 50, # table
|
||||
'download_mthread': True # downloads
|
||||
'system': {
|
||||
'notifications': True,
|
||||
'single_dependency_checking': False
|
||||
},
|
||||
'disk_cache': {
|
||||
'enabled': True
|
||||
},
|
||||
'suggestions': {
|
||||
'enabled': True,
|
||||
'by_type': 10
|
||||
},
|
||||
'ui': {
|
||||
'table': {
|
||||
'max_displayed': 50
|
||||
},
|
||||
'tray': {
|
||||
'default_icon': None,
|
||||
'updates_icon': None
|
||||
},
|
||||
'style': None
|
||||
},
|
||||
'download': {
|
||||
'multithreaded': True,
|
||||
'icons': True
|
||||
}
|
||||
}
|
||||
obj = read(FILE_PATH, default, update_file=update_file, update_async=True)
|
||||
return Configuration(**obj)
|
||||
return read(FILE_PATH, default, update_file=update_file, update_async=True)
|
||||
|
||||
|
||||
def save(config: Configuration):
|
||||
def save(config: dict):
|
||||
Path(CONFIG_PATH).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with open(FILE_PATH, 'w+') as f:
|
||||
f.write(yaml.safe_dump(config.__dict__))
|
||||
f.write(yaml.safe_dump(config))
|
||||
|
||||
|
||||
def remove_old_config(logger: logging.Logger):
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import re
|
||||
import time
|
||||
import traceback
|
||||
from argparse import Namespace
|
||||
from threading import Thread
|
||||
from typing import List, Set, Type
|
||||
|
||||
@@ -11,26 +10,24 @@ from bauh.api.abstract.handler import ProcessWatcher
|
||||
from bauh.api.abstract.model import SoftwarePackage, PackageUpdate, PackageHistory, PackageSuggestion, PackageAction
|
||||
from bauh.api.exception import NoInternetException
|
||||
from bauh.commons import internet
|
||||
from bauh.view.core.config import Configuration
|
||||
|
||||
RE_IS_URL = re.compile(r'^https?://.+')
|
||||
|
||||
SUGGESTIONS_LIMIT = 10
|
||||
|
||||
|
||||
class GenericSoftwareManager(SoftwareManager):
|
||||
|
||||
def __init__(self, managers: List[SoftwareManager], context: ApplicationContext, config: Configuration):
|
||||
def __init__(self, managers: List[SoftwareManager], context: ApplicationContext, config: dict):
|
||||
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._available_cache = {} if config.check_packaging_once else None
|
||||
self._available_cache = {} if config['system']['single_dependency_checking'] else None
|
||||
self.thread_prepare = None
|
||||
self.i18n = context.i18n
|
||||
self.disk_loader_factory = context.disk_loader_factory
|
||||
self.logger = context.logger
|
||||
self._already_prepared = []
|
||||
self.working_managers = []
|
||||
self.config = config
|
||||
|
||||
def reset_cache(self):
|
||||
if self._available_cache is not None:
|
||||
@@ -345,20 +342,22 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
suggestions.extend(man_sugs)
|
||||
|
||||
def list_suggestions(self, limit: int) -> List[PackageSuggestion]:
|
||||
if self.managers and internet.is_available(self.context.http_client, self.context.logger):
|
||||
suggestions, threads = [], []
|
||||
for man in self.managers:
|
||||
t = Thread(target=self._fill_suggestions, args=(suggestions, man, SUGGESTIONS_LIMIT))
|
||||
t.start()
|
||||
threads.append(t)
|
||||
if bool(self.config['suggestions']['enabled']):
|
||||
if self.managers and internet.is_available(self.context.http_client, self.context.logger):
|
||||
suggestions, threads = [], []
|
||||
for man in self.managers:
|
||||
t = Thread(target=self._fill_suggestions, args=(suggestions, man, int(self.config['suggestions']['by_type'])))
|
||||
t.start()
|
||||
threads.append(t)
|
||||
|
||||
for t in threads:
|
||||
t.join()
|
||||
for t in threads:
|
||||
t.join()
|
||||
|
||||
if suggestions:
|
||||
suggestions.sort(key=lambda s: s.priority.value, reverse=True)
|
||||
if suggestions:
|
||||
suggestions.sort(key=lambda s: s.priority.value, reverse=True)
|
||||
|
||||
return suggestions
|
||||
return suggestions
|
||||
return []
|
||||
|
||||
def execute_custom_action(self, action: PackageAction, pkg: SoftwarePackage, root_password: str, watcher: ProcessWatcher):
|
||||
man = self._get_manager_for(pkg)
|
||||
|
||||
@@ -5,8 +5,7 @@ from typing import List
|
||||
|
||||
from bauh import ROOT_DIR
|
||||
from bauh.api.abstract.controller import SoftwareManager, ApplicationContext
|
||||
from bauh.view.core.config import Configuration
|
||||
from bauh.view.util import util, translation
|
||||
from bauh.view.util import translation
|
||||
|
||||
|
||||
def find_manager(member):
|
||||
@@ -20,7 +19,7 @@ def find_manager(member):
|
||||
return manager_found
|
||||
|
||||
|
||||
def load_managers(locale: str, context: ApplicationContext, config: Configuration, default_locale: str) -> List[SoftwareManager]:
|
||||
def load_managers(locale: str, context: ApplicationContext, config: dict, default_locale: str) -> List[SoftwareManager]:
|
||||
managers = []
|
||||
|
||||
for f in os.scandir(ROOT_DIR + '/gems'):
|
||||
@@ -44,10 +43,10 @@ def load_managers(locale: str, context: ApplicationContext, config: Configuratio
|
||||
|
||||
man = manager_class(context=context)
|
||||
|
||||
if config.gems is None:
|
||||
if config['gems'] is None:
|
||||
man.set_enabled(man.is_default_enabled())
|
||||
else:
|
||||
man.set_enabled(f.name in config.gems)
|
||||
man.set_enabled(f.name in config['gems'])
|
||||
|
||||
managers.append(man)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user