mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-10 05:24:16 +02:00
improvement -> all suported types now display a 'Checking configuration file' task during the initialization process
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
from bauh.commons.config import read_config as read
|
||||
from bauh.commons.config import YAMLConfigManager
|
||||
from bauh.gems.appimage import CONFIG_FILE
|
||||
|
||||
|
||||
def read_config(update_file: bool = False) -> dict:
|
||||
default = {
|
||||
'database': {
|
||||
'expiration': 60
|
||||
class AppImageConfigManager(YAMLConfigManager):
|
||||
|
||||
def __init__(self):
|
||||
super(AppImageConfigManager, self).__init__(config_file_path=CONFIG_FILE)
|
||||
|
||||
def get_default_config(self) -> dict:
|
||||
return {
|
||||
'database': {
|
||||
'expiration': 60
|
||||
}
|
||||
}
|
||||
}
|
||||
return read(CONFIG_FILE, default, update_file=update_file)
|
||||
|
||||
@@ -24,13 +24,13 @@ from bauh.api.abstract.model import SoftwarePackage, PackageHistory, PackageUpda
|
||||
from bauh.api.abstract.view import MessageType, ViewComponent, FormComponent, InputOption, SingleSelectComponent, \
|
||||
SelectViewType, TextInputComponent, PanelComponent, FileChooserComponent, ViewObserver
|
||||
from bauh.commons import resource
|
||||
from bauh.commons.config import save_config
|
||||
from bauh.commons.boot import CreateConfigFile
|
||||
from bauh.commons.html import bold
|
||||
from bauh.commons.system import SystemProcess, new_subprocess, ProcessHandler, run_cmd, SimpleProcess
|
||||
from bauh.gems.appimage import query, INSTALLATION_PATH, LOCAL_PATH, SUGGESTIONS_FILE, CONFIG_FILE, ROOT_DIR, \
|
||||
from bauh.gems.appimage import query, INSTALLATION_PATH, LOCAL_PATH, SUGGESTIONS_FILE, ROOT_DIR, \
|
||||
CONFIG_DIR, UPDATES_IGNORED_FILE, util, get_default_manual_installation_file_dir, DATABASE_APPS_FILE, \
|
||||
DATABASE_RELEASES_FILE, DESKTOP_ENTRIES_PATH, DATABASES_DIR
|
||||
from bauh.gems.appimage.config import read_config
|
||||
DATABASE_RELEASES_FILE, DESKTOP_ENTRIES_PATH, DATABASES_DIR, get_icon_path
|
||||
from bauh.gems.appimage.config import AppImageConfigManager
|
||||
from bauh.gems.appimage.model import AppImage
|
||||
from bauh.gems.appimage.util import replace_desktop_entry_exec_command
|
||||
from bauh.gems.appimage.worker import DatabaseUpdater, SymlinksVerifier
|
||||
@@ -76,6 +76,7 @@ class AppImageManager(SoftwareManager):
|
||||
self.http_client = context.http_client
|
||||
self.logger = context.logger
|
||||
self.file_downloader = context.file_downloader
|
||||
self.configman = AppImageConfigManager()
|
||||
self.custom_actions = [CustomSoftwareAction(i18n_label_key='appimage.custom_action.install_file',
|
||||
i18n_status_key='appimage.custom_action.install_file.status',
|
||||
manager=self,
|
||||
@@ -616,16 +617,17 @@ class AppImageManager(SoftwareManager):
|
||||
return False
|
||||
|
||||
def prepare(self, task_manager: TaskManager, root_password: str, internet_available: bool):
|
||||
create_config = CreateConfigFile(taskman=task_manager, configman=self.configman, i18n=self.i18n,
|
||||
task_icon_path=get_icon_path(), logger=self.logger)
|
||||
create_config.start()
|
||||
|
||||
symlink_check = SymlinksVerifier(taskman=task_manager, i18n=self.i18n, logger=self.logger)
|
||||
symlink_check.start()
|
||||
|
||||
if internet_available:
|
||||
updater = DatabaseUpdater(taskman=task_manager, i18n=self.context.i18n,
|
||||
http_client=self.context.http_client, logger=self.context.logger)
|
||||
|
||||
if updater.should_update(read_config()):
|
||||
updater.register_task()
|
||||
updater.start()
|
||||
DatabaseUpdater(taskman=task_manager, i18n=self.context.i18n,
|
||||
create_config=create_config, http_client=self.context.http_client,
|
||||
logger=self.context.logger).start()
|
||||
|
||||
def list_updates(self, internet_available: bool) -> List[PackageUpdate]:
|
||||
res = self.read_installed(disk_loader=None, internet_available=internet_available)
|
||||
@@ -729,12 +731,12 @@ class AppImageManager(SoftwareManager):
|
||||
traceback.print_exc()
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent:
|
||||
config = read_config()
|
||||
appimage_config = self.configman.get_config()
|
||||
max_width = floor(screen_width * 0.15)
|
||||
|
||||
opts = [
|
||||
TextInputComponent(label=self.i18n['appimage.config.database.expiration'],
|
||||
value=int(config['database']['expiration']) if isinstance(config['database']['expiration'], int) else '',
|
||||
value=int(appimage_config['database']['expiration']) if isinstance(appimage_config['database']['expiration'], int) else '',
|
||||
tooltip=self.i18n['appimage.config.database.expiration.tip'],
|
||||
only_int=True,
|
||||
max_width=max_width,
|
||||
@@ -744,13 +746,13 @@ class AppImageManager(SoftwareManager):
|
||||
return PanelComponent([FormComponent(opts, self.i18n['appimage.config.database'])])
|
||||
|
||||
def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
config = read_config()
|
||||
appimage_config = self.configman.get_config()
|
||||
|
||||
panel = component.components[0]
|
||||
config['database']['expiration'] = panel.get_component('appim_db_exp').get_int_value()
|
||||
appimage_config['database']['expiration'] = panel.get_component('appim_db_exp').get_int_value()
|
||||
|
||||
try:
|
||||
save_config(config, CONFIG_FILE)
|
||||
self.configman.save_config(appimage_config)
|
||||
return True, None
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
@@ -822,7 +824,7 @@ class AppImageManager(SoftwareManager):
|
||||
|
||||
def update_database(self, root_password: str, watcher: ProcessWatcher) -> bool:
|
||||
db_updater = DatabaseUpdater(i18n=self.i18n, http_client=self.context.http_client,
|
||||
logger=self.context.logger, watcher=watcher)
|
||||
logger=self.context.logger, watcher=watcher, taskman=TaskManager())
|
||||
|
||||
res = db_updater.download_databases()
|
||||
return res
|
||||
|
||||
@@ -36,6 +36,7 @@ appimage.update_database.deleting_old=Removing old files
|
||||
appimage.update_database.downloading=Downloading database files
|
||||
appimage.update_database.uncompressing=Uncompressing files
|
||||
appimage.task.db_update=Actualització de bases de dades
|
||||
appimage.task.db_update.checking=Checking for updates
|
||||
appimage.task.symlink_check=Checking symlinks
|
||||
appimage.uninstall.error.remove_folder=No s’ha pogut suprimir el directori d’instal·lació de l’aplicació {}
|
||||
appimage.warning.missing_db_files={appimage} database files were not found. Some actions will not work properly.
|
||||
|
||||
@@ -36,6 +36,7 @@ appimage.update_database.deleting_old=Removing old files
|
||||
appimage.update_database.downloading=Downloading database files
|
||||
appimage.update_database.uncompressing=Uncompressing files
|
||||
appimage.task.db_update=Updating databases
|
||||
appimage.task.db_update.checking=Checking for updates
|
||||
appimage.task.symlink_check=Checking symlinks
|
||||
appimage.uninstall.error.remove_folder=Anwendungordner {} konnte nicht entfernt werden
|
||||
appimage.warning.missing_db_files={appimage} database files were not found. Some actions will not work properly.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
appimage.config.database=Database
|
||||
appimage.config.database.expiration=Expiration
|
||||
appimage.config.database.expiration.tip=appimage.config.database.expiration.tip=It defines the period (in minutes) in which the database will be considered up to date. Use 0 if you always want to update it.
|
||||
appimage.config.database.expiration.tip=It defines the period (in minutes) in which the database will be considered up to date. Use 0 if you always want to update it.
|
||||
appimage.custom_action.install_file=Install AppImage file
|
||||
appimage.custom_action.install_file.details=Installation details
|
||||
appimage.custom_action.install_file.invalid_file=You must define a valid AppImage file
|
||||
@@ -36,6 +36,7 @@ appimage.update_database.deleting_old=Removing old files
|
||||
appimage.update_database.downloading=Downloading database files
|
||||
appimage.update_database.uncompressing=Uncompressing files
|
||||
appimage.task.db_update=Updating databases
|
||||
appimage.task.db_update.checking=Checking for updates
|
||||
appimage.task.symlink_check=Checking symlinks
|
||||
appimage.uninstall.error.remove_folder=Could not remove the application installation directory {}
|
||||
appimage.warning.missing_db_files={appimage} database files were not found. Some actions will not work properly.
|
||||
|
||||
@@ -36,6 +36,7 @@ appimage.update_database.deleting_old=Eliminando archivos antiguos
|
||||
appimage.update_database.downloading=Descargando archivos de la base de datos
|
||||
appimage.update_database.uncompressing=Descomprindo archivos
|
||||
appimage.task.db_update=Actualizando base de datos
|
||||
appimage.task.db_update.checking=Buscando actualizaciones
|
||||
appimage.task.symlink_check=Verificando links simbólicos
|
||||
appimage.uninstall.error.remove_folder=No se pudo eliminar el directorio de instalación de la aplicación {}
|
||||
appimage.warning.missing_db_files=No se encontraron archivos de la base de datos {appimage}. Algunas acciones no funcionarán correctamente.
|
||||
|
||||
@@ -36,6 +36,7 @@ appimage.update_database.deleting_old=Removing old files
|
||||
appimage.update_database.downloading=Downloading database files
|
||||
appimage.update_database.uncompressing=Uncompressing files
|
||||
appimage.task.db_update=Mise à jour des bases de données
|
||||
appimage.task.db_update.checking=Checking for updates
|
||||
appimage.task.symlink_check=Verification des symlinks
|
||||
appimage.uninstall.error.remove_folder=Impossible de supprimer le répertoire d'installation {}
|
||||
appimage.warning.missing_db_files={appimage} database files were not found. Some actions will not work properly.
|
||||
|
||||
@@ -36,6 +36,7 @@ appimage.update_database.deleting_old=Removing old files
|
||||
appimage.update_database.downloading=Downloading database files
|
||||
appimage.update_database.uncompressing=Uncompressing files
|
||||
appimage.task.db_update=Aggiornamento dei database
|
||||
appimage.task.db_update.checking=Checking for updates
|
||||
appimage.task.symlink_check=Checking symlinks
|
||||
appimage.uninstall.error.remove_folder=Impossibile rimuovere la directory di installazione dell'applicazione {}
|
||||
appimage.warning.missing_db_files={appimage} database files were not found. Some actions will not work properly.
|
||||
|
||||
@@ -36,6 +36,7 @@ appimage.update_database.deleting_old=Removendo arquicos antigos
|
||||
appimage.update_database.downloading=Baixando arquivos do banco de dados
|
||||
appimage.update_database.uncompressing=Descomprimindo arquivos
|
||||
appimage.task.db_update=Atualizando base de dados
|
||||
appimage.task.db_update.checking=Checando atualizações
|
||||
appimage.task.symlink_check=Verificando links simbólicos
|
||||
appimage.uninstall.error.remove_folder=Não foi possível remover o diretóri ode instalação do aplicativo {}
|
||||
appimage.warning.missing_db_files=Arquivos do banco de dados {appimage} não foram encontrados. Algumas ações não funcionarão corretamente.
|
||||
|
||||
@@ -36,6 +36,7 @@ appimage.update_database.deleting_old=Removing old files
|
||||
appimage.update_database.downloading=Downloading database files
|
||||
appimage.update_database.uncompressing=Uncompressing files
|
||||
appimage.task.db_update=Обновление базы данных
|
||||
appimage.task.db_update.checking=Checking for updates
|
||||
appimage.task.symlink_check=Checking symlinks
|
||||
appimage.uninstall.error.remove_folder=Не удалось удалить каталог приложения {}
|
||||
appimage.warning.missing_db_files={appimage} database files were not found. Some actions will not work properly.
|
||||
|
||||
@@ -36,6 +36,7 @@ appimage.update_database.deleting_old=Removing old files
|
||||
appimage.update_database.downloading=Downloading database files
|
||||
appimage.update_database.uncompressing=Uncompressing files
|
||||
appimage.task.db_update=Veritabanları güncelleniyor
|
||||
appimage.task.db_update.checking=Checking for updates
|
||||
appimage.task.symlink_check=Checking symlinks
|
||||
appimage.uninstall.error.remove_folder={} uygulama kurulum dizini kaldırılamadı
|
||||
appimage.warning.missing_db_files={appimage} database files were not found. Some actions will not work properly.
|
||||
|
||||
@@ -12,6 +12,8 @@ from typing import Optional
|
||||
|
||||
from bauh.api.abstract.handler import TaskManager, ProcessWatcher
|
||||
from bauh.api.http import HttpClient
|
||||
from bauh.commons.boot import CreateConfigFile
|
||||
from bauh.commons.html import bold
|
||||
from bauh.gems.appimage import get_icon_path, INSTALLATION_PATH, SYMLINKS_DIR, util, DATABASES_TS_FILE, \
|
||||
DATABASES_DIR, DATABASE_APPS_FILE, DATABASE_RELEASES_FILE, URL_COMPRESSED_DATABASES
|
||||
from bauh.gems.appimage.model import AppImage
|
||||
@@ -21,7 +23,8 @@ from bauh.view.util.translation import I18n
|
||||
class DatabaseUpdater(Thread):
|
||||
COMPRESS_FILE_PATH = '{}/db.tar.gz'.format(DATABASES_DIR)
|
||||
|
||||
def __init__(self, i18n: I18n, http_client: HttpClient, logger: logging.Logger, watcher: Optional[ProcessWatcher] = None, taskman: Optional[TaskManager] = None):
|
||||
def __init__(self, i18n: I18n, http_client: HttpClient, logger: logging.Logger, taskman: TaskManager,
|
||||
watcher: Optional[ProcessWatcher] = None, appimage_config: Optional[dict] = None, create_config: Optional[CreateConfigFile] = None):
|
||||
super(DatabaseUpdater, self).__init__(daemon=True)
|
||||
self.http_client = http_client
|
||||
self.logger = logger
|
||||
@@ -29,6 +32,9 @@ class DatabaseUpdater(Thread):
|
||||
self.taskman = taskman
|
||||
self.watcher = watcher
|
||||
self.task_id = 'appim_db'
|
||||
self.config = appimage_config
|
||||
self.create_config = create_config
|
||||
self.taskman.register_task(self.task_id, self.i18n['appimage.task.db_update'], get_icon_path())
|
||||
|
||||
def should_update(self, appimage_config: dict) -> bool:
|
||||
ti = time.time()
|
||||
@@ -75,26 +81,14 @@ class DatabaseUpdater(Thread):
|
||||
self.logger.info('Finished. Took {0:.2f} seconds'.format(time.time() - ti))
|
||||
return update
|
||||
|
||||
def register_task(self):
|
||||
if self.taskman:
|
||||
self.taskman.register_task(self.task_id, self.i18n['appimage.task.db_update'], get_icon_path())
|
||||
|
||||
def _finish_task(self):
|
||||
if self.taskman:
|
||||
self.taskman.update_progress(self.task_id, 100, None)
|
||||
self.taskman.finish_task(self.task_id)
|
||||
self.taskman = None
|
||||
self.logger.info("Finished")
|
||||
|
||||
def _update_task_progress(self, progress: float, substatus: Optional[str] = None):
|
||||
if self.taskman:
|
||||
self.taskman.update_progress(self.task_id, progress, substatus)
|
||||
self.taskman.update_progress(self.task_id, progress, substatus)
|
||||
|
||||
if self.watcher:
|
||||
self.watcher.change_substatus(substatus)
|
||||
|
||||
def download_databases(self) -> bool:
|
||||
self._update_task_progress(1, self.i18n['appimage.update_database.downloading'])
|
||||
self._update_task_progress(10, self.i18n['appimage.update_database.downloading'])
|
||||
self.logger.info('Retrieving AppImage databases')
|
||||
|
||||
database_timestamp = datetime.utcnow().timestamp()
|
||||
@@ -106,7 +100,6 @@ class DatabaseUpdater(Thread):
|
||||
|
||||
if not res:
|
||||
self.logger.warning('Could not download the database file {}'.format(URL_COMPRESSED_DATABASES))
|
||||
self._finish_task()
|
||||
return False
|
||||
|
||||
Path(DATABASES_DIR).mkdir(parents=True, exist_ok=True)
|
||||
@@ -150,11 +143,25 @@ class DatabaseUpdater(Thread):
|
||||
|
||||
self.logger.info("Database timestamp saved")
|
||||
|
||||
self._finish_task()
|
||||
return True
|
||||
|
||||
def run(self):
|
||||
self.download_databases()
|
||||
ti = time.time()
|
||||
|
||||
if self.create_config:
|
||||
self.taskman.update_progress(self.task_id, 0, self.i18n['task.waiting_task'].format(bold(self.create_config.task_name)))
|
||||
self.create_config.join()
|
||||
self.config = self.create_config.config
|
||||
|
||||
self.taskman.update_progress(self.task_id, 1, self.i18n['appimage.task.db_update.checking'])
|
||||
|
||||
if self.should_update(self.config):
|
||||
self.download_databases()
|
||||
|
||||
self.taskman.update_progress(self.task_id, 100, None)
|
||||
self.taskman.finish_task(self.task_id)
|
||||
tf = time.time()
|
||||
self.logger.info("Finished. Took {0:.2f} seconds".format(tf - ti))
|
||||
|
||||
|
||||
class SymlinksVerifier(Thread):
|
||||
@@ -165,6 +172,7 @@ class SymlinksVerifier(Thread):
|
||||
self.i18n = i18n
|
||||
self.logger = logger
|
||||
self.task_id = 'appim_symlink_check'
|
||||
self.taskman.register_task(self.task_id, self.i18n['appimage.task.symlink_check'], get_icon_path())
|
||||
|
||||
@staticmethod
|
||||
def create_symlink(app: AppImage, file_path: str, logger: logging.Logger, watcher: ProcessWatcher = None):
|
||||
@@ -222,8 +230,6 @@ class SymlinksVerifier(Thread):
|
||||
watcher.print('[error] {}'.format(msg))
|
||||
|
||||
def run(self):
|
||||
self.taskman.register_task(self.task_id, self.i18n['appimage.task.symlink_check'], get_icon_path())
|
||||
|
||||
if os.path.exists(INSTALLATION_PATH):
|
||||
installed_files = glob.glob('{}/*/*.json'.format(INSTALLATION_PATH))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user