mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-10 01:54:15 +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))
|
||||
|
||||
|
||||
@@ -1,11 +1,26 @@
|
||||
from pathlib import Path
|
||||
|
||||
from bauh.commons.config import read_config as read
|
||||
from bauh.commons.config import YAMLConfigManager
|
||||
from bauh.gems.arch import CONFIG_FILE, BUILD_DIR
|
||||
|
||||
|
||||
def read_config(update_file: bool = False) -> dict:
|
||||
template = {'optimize': True,
|
||||
def get_build_dir(arch_config: dict) -> str:
|
||||
build_dir = arch_config.get('aur_build_dir')
|
||||
|
||||
if not build_dir:
|
||||
build_dir = BUILD_DIR
|
||||
|
||||
Path(build_dir).mkdir(parents=True, exist_ok=True)
|
||||
return build_dir
|
||||
|
||||
|
||||
class ArchConfigManager(YAMLConfigManager):
|
||||
|
||||
def __init__(self):
|
||||
super(ArchConfigManager, self).__init__(config_file_path=CONFIG_FILE)
|
||||
|
||||
def get_default_config(self) -> dict:
|
||||
return {'optimize': True,
|
||||
"sync_databases": True,
|
||||
"clean_cached": True,
|
||||
'aur': True,
|
||||
@@ -24,14 +39,3 @@ def read_config(update_file: bool = False) -> dict:
|
||||
'suggest_optdep_uninstall': False,
|
||||
'aur_idx_exp': 720,
|
||||
'categories_exp': 24}
|
||||
return read(CONFIG_FILE, template, update_file=update_file)
|
||||
|
||||
|
||||
def get_build_dir(arch_config: dict) -> str:
|
||||
build_dir = arch_config.get('aur_build_dir')
|
||||
|
||||
if not build_dir:
|
||||
build_dir = BUILD_DIR
|
||||
|
||||
Path(build_dir).mkdir(parents=True, exist_ok=True)
|
||||
return build_dir
|
||||
|
||||
@@ -27,18 +27,18 @@ from bauh.api.abstract.view import MessageType, FormComponent, InputOption, Sing
|
||||
FileChooserComponent, TextComponent
|
||||
from bauh.api.constants import TEMP_DIR
|
||||
from bauh.commons import user, system
|
||||
from bauh.commons.boot import CreateConfigFile
|
||||
from bauh.commons.category import CategoriesDownloader
|
||||
from bauh.commons.config import save_config
|
||||
from bauh.commons.html import bold
|
||||
from bauh.commons.system import SystemProcess, ProcessHandler, new_subprocess, run_cmd, SimpleProcess
|
||||
from bauh.commons.util import datetime_as_milis
|
||||
from bauh.commons.view_utils import new_select
|
||||
from bauh.gems.arch import aur, pacman, makepkg, message, confirmation, disk, git, \
|
||||
gpg, URL_CATEGORIES_FILE, CATEGORIES_FILE_PATH, CUSTOM_MAKEPKG_FILE, SUGGESTIONS_FILE, \
|
||||
CONFIG_FILE, get_icon_path, database, mirrors, sorting, cpu_manager, ARCH_CACHE_PATH, UPDATES_IGNORED_FILE, \
|
||||
get_icon_path, database, mirrors, sorting, cpu_manager, UPDATES_IGNORED_FILE, \
|
||||
CONFIG_DIR, EDITABLE_PKGBUILDS_FILE, URL_GPG_SERVERS, BUILD_DIR
|
||||
from bauh.gems.arch.aur import AURClient
|
||||
from bauh.gems.arch.config import read_config, get_build_dir
|
||||
from bauh.gems.arch.config import get_build_dir, ArchConfigManager
|
||||
from bauh.gems.arch.dependencies import DependenciesAnalyser
|
||||
from bauh.gems.arch.download import MultithreadedDownloadService, ArchDownloadException
|
||||
from bauh.gems.arch.exceptions import PackageNotFoundException, PackageInHoldException
|
||||
@@ -47,8 +47,8 @@ from bauh.gems.arch.model import ArchPackage
|
||||
from bauh.gems.arch.output import TransactionStatusHandler
|
||||
from bauh.gems.arch.pacman import RE_DEP_OPERATORS
|
||||
from bauh.gems.arch.updates import UpdatesSummarizer
|
||||
from bauh.gems.arch.worker import AURIndexUpdater, ArchDiskCacheUpdater, ArchCompilationOptimizer, SyncDatabases, \
|
||||
RefreshMirrors
|
||||
from bauh.gems.arch.worker import AURIndexUpdater, ArchDiskCacheUpdater, ArchCompilationOptimizer, RefreshMirrors, \
|
||||
SyncDatabases
|
||||
|
||||
URL_GIT = 'https://aur.archlinux.org/{}.git'
|
||||
URL_SRC_INFO = 'https://aur.archlinux.org/cgit/aur.git/plain/.SRCINFO?h='
|
||||
@@ -191,11 +191,11 @@ class TransactionContext:
|
||||
|
||||
class ArchManager(SoftwareManager):
|
||||
|
||||
def __init__(self, context: ApplicationContext, disk_cache_updater: ArchDiskCacheUpdater = None):
|
||||
def __init__(self, context: ApplicationContext, disk_cache_updater: Optional[ArchDiskCacheUpdater] = None):
|
||||
super(ArchManager, self).__init__(context=context)
|
||||
self.aur_cache = context.cache_factory.new()
|
||||
# context.disk_loader_factory.map(ArchPackage, self.aur_cache) TODO
|
||||
|
||||
self.configman = ArchConfigManager()
|
||||
self.aur_mapper = AURDataMapper(http_client=context.http_client, i18n=context.i18n, logger=context.logger)
|
||||
self.i18n = context.i18n
|
||||
self.aur_client = AURClient(http_client=context.http_client, logger=context.logger, x86_64=context.is_system_x86_64())
|
||||
@@ -309,7 +309,7 @@ class ArchManager(SoftwareManager):
|
||||
type_=MessageType.ERROR)
|
||||
return False
|
||||
|
||||
sort_limit = read_config()['mirrors_sort_limit']
|
||||
sort_limit = self.configman.get_config()['mirrors_sort_limit']
|
||||
|
||||
if sort_limit is not None and isinstance(sort_limit, int) and sort_limit >= 0:
|
||||
watcher.change_substatus(self.i18n['arch.custom_action.refresh_mirrors.status.sorting'])
|
||||
@@ -419,7 +419,7 @@ class ArchManager(SoftwareManager):
|
||||
if is_url:
|
||||
return SearchResult([], [], 0)
|
||||
|
||||
arch_config = read_config()
|
||||
arch_config = self.configman.get_config()
|
||||
aur_supported = aur.is_supported(arch_config)
|
||||
|
||||
if not any([arch_config['repositories'], aur_supported]):
|
||||
@@ -563,7 +563,7 @@ class ArchManager(SoftwareManager):
|
||||
|
||||
def read_installed(self, disk_loader: Optional[DiskCacheLoader], limit: int = -1, only_apps: bool = False, pkg_types: Set[Type[SoftwarePackage]] = None, internet_available: bool = None, names: Iterable[str] = None, wait_disk_cache: bool = True) -> SearchResult:
|
||||
self.aur_client.clean_caches()
|
||||
arch_config = read_config()
|
||||
arch_config = self.configman.get_config()
|
||||
|
||||
aur_supported = aur.is_supported(arch_config)
|
||||
|
||||
@@ -781,7 +781,7 @@ class ArchManager(SoftwareManager):
|
||||
if self._is_database_locked(handler, root_password):
|
||||
return False
|
||||
|
||||
arch_config = read_config()
|
||||
arch_config = self.configman.get_config()
|
||||
aur_supported = pkg.repository == 'aur' or aur.is_supported(arch_config)
|
||||
context = TransactionContext(name=pkg.name, base=pkg.get_base_name(), skip_opt_deps=True,
|
||||
change_progress=True, dependency=False, repository=pkg.repository, pkg=pkg,
|
||||
@@ -1105,7 +1105,7 @@ class ArchManager(SoftwareManager):
|
||||
if aur_pkgs and not self._check_action_allowed(aur_pkgs[0], watcher):
|
||||
return False
|
||||
|
||||
arch_config = read_config()
|
||||
arch_config = self.configman.get_config()
|
||||
aur_supported = bool(aur_pkgs) or aur.is_supported(arch_config)
|
||||
|
||||
self._sync_databases(arch_config=arch_config, aur_supported=aur_supported,
|
||||
@@ -1392,7 +1392,7 @@ class ArchManager(SoftwareManager):
|
||||
return TransactionResult.fail()
|
||||
|
||||
removed = {}
|
||||
arch_config = read_config()
|
||||
arch_config = self.configman.get_config()
|
||||
success = self._uninstall(TransactionContext(change_progress=True,
|
||||
arch_config=arch_config,
|
||||
watcher=watcher,
|
||||
@@ -1520,7 +1520,7 @@ class ArchManager(SoftwareManager):
|
||||
else:
|
||||
self.logger.warning("Package '{}' has no commit associated with it. Current history status may not be correct.".format(pkg.name))
|
||||
|
||||
arch_config = read_config()
|
||||
arch_config = self.configman.get_config()
|
||||
temp_dir = '{}/build_{}'.format(get_build_dir(arch_config), int(time.time()))
|
||||
|
||||
try:
|
||||
@@ -1938,7 +1938,7 @@ class ArchManager(SoftwareManager):
|
||||
watcher.change_substatus(self.i18n['arch.task.aur.index.status'])
|
||||
|
||||
idx_updater = AURIndexUpdater(context=self.context, taskman=TaskManager()) # null task manager
|
||||
idx_updater.run()
|
||||
idx_updater.update_index()
|
||||
else:
|
||||
self.logger.warning("Could not update the AUR index: no internet connection detected")
|
||||
|
||||
@@ -2488,7 +2488,7 @@ class ArchManager(SoftwareManager):
|
||||
def _optimize_makepkg(self, arch_config: dict, watcher: Optional[ProcessWatcher]):
|
||||
if arch_config['optimize'] and not os.path.exists(CUSTOM_MAKEPKG_FILE):
|
||||
watcher.change_substatus(self.i18n['arch.makepkg.optimizing'])
|
||||
ArchCompilationOptimizer(arch_config=arch_config, i18n=self.i18n, logger=self.context.logger).optimize()
|
||||
ArchCompilationOptimizer(i18n=self.i18n, logger=self.context.logger, taskman=TaskManager()).optimize()
|
||||
|
||||
def install(self, pkg: ArchPackage, root_password: str, disk_loader: Optional[DiskCacheLoader], watcher: ProcessWatcher, context: TransactionContext = None) -> TransactionResult:
|
||||
self.aur_client.clean_caches()
|
||||
@@ -2504,7 +2504,7 @@ class ArchManager(SoftwareManager):
|
||||
if context:
|
||||
install_context = context
|
||||
else:
|
||||
install_context = TransactionContext.gen_context_from(pkg=pkg, handler=handler, arch_config=read_config(),
|
||||
install_context = TransactionContext.gen_context_from(pkg=pkg, handler=handler, arch_config=self.configman.get_config(),
|
||||
root_password=root_password)
|
||||
install_context.skip_opt_deps = False
|
||||
install_context.disk_loader = disk_loader
|
||||
@@ -2612,68 +2612,68 @@ class ArchManager(SoftwareManager):
|
||||
|
||||
def requires_root(self, action: SoftwareAction, pkg: ArchPackage) -> bool:
|
||||
if action == SoftwareAction.PREPARE:
|
||||
arch_config = read_config()
|
||||
arch_config = self.configman.get_config()
|
||||
aur_supported = (pkg and pkg.repository == 'aur') or aur.is_supported(arch_config)
|
||||
|
||||
if arch_config['refresh_mirrors_startup'] and mirrors.should_sync(self.logger):
|
||||
if RefreshMirrors.should_synchronize(arch_config, aur_supported, self.logger):
|
||||
return True
|
||||
|
||||
aur_supported = (pkg and pkg.repository == 'aur') or aur.is_supported(arch_config)
|
||||
return arch_config['sync_databases_startup'] and database.should_sync(arch_config, aur_supported, None, self.logger)
|
||||
return SyncDatabases.should_sync(mirrors_refreshed=False, arch_config=arch_config,
|
||||
aur_supported=aur_supported, logger=self.logger)
|
||||
|
||||
return action != SoftwareAction.SEARCH
|
||||
|
||||
def _start_category_task(self, task_man: TaskManager):
|
||||
task_man.register_task('arch_aur_cats', self.i18n['task.download_categories'], get_icon_path())
|
||||
task_man.update_progress('arch_aur_cats', 50, None)
|
||||
def _start_category_task(self, taskman: TaskManager, create_config: CreateConfigFile, downloader: CategoriesDownloader):
|
||||
taskman.update_progress('arch_aur_cats', 0, self.i18n['task.waiting_task'].format(bold(create_config.task_name)))
|
||||
create_config.join()
|
||||
arch_config = create_config.config
|
||||
|
||||
def _finish_category_task(self, task_man: TaskManager):
|
||||
task_man.update_progress('arch_aur_cats', 100, None)
|
||||
task_man.finish_task('arch_aur_cats')
|
||||
downloader.expiration = arch_config['categories_exp'] if isinstance(arch_config['categories_exp'], int) else None
|
||||
taskman.update_progress('arch_aur_cats', 50, None)
|
||||
|
||||
def _finish_category_task(self, taskman: TaskManager):
|
||||
taskman.update_progress('arch_aur_cats', 100, None)
|
||||
taskman.finish_task('arch_aur_cats')
|
||||
|
||||
def prepare(self, task_manager: TaskManager, root_password: str, internet_available: bool):
|
||||
arch_config = read_config(update_file=True)
|
||||
create_config = CreateConfigFile(taskman=task_manager, configman=self.configman, i18n=self.i18n,
|
||||
task_icon_path=get_icon_path(), logger=self.logger)
|
||||
create_config.start()
|
||||
|
||||
if internet_available and AURIndexUpdater.should_update(arch_config):
|
||||
self.index_aur = AURIndexUpdater(context=self.context, taskman=task_manager) # must all execute to properly determine the installed packages (even that AUR is disabled)
|
||||
if internet_available:
|
||||
self.index_aur = AURIndexUpdater(context=self.context, taskman=task_manager, create_config=create_config) # must always execute to properly determine the installed packages (even that AUR is disabled)
|
||||
self.index_aur.start()
|
||||
|
||||
aur_supported = aur.is_supported(arch_config)
|
||||
|
||||
if aur_supported:
|
||||
ArchCompilationOptimizer(arch_config, self.i18n, self.context.logger, task_manager).start()
|
||||
|
||||
if aur_supported or arch_config['repositories']:
|
||||
self.disk_cache_updater = ArchDiskCacheUpdater(task_man=task_manager,
|
||||
arch_config=arch_config,
|
||||
i18n=self.i18n,
|
||||
logger=self.context.logger,
|
||||
controller=self,
|
||||
internet_available=internet_available,
|
||||
aur_indexer=self.index_aur,
|
||||
aur_supported=aur_supported)
|
||||
self.disk_cache_updater.start()
|
||||
|
||||
CategoriesDownloader(id_='Arch', http_client=self.context.http_client, logger=self.context.logger,
|
||||
manager=self, url_categories_file=URL_CATEGORIES_FILE,
|
||||
categories_path=CATEGORIES_FILE_PATH,
|
||||
expiration=arch_config['categories_exp'] if isinstance(arch_config['categories_exp'], int) else '',
|
||||
internet_connection=internet_available,
|
||||
internet_checker=self.context.internet_checker,
|
||||
before=lambda: self._start_category_task(task_manager),
|
||||
after=lambda: self._finish_category_task(task_manager)).start()
|
||||
|
||||
refresh_mirrors = None
|
||||
if internet_available and arch_config['repositories'] and arch_config['refresh_mirrors_startup'] \
|
||||
and pacman.is_mirrors_available() and mirrors.should_sync(self.logger):
|
||||
|
||||
refresh_mirrors = RefreshMirrors(taskman=task_manager, i18n=self.i18n,
|
||||
root_password=root_password, logger=self.logger,
|
||||
sort_limit=arch_config['mirrors_sort_limit'])
|
||||
refresh_mirrors = RefreshMirrors(taskman=task_manager, i18n=self.i18n, root_password=root_password,
|
||||
logger=self.logger, create_config=create_config)
|
||||
refresh_mirrors.start()
|
||||
|
||||
if internet_available and (refresh_mirrors or (arch_config['sync_databases_startup'] and database.should_sync(arch_config, aur_supported, None, self.logger))):
|
||||
SyncDatabases(taskman=task_manager, root_password=root_password, i18n=self.i18n,
|
||||
logger=self.logger, refresh_mirrors=refresh_mirrors).start()
|
||||
logger=self.logger, refresh_mirrors=refresh_mirrors, create_config=create_config).start()
|
||||
|
||||
ArchCompilationOptimizer(i18n=self.i18n, logger=self.context.logger,
|
||||
taskman=task_manager, create_config=create_config).start()
|
||||
|
||||
self.disk_cache_updater = ArchDiskCacheUpdater(taskman=task_manager,
|
||||
i18n=self.i18n,
|
||||
logger=self.context.logger,
|
||||
controller=self,
|
||||
internet_available=internet_available,
|
||||
aur_indexer=self.index_aur,
|
||||
create_config=create_config)
|
||||
self.disk_cache_updater.start()
|
||||
|
||||
task_manager.register_task('arch_aur_cats', self.i18n['task.download_categories'], get_icon_path())
|
||||
cat_download = CategoriesDownloader(id_='Arch', http_client=self.context.http_client,
|
||||
logger=self.context.logger,
|
||||
manager=self, url_categories_file=URL_CATEGORIES_FILE,
|
||||
categories_path=CATEGORIES_FILE_PATH,
|
||||
internet_connection=internet_available,
|
||||
internet_checker=self.context.internet_checker,
|
||||
after=lambda: self._finish_category_task(task_manager))
|
||||
cat_download.before = lambda: self._start_category_task(taskman=task_manager, create_config=create_config,
|
||||
downloader=cat_download)
|
||||
cat_download.start()
|
||||
|
||||
def list_updates(self, internet_available: bool) -> List[PackageUpdate]:
|
||||
installed = self.read_installed(disk_loader=None, internet_available=internet_available).installed
|
||||
@@ -2763,90 +2763,92 @@ class ArchManager(SoftwareManager):
|
||||
capitalize_label=capitalize_label)
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent:
|
||||
local_config = read_config()
|
||||
arch_config = self.configman.get_config()
|
||||
max_width = floor(screen_width * 0.25)
|
||||
|
||||
db_sync_start = self._gen_bool_selector(id_='sync_dbs_start',
|
||||
label_key='arch.config.sync_dbs',
|
||||
tooltip_key='arch.config.sync_dbs_start.tip',
|
||||
value=bool(local_config['sync_databases_startup']),
|
||||
value=bool(arch_config['sync_databases_startup']),
|
||||
max_width=max_width)
|
||||
|
||||
db_sync_start.label += ' ( {} )'.format(self.i18n['initialization'].capitalize())
|
||||
db_sync_start.label += ' ({})'.format(self.i18n['initialization'].capitalize())
|
||||
|
||||
fields = [
|
||||
self._gen_bool_selector(id_='repos',
|
||||
label_key='arch.config.repos',
|
||||
tooltip_key='arch.config.repos.tip',
|
||||
value=bool(local_config['repositories']),
|
||||
value=bool(arch_config['repositories']),
|
||||
max_width=max_width),
|
||||
self._gen_bool_selector(id_='aur',
|
||||
label_key='arch.config.aur',
|
||||
tooltip_key='arch.config.aur.tip',
|
||||
value=local_config['aur'],
|
||||
value=arch_config['aur'],
|
||||
max_width=max_width,
|
||||
capitalize_label=False),
|
||||
self._gen_bool_selector(id_='opts',
|
||||
label_key='arch.config.optimize',
|
||||
tooltip_key='arch.config.optimize.tip',
|
||||
value=bool(local_config['optimize']),
|
||||
value=bool(arch_config['optimize']),
|
||||
label_params=['(AUR)'],
|
||||
capitalize_label=False,
|
||||
max_width=max_width),
|
||||
self._gen_bool_selector(id_='autoprovs',
|
||||
label_key='arch.config.automatch_providers',
|
||||
tooltip_key='arch.config.automatch_providers.tip',
|
||||
value=bool(local_config['automatch_providers']),
|
||||
value=bool(arch_config['automatch_providers']),
|
||||
max_width=max_width),
|
||||
self._gen_bool_selector(id_='check_dependency_breakage',
|
||||
label_key='arch.config.check_dependency_breakage',
|
||||
tooltip_key='arch.config.check_dependency_breakage.tip',
|
||||
value=bool(local_config['check_dependency_breakage']),
|
||||
value=bool(arch_config['check_dependency_breakage']),
|
||||
max_width=max_width),
|
||||
self._gen_bool_selector(id_='mthread_download',
|
||||
label_key='arch.config.pacman_mthread_download',
|
||||
tooltip_key='arch.config.pacman_mthread_download.tip',
|
||||
value=local_config['repositories_mthread_download'],
|
||||
value=arch_config['repositories_mthread_download'],
|
||||
max_width=max_width,
|
||||
capitalize_label=True),
|
||||
self._gen_bool_selector(id_='sync_dbs',
|
||||
label_key='arch.config.sync_dbs',
|
||||
tooltip_key='arch.config.sync_dbs.tip',
|
||||
value=bool(local_config['sync_databases']),
|
||||
value=bool(arch_config['sync_databases']),
|
||||
max_width=max_width),
|
||||
db_sync_start,
|
||||
self._gen_bool_selector(id_='clean_cached',
|
||||
label_key='arch.config.clean_cache',
|
||||
tooltip_key='arch.config.clean_cache.tip',
|
||||
value=bool(local_config['clean_cached']),
|
||||
value=bool(arch_config['clean_cached']),
|
||||
max_width=max_width),
|
||||
self._gen_bool_selector(id_='suggest_unneeded_uninstall',
|
||||
label_key='arch.config.suggest_unneeded_uninstall',
|
||||
tooltip_params=['"{}"'.format(self.i18n['arch.config.suggest_optdep_uninstall'])],
|
||||
tooltip_key='arch.config.suggest_unneeded_uninstall.tip',
|
||||
value=bool(local_config['suggest_unneeded_uninstall']),
|
||||
value=bool(arch_config['suggest_unneeded_uninstall']),
|
||||
max_width=max_width),
|
||||
self._gen_bool_selector(id_='suggest_optdep_uninstall',
|
||||
label_key='arch.config.suggest_optdep_uninstall',
|
||||
tooltip_key='arch.config.suggest_optdep_uninstall.tip',
|
||||
value=bool(local_config['suggest_optdep_uninstall']),
|
||||
value=bool(arch_config['suggest_optdep_uninstall']),
|
||||
max_width=max_width),
|
||||
self._gen_bool_selector(id_='ref_mirs',
|
||||
label_key='arch.config.refresh_mirrors',
|
||||
tooltip_key='arch.config.refresh_mirrors.tip',
|
||||
value=bool(local_config['refresh_mirrors_startup']),
|
||||
value=bool(arch_config['refresh_mirrors_startup']),
|
||||
max_width=max_width),
|
||||
TextInputComponent(id_='mirrors_sort_limit',
|
||||
label=self.i18n['arch.config.mirrors_sort_limit'],
|
||||
tooltip=self.i18n['arch.config.mirrors_sort_limit.tip'],
|
||||
only_int=True,
|
||||
max_width=max_width,
|
||||
value=local_config['mirrors_sort_limit'] if isinstance(local_config['mirrors_sort_limit'], int) else ''),
|
||||
value=arch_config['mirrors_sort_limit'] if isinstance(arch_config['mirrors_sort_limit'], int) else ''),
|
||||
TextInputComponent(id_='aur_idx_exp',
|
||||
label=self.i18n['arch.config.aur_idx_exp'] + ' (AUR)',
|
||||
tooltip=self.i18n['arch.config.aur_idx_exp.tip'],
|
||||
max_width=max_width,
|
||||
only_int=True,
|
||||
capitalize_label=False,
|
||||
value=local_config['aur_idx_exp'] if isinstance(local_config['aur_idx_exp'], int) else ''),
|
||||
value=arch_config['aur_idx_exp'] if isinstance(arch_config['aur_idx_exp'], int) else ''),
|
||||
new_select(id_='aur_build_only_chosen',
|
||||
label=self.i18n['arch.config.aur_build_only_chosen'],
|
||||
tip=self.i18n['arch.config.aur_build_only_chosen.tip'],
|
||||
@@ -2854,7 +2856,7 @@ class ArchManager(SoftwareManager):
|
||||
(self.i18n['no'].capitalize(), False, None),
|
||||
(self.i18n['ask'].capitalize(), None, None),
|
||||
],
|
||||
value=local_config['aur_build_only_chosen'],
|
||||
value=arch_config['aur_build_only_chosen'],
|
||||
max_width=max_width,
|
||||
type_=SelectViewType.RADIO,
|
||||
capitalize_label=False),
|
||||
@@ -2865,21 +2867,21 @@ class ArchManager(SoftwareManager):
|
||||
(self.i18n['no'].capitalize(), False, None),
|
||||
(self.i18n['ask'].capitalize(), None, None),
|
||||
],
|
||||
value=local_config['edit_aur_pkgbuild'],
|
||||
value=arch_config['edit_aur_pkgbuild'],
|
||||
max_width=max_width,
|
||||
type_=SelectViewType.RADIO,
|
||||
capitalize_label=False),
|
||||
self._gen_bool_selector(id_='aur_remove_build_dir',
|
||||
label_key='arch.config.aur_remove_build_dir',
|
||||
tooltip_key='arch.config.aur_remove_build_dir.tip',
|
||||
value=bool(local_config['aur_remove_build_dir']),
|
||||
value=bool(arch_config['aur_remove_build_dir']),
|
||||
max_width=max_width,
|
||||
capitalize_label=False),
|
||||
FileChooserComponent(id_='aur_build_dir',
|
||||
label=self.i18n['arch.config.aur_build_dir'],
|
||||
tooltip=self.i18n['arch.config.aur_build_dir.tip'].format(BUILD_DIR),
|
||||
max_width=max_width,
|
||||
file_path=local_config['aur_build_dir'],
|
||||
file_path=arch_config['aur_build_dir'],
|
||||
capitalize_label=False,
|
||||
directory=True),
|
||||
TextInputComponent(id_='arch_cats_exp',
|
||||
@@ -2888,47 +2890,47 @@ class ArchManager(SoftwareManager):
|
||||
max_width=max_width,
|
||||
only_int=True,
|
||||
capitalize_label=False,
|
||||
value=local_config['categories_exp'] if isinstance(local_config['categories_exp'], int) else ''),
|
||||
value=arch_config['categories_exp'] if isinstance(arch_config['categories_exp'], int) else ''),
|
||||
]
|
||||
|
||||
return PanelComponent([FormComponent(fields, spaces=False)])
|
||||
|
||||
def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
config = read_config()
|
||||
arch_config = self.configman.get_config()
|
||||
|
||||
panel = component.components[0]
|
||||
config['repositories'] = panel.get_component('repos').get_selected()
|
||||
config['aur'] = panel.get_component('aur').get_selected()
|
||||
config['optimize'] = panel.get_component('opts').get_selected()
|
||||
config['sync_databases'] = panel.get_component('sync_dbs').get_selected()
|
||||
config['sync_databases_startup'] = panel.get_component('sync_dbs_start').get_selected()
|
||||
config['clean_cached'] = panel.get_component('clean_cached').get_selected()
|
||||
config['refresh_mirrors_startup'] = panel.get_component('ref_mirs').get_selected()
|
||||
config['mirrors_sort_limit'] = panel.get_component('mirrors_sort_limit').get_int_value()
|
||||
config['repositories_mthread_download'] = panel.get_component('mthread_download').get_selected()
|
||||
config['automatch_providers'] = panel.get_component('autoprovs').get_selected()
|
||||
config['edit_aur_pkgbuild'] = panel.get_component('edit_aur_pkgbuild').get_selected()
|
||||
config['aur_remove_build_dir'] = panel.get_component('aur_remove_build_dir').get_selected()
|
||||
config['aur_build_dir'] = panel.get_component('aur_build_dir').file_path
|
||||
config['aur_build_only_chosen'] = panel.get_component('aur_build_only_chosen').get_selected()
|
||||
config['aur_idx_exp'] = panel.get_component('aur_idx_exp').get_int_value()
|
||||
config['check_dependency_breakage'] = panel.get_component('check_dependency_breakage').get_selected()
|
||||
config['suggest_optdep_uninstall'] = panel.get_component('suggest_optdep_uninstall').get_selected()
|
||||
config['suggest_unneeded_uninstall'] = panel.get_component('suggest_unneeded_uninstall').get_selected()
|
||||
config['categories_exp'] = panel.get_component('arch_cats_exp').get_int_value()
|
||||
arch_config['repositories'] = panel.get_component('repos').get_selected()
|
||||
arch_config['aur'] = panel.get_component('aur').get_selected()
|
||||
arch_config['optimize'] = panel.get_component('opts').get_selected()
|
||||
arch_config['sync_databases'] = panel.get_component('sync_dbs').get_selected()
|
||||
arch_config['sync_databases_startup'] = panel.get_component('sync_dbs_start').get_selected()
|
||||
arch_config['clean_cached'] = panel.get_component('clean_cached').get_selected()
|
||||
arch_config['refresh_mirrors_startup'] = panel.get_component('ref_mirs').get_selected()
|
||||
arch_config['mirrors_sort_limit'] = panel.get_component('mirrors_sort_limit').get_int_value()
|
||||
arch_config['repositories_mthread_download'] = panel.get_component('mthread_download').get_selected()
|
||||
arch_config['automatch_providers'] = panel.get_component('autoprovs').get_selected()
|
||||
arch_config['edit_aur_pkgbuild'] = panel.get_component('edit_aur_pkgbuild').get_selected()
|
||||
arch_config['aur_remove_build_dir'] = panel.get_component('aur_remove_build_dir').get_selected()
|
||||
arch_config['aur_build_dir'] = panel.get_component('aur_build_dir').file_path
|
||||
arch_config['aur_build_only_chosen'] = panel.get_component('aur_build_only_chosen').get_selected()
|
||||
arch_config['aur_idx_exp'] = panel.get_component('aur_idx_exp').get_int_value()
|
||||
arch_config['check_dependency_breakage'] = panel.get_component('check_dependency_breakage').get_selected()
|
||||
arch_config['suggest_optdep_uninstall'] = panel.get_component('suggest_optdep_uninstall').get_selected()
|
||||
arch_config['suggest_unneeded_uninstall'] = panel.get_component('suggest_unneeded_uninstall').get_selected()
|
||||
arch_config['categories_exp'] = panel.get_component('arch_cats_exp').get_int_value()
|
||||
|
||||
if not config['aur_build_dir']:
|
||||
config['aur_build_dir'] = None
|
||||
if not arch_config['aur_build_dir']:
|
||||
arch_config['aur_build_dir'] = None
|
||||
|
||||
try:
|
||||
save_config(config, CONFIG_FILE)
|
||||
self.configman.save_config(arch_config)
|
||||
return True, None
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
|
||||
def get_upgrade_requirements(self, pkgs: List[ArchPackage], root_password: str, watcher: ProcessWatcher) -> UpgradeRequirements:
|
||||
self.aur_client.clean_caches()
|
||||
arch_config = read_config()
|
||||
arch_config = self.configman.get_config()
|
||||
|
||||
aur_supported = aur.is_supported(arch_config)
|
||||
|
||||
@@ -2949,7 +2951,7 @@ class ArchManager(SoftwareManager):
|
||||
def get_custom_actions(self) -> List[CustomSoftwareAction]:
|
||||
actions = []
|
||||
|
||||
arch_config = read_config()
|
||||
arch_config = self.configman.get_config()
|
||||
|
||||
if pacman.is_mirrors_available():
|
||||
actions.append(self.custom_actions['ref_mirrors'])
|
||||
|
||||
@@ -497,7 +497,8 @@ def get_current_mirror_countries() -> List[str]:
|
||||
|
||||
|
||||
def is_mirrors_available() -> bool:
|
||||
return bool(run_cmd('which pacman-mirrors', print_error=False))
|
||||
code, _ = system.execute(cmd='which pacman-mirrors', output=False)
|
||||
return code == 0
|
||||
|
||||
|
||||
def map_update_sizes(pkgs: List[str]) -> Dict[str, int]: # bytes:
|
||||
|
||||
@@ -53,12 +53,12 @@ arch.config.aur_idx_exp=Index expiration
|
||||
arch.config.aur_idx_exp.tip=It defines the period (in minutes) for the AUR index stored in disc to be considered valid during the initialization process. Use 0 so that it is always updated.
|
||||
arch.config.mirrors_sort_limit=Mirrors sort limit
|
||||
arch.config.mirrors_sort_limit.tip=Defines the maximum number of mirrors that will be used for speed sorting. Use 0 for no limit or leave it blank to disable sorting.
|
||||
arch.config.optimize=optimize
|
||||
arch.config.optimize=Optimize {}
|
||||
arch.config.optimize.tip=La configuració optimitzada s'utilitzarà per fer més ràpida la instal·lació, actualització i reversió dels paquets, en cas contrari s'utilitzarà la configuració del sistema.
|
||||
arch.config.pacman_mthread_download=Multithreaded download (repositories)
|
||||
arch.config.pacman_mthread_download.tip=Whether the repository packages should be downloaded with a tool that works with threads (it may be faster). pacman-mirrors must be installed.
|
||||
arch.config.refresh_mirrors=Refresh mirrors on startup
|
||||
arch.config.refresh_mirrors.tip=Refresh the package mirrors once a day on startup ( or after a device reboot )
|
||||
arch.config.refresh_mirrors.tip=Refresh the package mirrors once a day on startup
|
||||
arch.config.repos=Repositories packages
|
||||
arch.config.repos.tip=It allows to manage packages from the repositories set
|
||||
arch.config.suggest_optdep_uninstall=Uninstall optional dependencies
|
||||
@@ -210,11 +210,15 @@ arch.substatus.pre_hooks=Running pre-transaction hooks
|
||||
arch.sync.dep_breakage.reason={} requires {}
|
||||
arch.sync_databases.substatus=Synchronizing package databases
|
||||
arch.sync_databases.substatus.error=It was not possible to synchronize the package database
|
||||
arch.sync_databases.substatus.synchronized=Synchronized
|
||||
arch.task.aur.index.status=Generating local AUR index
|
||||
arch.task.aur.index.substatus.checking=Checking for updates
|
||||
arch.task.aur.index.substatus.download=Downloading the AUR index
|
||||
arch.task.aur.index.substatus.error.download=Connection error while downloading the index
|
||||
arch.task.aur.index.substatus.error.no_data=Error: empty index
|
||||
arch.task.aur.index.substatus.gen_index=Generating index
|
||||
arch.task.checking_settings=Checking settings
|
||||
arch.task.disabled=Disabled
|
||||
arch.task.disk_cache=Indexing packages data
|
||||
arch.task.disk_cache.checking=Checking index
|
||||
arch.task.disk_cache.indexed=Indexed
|
||||
@@ -222,8 +226,8 @@ arch.task.disk_cache.indexing=Indexing
|
||||
arch.task.disk_cache.reading_files=Reading files
|
||||
arch.task.disk_cache.waiting_aur_index=Waiting {}
|
||||
arch.task.mirrors=Refreshing mirrors
|
||||
arch.task.mirrors.cached=Refreshed
|
||||
arch.task.optimizing=Optimizing {}
|
||||
arch.task.sync_databases.waiting=Waiting for {}
|
||||
arch.task.sync_sb.status=Actualitzen {}
|
||||
arch.uninstall.clean_cached.error=No s'ha pogut eliminar {} versions antigues que es troba al disc
|
||||
arch.uninstall.clean_cached.substatus=Eliminació de versions antigues del disc
|
||||
|
||||
@@ -53,12 +53,12 @@ arch.config.aur_idx_exp=Index expiration
|
||||
arch.config.aur_idx_exp.tip=It defines the period (in minutes) for the AUR index stored in disc to be considered valid during the initialization process. Use 0 so that it is always updated.
|
||||
arch.config.mirrors_sort_limit=Mirrors sort limit
|
||||
arch.config.mirrors_sort_limit.tip=Defines the maximum number of mirrors that will be used for speed sorting. Use 0 for no limit or leave it blank to disable sorting.
|
||||
arch.config.optimize=optimize
|
||||
arch.config.optimize=Optimize {}
|
||||
arch.config.optimize.tip=Optimized settings will be used in order to make the packages installation, upgrading and downgrading faster, otherwise the system settings will be used
|
||||
arch.config.pacman_mthread_download=Multithreaded download (repositories)
|
||||
arch.config.pacman_mthread_download.tip=Whether the repository packages should be downloaded with a tool that works with threads (it may be faster). pacman-mirrors must be installed.
|
||||
arch.config.refresh_mirrors=Refresh mirrors on startup
|
||||
arch.config.refresh_mirrors.tip=Refresh the package mirrors once a day on startup ( or after a device reboot )
|
||||
arch.config.refresh_mirrors.tip=Refresh the package mirrors once a day on startup
|
||||
arch.config.repos=Repositories packages
|
||||
arch.config.repos.tip=It allows to manage packages from the repositories set
|
||||
arch.config.suggest_optdep_uninstall=Uninstall optional dependencies
|
||||
@@ -210,11 +210,15 @@ arch.substatus.pre_hooks=Running pre-transaction hooks
|
||||
arch.sync.dep_breakage.reason={} requires {}
|
||||
arch.sync_databases.substatus=Synchronizing package databases
|
||||
arch.sync_databases.substatus.error=It was not possible to synchronize the package database
|
||||
arch.sync_databases.substatus.synchronized=Synchronized
|
||||
arch.task.aur.index.status=Generating local AUR index
|
||||
arch.task.aur.index.substatus.checking=Checking for updates
|
||||
arch.task.aur.index.substatus.download=Downloading the AUR index
|
||||
arch.task.aur.index.substatus.error.download=Connection error while downloading the index
|
||||
arch.task.aur.index.substatus.error.no_data=Error: empty index
|
||||
arch.task.aur.index.substatus.gen_index=Generating index
|
||||
arch.task.checking_settings=Checking settings
|
||||
arch.task.disabled=Disabled
|
||||
arch.task.disk_cache=Indexing packages data
|
||||
arch.task.disk_cache.checking=Checking index
|
||||
arch.task.disk_cache.indexed=Indexed
|
||||
@@ -222,8 +226,8 @@ arch.task.disk_cache.indexing=Indexing
|
||||
arch.task.disk_cache.reading_files=Reading files
|
||||
arch.task.disk_cache.waiting_aur_index=Waiting {}
|
||||
arch.task.mirrors=Refreshing mirrors
|
||||
arch.task.mirrors.cached=Refreshed
|
||||
arch.task.optimizing=Optimizing {}
|
||||
arch.task.sync_databases.waiting=Waiting for {}
|
||||
arch.task.sync_sb.status=Updating {}
|
||||
arch.uninstall.clean_cached.error=It was not possible to remove old {} versions found on disk
|
||||
arch.uninstall.clean_cached.substatus=Removing old versions from disk
|
||||
|
||||
@@ -53,12 +53,12 @@ arch.config.aur_idx_exp=Index expiration
|
||||
arch.config.aur_idx_exp.tip=It defines the period (in minutes) for the AUR index stored in disc to be considered valid during the initialization process. Use 0 so that it is always updated.
|
||||
arch.config.mirrors_sort_limit=Mirrors sort limit
|
||||
arch.config.mirrors_sort_limit.tip=Defines the maximum number of mirrors that will be used for speed sorting. Use 0 for no limit or leave it blank to disable sorting.
|
||||
arch.config.optimize=optimize
|
||||
arch.config.optimize=Optimize {}
|
||||
arch.config.optimize.tip=Optimized settings will be used in order to make the packages installation, upgrading and downgrading faster, otherwise the system settings will be used
|
||||
arch.config.pacman_mthread_download=Multi-threaded download (repositories)
|
||||
arch.config.pacman_mthread_download.tip=Whether the repository packages should be downloaded with a tool that works with threads (it may be faster). pacman-mirrors must be installed.
|
||||
arch.config.refresh_mirrors=Refresh mirrors on startup
|
||||
arch.config.refresh_mirrors.tip=Refresh the package mirrors once a day on startup ( or after a device reboot )
|
||||
arch.config.refresh_mirrors.tip=Refresh the package mirrors once a day on startup
|
||||
arch.config.repos=Repositories packages
|
||||
arch.config.repos.tip=It allows to manage packages from the repositories set
|
||||
arch.config.suggest_optdep_uninstall=Uninstall optional dependencies
|
||||
@@ -210,11 +210,15 @@ arch.substatus.pre_hooks=Running pre-transaction hooks
|
||||
arch.sync.dep_breakage.reason={} requires {}
|
||||
arch.sync_databases.substatus=Synchronizing package databases
|
||||
arch.sync_databases.substatus.error=It was not possible to synchronize the package database
|
||||
arch.sync_databases.substatus.synchronized=Synchronized
|
||||
arch.task.aur.index.status=Generating local AUR index
|
||||
arch.task.aur.index.substatus.checking=Checking for updates
|
||||
arch.task.aur.index.substatus.download=Downloading the AUR index
|
||||
arch.task.aur.index.substatus.error.download=Connection error while downloading the index
|
||||
arch.task.aur.index.substatus.error.no_data=Error: empty index
|
||||
arch.task.aur.index.substatus.gen_index=Generating index
|
||||
arch.task.checking_settings=Checking settings
|
||||
arch.task.disabled=Disabled
|
||||
arch.task.disk_cache=Indexing packages data
|
||||
arch.task.disk_cache.checking=Checking index
|
||||
arch.task.disk_cache.indexed=Indexed
|
||||
@@ -222,8 +226,8 @@ arch.task.disk_cache.indexing=Indexing
|
||||
arch.task.disk_cache.reading_files=Reading files
|
||||
arch.task.disk_cache.waiting_aur_index=Waiting {}
|
||||
arch.task.mirrors=Refreshing mirrors
|
||||
arch.task.mirrors.cached=Refreshed
|
||||
arch.task.optimizing=Optimizing {}
|
||||
arch.task.sync_databases.waiting=Waiting for {}
|
||||
arch.task.sync_sb.status=Updating {}
|
||||
arch.uninstall.clean_cached.error=It was not possible to remove old {} versions found on disk
|
||||
arch.uninstall.clean_cached.substatus=Removing old versions from disk
|
||||
|
||||
@@ -53,12 +53,12 @@ arch.config.aur_idx_exp=Expiración del índice
|
||||
arch.config.aur_idx_exp.tip=Define el período (en minutos) para que el índice AUR almacenado en el disco se considere válido durante el proceso de inicialización. Utilice 0 para que esté siempre actualizado.
|
||||
arch.config.mirrors_sort_limit=Límite de ordenación de espejos
|
||||
arch.config.mirrors_sort_limit.tip=Define el número máximo de espejos que se utilizarán para la ordenación por velocidad. Use 0 para no limitar o déjelo en blanco para deshabilitar la clasificación.
|
||||
arch.config.optimize=optimizar
|
||||
arch.config.optimize=Optimizar {}
|
||||
arch.config.optimize.tip=Se usará la configuración optimizada para que la instalación, actualización y reversión de los paquetes sean más rápidas, de lo contrario se usará la configuración del sistema
|
||||
arch.config.pacman_mthread_download=Descarga segmentada (repositorios)
|
||||
arch.config.pacman_mthread_download.tip=Si los paquetes de los repositorios deben descargarse con una herramienta que usa segmentación/threads (puede ser más rápido). pacman-mirrors necesita estar instalado.
|
||||
arch.config.refresh_mirrors=Actualizar espejos al iniciar
|
||||
arch.config.refresh_mirrors.tip=Actualiza los espejos de paquetes una vez al día al iniciar ( o después de reiniciar el dispositivo )
|
||||
arch.config.refresh_mirrors.tip=Actualiza los espejos de paquetes una vez al día al iniciar
|
||||
arch.config.repos=Paquetes de repositorios
|
||||
arch.config.repos.tip=Permite gestionar paquetes de los repositorios configurados
|
||||
arch.config.suggest_optdep_uninstall=Desinstalar dependencias opcionales
|
||||
@@ -210,11 +210,15 @@ arch.substatus.pre_hooks=Ejecutando ganchos pre-transacción
|
||||
arch.sync.dep_breakage.reason={} necesita de {}
|
||||
arch.sync_databases.substatus=Sincronizando bases de paquetes
|
||||
arch.sync_databases.substatus.error=No fue posible sincronizar la base de paquetes
|
||||
arch.sync_databases.substatus.synchronized=Sincronizado
|
||||
arch.task.aur.index.status=Generando índice local del AUR
|
||||
arch.task.aur.index.substatus.checking=Buscando actualizaciones
|
||||
arch.task.aur.index.substatus.download=Descargando el índice
|
||||
arch.task.aur.index.substatus.error.download=Error de conexión al descargar el índice
|
||||
arch.task.aur.index.substatus.error.no_data=Error: índice vacío
|
||||
arch.task.aur.index.substatus.gen_index=Generando índice
|
||||
arch.task.checking_settings=Verificando configuraciones
|
||||
arch.task.disabled=Deshabilitado
|
||||
arch.task.disk_cache=Indexando datos de paquetes
|
||||
arch.task.disk_cache.checking=Comprobando índice
|
||||
arch.task.disk_cache.indexed=Indexados
|
||||
@@ -222,8 +226,8 @@ arch.task.disk_cache.indexing=Indexando
|
||||
arch.task.disk_cache.reading_files=Lendo archivos
|
||||
arch.task.disk_cache.waiting_aur_index=Esperando {}
|
||||
arch.task.mirrors=Actualizando espejos
|
||||
arch.task.mirrors.cached=Actualizados
|
||||
arch.task.optimizing=Optimizando {}
|
||||
arch.task.sync_databases.waiting=Esperando por {}
|
||||
arch.task.sync_sb.status=Actualizando {}
|
||||
arch.uninstall.clean_cached.error=No fue posible eliminar versiones antiguas de {} encontradas en disco
|
||||
arch.uninstall.clean_cached.substatus=Eliminando versiones antiguas del disco
|
||||
|
||||
@@ -53,12 +53,12 @@ arch.config.aur_idx_exp=Index expiration
|
||||
arch.config.aur_idx_exp.tip=It defines the period (in minutes) for the AUR index stored in disc to be considered valid during the initialization process. Use 0 so that it is always updated.
|
||||
arch.config.mirrors_sort_limit=Limite de tri des miroirs
|
||||
arch.config.mirrors_sort_limit.tip=Définit le nombre maximal de miroirs utilisés pour trier vite. 0 pour aucune limite ou vide pour désactiver le tri.
|
||||
arch.config.optimize=optimizer
|
||||
arch.config.optimize=Optimizer {}
|
||||
arch.config.optimize.tip=Utiliser des paramètres optimisés pour rendre l'installation, mise à jour et downgrade des paquets plus rapide. À défaut, les paramètres systèmes seront utilisés.
|
||||
arch.config.pacman_mthread_download=Téléchargement parallèle (repos)
|
||||
arch.config.pacman_mthread_download.tip=Si il faut utiliser un outil qui télécharge les paquets du répos en parallèle (plus rapide). pacman-mirrors doit être installé.
|
||||
arch.config.refresh_mirrors=Actualiser les miroirs au démarrage
|
||||
arch.config.refresh_mirrors.tip=Actualiser les miroirs du paquet une fois par jour au démarrage ( ou après redémarrage système )
|
||||
arch.config.refresh_mirrors.tip=Actualiser les miroirs du paquet une fois par jour au démarrage
|
||||
arch.config.repos=Repos des paquets
|
||||
arch.config.repos.tip=Permet de gerer les paquets du repo
|
||||
arch.config.suggest_optdep_uninstall=Désinstaller les dépendances optionnelles
|
||||
@@ -210,11 +210,15 @@ arch.substatus.pre_hooks=Éxécution des pre-transaction hooks
|
||||
arch.sync.dep_breakage.reason={} requiert {}
|
||||
arch.sync_databases.substatus=Synchronisation des bases de données du paquet
|
||||
arch.sync_databases.substatus.error=Impossible de synchroniser les bases de données du paquet
|
||||
arch.sync_databases.substatus.synchronized=Synchronized
|
||||
arch.task.aur.index.status=Generating local AUR index
|
||||
arch.task.aur.index.substatus.checking=Checking for updates
|
||||
arch.task.aur.index.substatus.download=Downloading the AUR index
|
||||
arch.task.aur.index.substatus.error.download=Connection error while downloading the index
|
||||
arch.task.aur.index.substatus.error.no_data=Error: empty index
|
||||
arch.task.aur.index.substatus.gen_index=Generating index
|
||||
arch.task.checking_settings=Checking settings
|
||||
arch.task.disabled=Disabled
|
||||
arch.task.disk_cache=Indexation des données des paquets
|
||||
arch.task.disk_cache.checking=Verification de l'index
|
||||
arch.task.disk_cache.indexed=Indexé
|
||||
@@ -222,8 +226,8 @@ arch.task.disk_cache.indexing=Indexation
|
||||
arch.task.disk_cache.reading_files=Lecture des fichiers
|
||||
arch.task.disk_cache.waiting_aur_index=Waiting {}
|
||||
arch.task.mirrors=Mise à jour des miroirs
|
||||
arch.task.mirrors.cached=Refreshed
|
||||
arch.task.optimizing=Optimisation {}
|
||||
arch.task.sync_databases.waiting=Attente de {}
|
||||
arch.task.sync_sb.status=Mise à jour {}
|
||||
arch.uninstall.clean_cached.error=Impossible de supprimer les anciennes version de {} trouvées sur le disque
|
||||
arch.uninstall.clean_cached.substatus=Suppression des anciennes versions
|
||||
|
||||
@@ -53,12 +53,12 @@ arch.config.aur_idx_exp=Index expiration
|
||||
arch.config.aur_idx_exp.tip=It defines the period (in minutes) for the AUR index stored in disc to be considered valid during the initialization process. Use 0 so that it is always updated.
|
||||
arch.config.mirrors_sort_limit=Mirrors sort limit
|
||||
arch.config.mirrors_sort_limit.tip=Defines the maximum number of mirrors that will be used for speed sorting. Use 0 for no limit or leave it blank to disable sorting.
|
||||
arch.config.optimize=optimize
|
||||
arch.config.optimize=Optimize {}
|
||||
arch.config.optimize.tip=Verranno utilizzate le impostazioni ottimizzate per velocizzare l'installazione, l'aggiornamento e l'inversione dei pacchetti, altrimenti verranno utilizzate le impostazioni di sistema
|
||||
arch.config.pacman_mthread_download=Multithreaded download (repositories)
|
||||
arch.config.pacman_mthread_download.tip=Whether the repository packages should be downloaded with a tool that works with threads (it may be faster). pacman-mirrors must be installed.
|
||||
arch.config.refresh_mirrors=Refresh mirrors on startup
|
||||
arch.config.refresh_mirrors.tip=Refresh the package mirrors once a day on startup ( or after a device reboot )
|
||||
arch.config.refresh_mirrors.tip=Refresh the package mirrors once a day on startup
|
||||
arch.config.repos=Repositories packages
|
||||
arch.config.repos.tip=It allows to manage packages from the repositories set
|
||||
arch.config.suggest_optdep_uninstall=Uninstall optional dependencies
|
||||
@@ -210,11 +210,15 @@ arch.substatus.pre_hooks=Running pre-transaction hooks
|
||||
arch.sync.dep_breakage.reason={} requires {}
|
||||
arch.sync_databases.substatus=Synchronizing package databases
|
||||
arch.sync_databases.substatus.error=It was not possible to synchronize the package database
|
||||
arch.sync_databases.substatus.synchronized=Synchronized
|
||||
arch.task.aur.index.status=Generating local AUR index
|
||||
arch.task.aur.index.substatus.checking=Checking for updates
|
||||
arch.task.aur.index.substatus.download=Downloading the AUR index
|
||||
arch.task.aur.index.substatus.error.download=Connection error while downloading the index
|
||||
arch.task.aur.index.substatus.error.no_data=Error: empty index
|
||||
arch.task.aur.index.substatus.gen_index=Generating index
|
||||
arch.task.checking_settings=Checking settings
|
||||
arch.task.disabled=Disabled
|
||||
arch.task.disk_cache=Indexing packages data
|
||||
arch.task.disk_cache.checking=Checking index
|
||||
arch.task.disk_cache.indexed=Indexed
|
||||
@@ -222,8 +226,8 @@ arch.task.disk_cache.indexing=Indexing
|
||||
arch.task.disk_cache.reading_files=Reading files
|
||||
arch.task.disk_cache.waiting_aur_index=Waiting {}
|
||||
arch.task.mirrors=Aggiornando i mirror
|
||||
arch.task.mirrors.cached=Refreshed
|
||||
arch.task.optimizing=Ottimizzando {}
|
||||
arch.task.sync_databases.waiting=Waiting for {}
|
||||
arch.task.sync_sb.status=Aggiornando {}
|
||||
arch.uninstall.clean_cached.error=Non è stato possibile rimuovere le vecchie {} versioni trovate sul disco
|
||||
arch.uninstall.clean_cached.substatus=Rimozione di versioni precedenti dal disco
|
||||
|
||||
@@ -53,7 +53,7 @@ arch.config.aur_idx_exp=Expiração do índice
|
||||
arch.config.aur_idx_exp.tip=Define o período (em minutos) em que o índice do AUR armazenado em disco é considerado válido durante a inicialização. Utilize 0 para que ele sempre seja atualizado.
|
||||
arch.config.mirrors_sort_limit=Limite de ordenação de espelhos
|
||||
arch.config.mirrors_sort_limit.tip=Define o número máximo de espelhos que serão utilizados para a ordenação por velocidade. Utilize 0 para não limitar ou deixe em branco para desabilitar a ordenação.
|
||||
arch.config.optimize=Otimizar
|
||||
arch.config.optimize=Otimizar {}
|
||||
arch.config.pacman_mthread_download=Download segmentado (repositórios)
|
||||
arch.config.pacman_mthread_download.tip=Se os pacotes dos repositórios devem baixados através de uma ferramenta que trabalha com segmentação/threads (pode ser mais rápido). pacman-mirrors precisa estar instalado.
|
||||
arch.config.refresh_mirrors=Atualizar espelhos ao iniciar
|
||||
@@ -209,11 +209,15 @@ arch.substatus.pre_hooks=Executando ganchos pré-transação
|
||||
arch.sync.dep_breakage.reason={} precisa de {}
|
||||
arch.sync_databases.substatus=Sincronizando bases de pacotes
|
||||
arch.sync_databases.substatus.error=Não foi possível sincronizar as bases de pacotes
|
||||
arch.sync_databases.substatus.synchronized=Sincronizado
|
||||
arch.task.aur.index.status=Gerando índice local do AUR
|
||||
arch.task.aur.index.substatus.checking=Checando atualizações
|
||||
arch.task.aur.index.substatus.download=Baixando o índice
|
||||
arch.task.aur.index.substatus.error.download=Erro de conexão ao baixar o índice
|
||||
arch.task.aur.index.substatus.error.no_data=Error: índice vazio
|
||||
arch.task.aur.index.substatus.gen_index=Gerando índice
|
||||
arch.task.checking_settings=Verificando configurações
|
||||
arch.task.disabled=Desabilitado
|
||||
arch.task.disk_cache=Indexando dados de pacotes
|
||||
arch.task.disk_cache.checking=Verificando índice
|
||||
arch.task.disk_cache.indexed=Indexados
|
||||
@@ -221,8 +225,8 @@ arch.task.disk_cache.indexing=Indexando
|
||||
arch.task.disk_cache.reading_files=Lendo arquivos
|
||||
arch.task.disk_cache.waiting_aur_index=Aguardando {}
|
||||
arch.task.mirrors=Atualizando espelhos
|
||||
arch.task.mirrors.cached=Atualizados
|
||||
arch.task.optimizing=Otimizando {}
|
||||
arch.task.sync_databases.waiting=Aguardando por {}
|
||||
arch.task.sync_sb.status=Atualizando {}
|
||||
arch.uninstall.clean_cached.error=Não foi possível remover versões antigas de {} encontradas em disco
|
||||
arch.uninstall.clean_cached.substatus=Removendo versões antigas do disco
|
||||
|
||||
@@ -53,12 +53,12 @@ arch.config.aur_idx_exp=Index expiration
|
||||
arch.config.aur_idx_exp.tip=It defines the period (in minutes) for the AUR index stored in disc to be considered valid during the initialization process. Use 0 so that it is always updated.
|
||||
arch.config.mirrors_sort_limit=Ограничение сортировки зеркал
|
||||
arch.config.mirrors_sort_limit.tip=Определяет максимальное количество зеркал, которые будут использоваться для сортировки по скорости. Используйте 0 для No limit или оставьте его пустым, чтобы отключить сортировку.
|
||||
arch.config.optimize=Оптимизация
|
||||
arch.config.optimize=Оптимизация {}
|
||||
arch.config.optimize.tip=Оптимизированные настройки будут использоваться для ускорения установки пакетов, в противном случае будут использоваться системные настройки
|
||||
arch.config.pacman_mthread_download=Multithreaded download (repositories)
|
||||
arch.config.pacman_mthread_download.tip=Whether the repository packages should be downloaded with a tool that works with threads (it may be faster). pacman-mirrors must be installed.
|
||||
arch.config.refresh_mirrors=Обновить зеркала при запуске
|
||||
arch.config.refresh_mirrors.tip=Обновляйте зеркала пакета один раз в день при запуске (или после перезагрузки устройства)
|
||||
arch.config.refresh_mirrors.tip=Обновляйте зеркала пакета один раз в день при запуске
|
||||
arch.config.repos=Пакеты репозиториев
|
||||
arch.config.repos.tip=Он позволяет управлять пакетами из набора репозиториев
|
||||
arch.config.suggest_optdep_uninstall=Uninstall optional dependencies
|
||||
@@ -210,11 +210,15 @@ arch.substatus.pre_hooks=Running pre-transaction hooks
|
||||
arch.sync.dep_breakage.reason={} requires {}
|
||||
arch.sync_databases.substatus=Синхронизация баз данных пакетов
|
||||
arch.sync_databases.substatus.error=Синхронизировать базу данных пакета не удалось
|
||||
arch.sync_databases.substatus.synchronized=Synchronized
|
||||
arch.task.aur.index.status=Generating local AUR index
|
||||
arch.task.aur.index.substatus.checking=Checking for updates
|
||||
arch.task.aur.index.substatus.download=Downloading the AUR index
|
||||
arch.task.aur.index.substatus.error.download=Connection error while downloading the index
|
||||
arch.task.aur.index.substatus.error.no_data=Error: empty index
|
||||
arch.task.aur.index.substatus.gen_index=Generating index
|
||||
arch.task.checking_settings=Checking settings
|
||||
arch.task.disabled=Disabled
|
||||
arch.task.disk_cache=Indexing packages data
|
||||
arch.task.disk_cache.checking=Checking index
|
||||
arch.task.disk_cache.indexed=Indexed
|
||||
@@ -222,8 +226,8 @@ arch.task.disk_cache.indexing=Indexing
|
||||
arch.task.disk_cache.reading_files=Reading files
|
||||
arch.task.disk_cache.waiting_aur_index=Waiting {}
|
||||
arch.task.mirrors=Обновление зеркал
|
||||
arch.task.mirrors.cached=Refreshed
|
||||
arch.task.optimizing=Optimizing {}
|
||||
arch.task.sync_databases.waiting=Waiting for {}
|
||||
arch.task.sync_sb.status=Updating {}
|
||||
arch.uninstall.clean_cached.error=It was not possible to remove old {} versions found on disk
|
||||
arch.uninstall.clean_cached.substatus=Removing old versions from disk
|
||||
|
||||
@@ -53,12 +53,12 @@ arch.config.aur_idx_exp=Index expiration
|
||||
arch.config.aur_idx_exp.tip=It defines the period (in minutes) for the AUR index stored in disc to be considered valid during the initialization process. Use 0 so that it is always updated.
|
||||
arch.config.mirrors_sort_limit=Yansı sıralama sınırı
|
||||
arch.config.mirrors_sort_limit.tip=Hız sıralama için kullanılacak maksimum yansı sayısını tanımlar. Sınırsız olması için 0 kullanın veya sıralamayı devre dışı bırakmak için boş bırakın.
|
||||
arch.config.optimize=optimize
|
||||
arch.config.optimize=Optimize {}
|
||||
arch.config.optimize.tip=Paketlerin kurulumunu, yükseltilmesini ve indirilmesini hızlandırmak için optimize edilmiş ayarlar kullanılacak, aksi takdirde sistem ayarları kullanılacak
|
||||
arch.config.pacman_mthread_download=Multithreaded download (repositories)
|
||||
arch.config.pacman_mthread_download.tip=Whether the repository packages should be downloaded with a tool that works with threads (it may be faster). pacman-mirrors must be installed.
|
||||
arch.config.refresh_mirrors=Başlangıçta yansıları yenile
|
||||
arch.config.refresh_mirrors.tip=Paket yansılarını başlangıçta günde bir kez (veya cihaz yeniden başlatıldıktan sonra) yenileyin
|
||||
arch.config.refresh_mirrors.tip=Paket yansılarını başlangıçta günde bir kez yenileyin
|
||||
arch.config.repos=Depo paketleri
|
||||
arch.config.repos.tip=Paketleri depolardan yönetmeye izin verir
|
||||
arch.config.suggest_optdep_uninstall=Uninstall optional dependencies
|
||||
@@ -210,11 +210,15 @@ arch.substatus.pre_hooks=Running pre-transaction hooks
|
||||
arch.sync.dep_breakage.reason={} requires {}
|
||||
arch.sync_databases.substatus=Paket veritabanı eşitleniyor
|
||||
arch.sync_databases.substatus.error=Paket veritabanı eşitlenemedi
|
||||
arch.sync_databases.substatus.synchronized=Synchronized
|
||||
arch.task.aur.index.status=Generating local AUR index
|
||||
arch.task.aur.index.substatus.checking=Checking for updates
|
||||
arch.task.aur.index.substatus.download=Downloading the AUR index
|
||||
arch.task.aur.index.substatus.error.download=Connection error while downloading the index
|
||||
arch.task.aur.index.substatus.error.no_data=Error: empty index
|
||||
arch.task.aur.index.substatus.gen_index=Generating index
|
||||
arch.task.checking_settings=Checking settings
|
||||
arch.task.disabled=Disabled
|
||||
arch.task.disk_cache=Indexing packages data
|
||||
arch.task.disk_cache.checking=Checking index
|
||||
arch.task.disk_cache.indexed=Indexed
|
||||
@@ -222,8 +226,8 @@ arch.task.disk_cache.indexing=Indexing
|
||||
arch.task.disk_cache.reading_files=Reading files
|
||||
arch.task.disk_cache.waiting_aur_index=Waiting {}
|
||||
arch.task.mirrors=Yansılar yenileniyor
|
||||
arch.task.mirrors.cached=Refreshed
|
||||
arch.task.optimizing=Uygun hale getiriliyor {}
|
||||
arch.task.sync_databases.waiting=Waiting for {}
|
||||
arch.task.sync_sb.status={} güncelleniyor
|
||||
arch.uninstall.clean_cached.error=Diskte bulunan eski {} sürümleri kaldırılamadı
|
||||
arch.uninstall.clean_cached.substatus=Eski sürümler diskten kaldırılıyor
|
||||
|
||||
@@ -13,11 +13,12 @@ import requests
|
||||
|
||||
from bauh.api.abstract.context import ApplicationContext
|
||||
from bauh.api.abstract.handler import TaskManager
|
||||
from bauh.commons import system
|
||||
from bauh.commons.boot import CreateConfigFile
|
||||
from bauh.commons.html import bold
|
||||
from bauh.commons.system import run_cmd, new_root_subprocess, ProcessHandler
|
||||
from bauh.commons.util import datetime_as_milis
|
||||
from bauh.commons.system import new_root_subprocess, ProcessHandler
|
||||
from bauh.gems.arch import pacman, disk, CUSTOM_MAKEPKG_FILE, CONFIG_DIR, AUR_INDEX_FILE, get_icon_path, database, \
|
||||
mirrors, ARCH_CACHE_PATH, BUILD_DIR, AUR_INDEX_TS_FILE
|
||||
mirrors, ARCH_CACHE_PATH, AUR_INDEX_TS_FILE, aur
|
||||
from bauh.gems.arch.aur import URL_INDEX
|
||||
from bauh.view.util.translation import I18n
|
||||
|
||||
@@ -31,18 +32,20 @@ RE_CLEAR_REPLACE = re.compile(r'[\-_.]')
|
||||
|
||||
class AURIndexUpdater(Thread):
|
||||
|
||||
def __init__(self, context: ApplicationContext, taskman: TaskManager):
|
||||
def __init__(self, context: ApplicationContext, taskman: TaskManager, create_config: Optional[CreateConfigFile] = None, arch_config: Optional[dict] = None):
|
||||
super(AURIndexUpdater, self).__init__(daemon=True)
|
||||
self.http_client = context.http_client
|
||||
self.i18n = context.i18n
|
||||
self.logger = context.logger
|
||||
self.taskman = taskman
|
||||
self.task_id = 'index_aur'
|
||||
self.create_config = create_config
|
||||
self.config = arch_config
|
||||
self.taskman.register_task(self.task_id, self.i18n['arch.task.aur.index.status'], get_icon_path())
|
||||
|
||||
@staticmethod
|
||||
def should_update(arch_config: dict) -> bool:
|
||||
def should_update(self) -> bool:
|
||||
try:
|
||||
exp_minutes = int(arch_config['aur_idx_exp'])
|
||||
exp_minutes = int(self.config['aur_idx_exp'])
|
||||
except:
|
||||
traceback.print_exc()
|
||||
return True
|
||||
@@ -66,11 +69,9 @@ class AURIndexUpdater(Thread):
|
||||
traceback.print_exc()
|
||||
return True
|
||||
|
||||
def run(self):
|
||||
ti = time.time()
|
||||
def update_index(self):
|
||||
self.logger.info('Indexing AUR packages')
|
||||
self.taskman.register_task(self.task_id, self.i18n['arch.task.aur.index.status'], get_icon_path())
|
||||
self.taskman.update_progress(self.task_id, 1, self.i18n['arch.task.aur.index.substatus.download'])
|
||||
self.taskman.update_progress(self.task_id, 5, self.i18n['arch.task.aur.index.substatus.download'])
|
||||
try:
|
||||
index_ts = datetime.utcnow().timestamp()
|
||||
res = self.http_client.get(URL_INDEX)
|
||||
@@ -115,6 +116,22 @@ class AURIndexUpdater(Thread):
|
||||
self.logger.warning('No internet connection: could not pre-index packages')
|
||||
self.taskman.update_progress(self.task_id, 100, self.i18n['arch.task.aur.index.substatus.error.download'])
|
||||
|
||||
def run(self):
|
||||
ti = time.time()
|
||||
|
||||
if self.create_config:
|
||||
self.taskman.update_progress(self.task_id, 0, self.i18n['task.waiting_task'].format(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['arch.task.aur.index.substatus.checking'])
|
||||
|
||||
if self.should_update():
|
||||
self.update_index()
|
||||
else:
|
||||
self.logger.info("AUR index is up to date. Aborting...")
|
||||
self.taskman.update_progress(self.task_id, 100, None)
|
||||
|
||||
tf = time.time()
|
||||
self.taskman.finish_task(self.task_id)
|
||||
self.logger.info("Finished. Took {0:.2f} seconds".format(tf - ti))
|
||||
@@ -122,48 +139,56 @@ class AURIndexUpdater(Thread):
|
||||
|
||||
class ArchDiskCacheUpdater(Thread):
|
||||
|
||||
def __init__(self, task_man: TaskManager, arch_config: dict, i18n: I18n, logger: logging.Logger, controller: "ArchManager", internet_available: bool,
|
||||
aur_supported: bool, aur_indexer: Thread):
|
||||
def __init__(self, taskman: TaskManager, i18n: I18n, logger: logging.Logger,
|
||||
controller: "ArchManager", internet_available: bool, aur_indexer: Thread,
|
||||
create_config: CreateConfigFile):
|
||||
super(ArchDiskCacheUpdater, self).__init__(daemon=True)
|
||||
self.logger = logger
|
||||
self.task_man = task_man
|
||||
self.taskman = taskman
|
||||
self.task_id = 'arch_cache_up'
|
||||
self.i18n = i18n
|
||||
self.indexed = 0
|
||||
self.indexed_template = self.i18n['arch.task.disk_cache.indexed'] + ': {}/ {}'
|
||||
self.to_index = 0
|
||||
self.progress = 0 # progress is defined by the number of packages prepared and indexed
|
||||
self.repositories = arch_config['repositories']
|
||||
self.aur = aur_supported
|
||||
self.controller = controller
|
||||
self.internet_available = internet_available
|
||||
self.installed_hash_path = '{}/installed.sha1'.format(ARCH_CACHE_PATH)
|
||||
self.installed_cache_dir = '{}/installed'.format(ARCH_CACHE_PATH)
|
||||
self.aur_indexer = aur_indexer
|
||||
self.create_config = create_config
|
||||
self.taskman.register_task(self.task_id, self.i18n['arch.task.disk_cache'], get_icon_path())
|
||||
|
||||
def update_indexed(self, pkgname: str):
|
||||
self.indexed += 1
|
||||
sub = self.indexed_template.format(self.indexed, self.to_index)
|
||||
progress = self.progress + (self.indexed / self.to_index) * 50
|
||||
self.task_man.update_progress(self.task_id, progress, sub)
|
||||
self.taskman.update_progress(self.task_id, progress, sub)
|
||||
|
||||
def _update_progress(self, progress: float, msg: str):
|
||||
self.progress = progress
|
||||
self.task_man.update_progress(self.task_id, self.progress, msg)
|
||||
self.taskman.update_progress(self.task_id, self.progress, msg)
|
||||
|
||||
def _notify_reading_files(self):
|
||||
self._update_progress(50, self.i18n['arch.task.disk_cache.indexing'])
|
||||
|
||||
def run(self):
|
||||
if not any([self.aur, self.repositories]):
|
||||
ti = time.time()
|
||||
self.taskman.update_progress(self.task_id, 0, self.i18n['task.waiting_task'].format(self.create_config.task_name))
|
||||
self.create_config.join()
|
||||
|
||||
config = self.create_config.config
|
||||
aur_supported, repositories = aur.is_supported(config), config['repositories']
|
||||
|
||||
self.taskman.update_progress(self.task_id, 1, None)
|
||||
if not any([aur_supported, repositories]):
|
||||
self.taskman.update_progress(self.task_id, 100, self.i18n['arch.task.disabled'])
|
||||
self.taskman.finish_task(self.task_id)
|
||||
return
|
||||
|
||||
ti = time.time()
|
||||
self.task_man.register_task(self.task_id, self.i18n['arch.task.disk_cache'], get_icon_path())
|
||||
|
||||
self.logger.info("Checking already cached package data")
|
||||
|
||||
self._update_progress(1, self.i18n['arch.task.disk_cache.checking'])
|
||||
|
||||
cache_dirs = [fpath for fpath in glob.glob('{}/*'.format(self.installed_cache_dir)) if os.path.isdir(fpath)]
|
||||
|
||||
not_cached_names = None
|
||||
@@ -177,8 +202,8 @@ class ArchDiskCacheUpdater(Thread):
|
||||
self._update_progress(20, self.i18n['arch.task.disk_cache.checking'])
|
||||
|
||||
if not not_cached_names:
|
||||
self.task_man.update_progress(self.task_id, 100, '')
|
||||
self.task_man.finish_task(self.task_id)
|
||||
self.taskman.update_progress(self.task_id, 100, '')
|
||||
self.taskman.finish_task(self.task_id)
|
||||
tf = time.time()
|
||||
time_msg = '{0:.2f} seconds'.format(tf - ti)
|
||||
self.logger.info('Finished: no package data to cache ({})'.format(time_msg))
|
||||
@@ -186,8 +211,8 @@ class ArchDiskCacheUpdater(Thread):
|
||||
|
||||
self.logger.info('Pre-caching installed Arch packages data to disk')
|
||||
|
||||
if self.aur and self.aur_indexer:
|
||||
self.task_man.update_progress(self.task_id, 20, self.i18n['arch.task.disk_cache.waiting_aur_index'].format(bold(self.i18n['arch.task.aur.index.status'])))
|
||||
if aur_supported and self.aur_indexer:
|
||||
self.taskman.update_progress(self.task_id, 20, self.i18n['arch.task.disk_cache.waiting_aur_index'].format(bold(self.i18n['arch.task.aur.index.status'])))
|
||||
self.aur_indexer.join()
|
||||
|
||||
self._update_progress(21, self.i18n['arch.task.disk_cache.checking'])
|
||||
@@ -199,7 +224,7 @@ class ArchDiskCacheUpdater(Thread):
|
||||
|
||||
saved = 0
|
||||
|
||||
pkgs = {p.name: p for p in installed if ((self.aur and p.repository == 'aur') or (self.repositories and p.repository != 'aur')) and not os.path.exists(p.get_disk_cache_path())}
|
||||
pkgs = {p.name: p for p in installed if ((aur_supported and p.repository == 'aur') or (repositories and p.repository != 'aur')) and not os.path.exists(p.get_disk_cache_path())}
|
||||
self.to_index = len(pkgs)
|
||||
|
||||
# overwrite == True because the verification already happened
|
||||
@@ -207,8 +232,8 @@ class ArchDiskCacheUpdater(Thread):
|
||||
saved += disk.write_several(pkgs=pkgs,
|
||||
after_desktop_files=self._notify_reading_files,
|
||||
after_written=self.update_indexed, overwrite=True)
|
||||
self.task_man.update_progress(self.task_id, 100, None)
|
||||
self.task_man.finish_task(self.task_id)
|
||||
self.taskman.update_progress(self.task_id, 100, None)
|
||||
self.taskman.finish_task(self.task_id)
|
||||
|
||||
tf = time.time()
|
||||
time_msg = '{0:.2f} seconds'.format(tf - ti)
|
||||
@@ -217,7 +242,7 @@ class ArchDiskCacheUpdater(Thread):
|
||||
|
||||
class ArchCompilationOptimizer(Thread):
|
||||
|
||||
def __init__(self, arch_config: dict, i18n: I18n, logger: logging.Logger, taskman: Optional[TaskManager] = None):
|
||||
def __init__(self, i18n: I18n, logger: logging.Logger, taskman: TaskManager, create_config: Optional[CreateConfigFile] = None):
|
||||
super(ArchCompilationOptimizer, self).__init__(daemon=True)
|
||||
self.logger = logger
|
||||
self.i18n = i18n
|
||||
@@ -227,17 +252,12 @@ class ArchCompilationOptimizer(Thread):
|
||||
self.re_ccache = re.compile(r'!?ccache')
|
||||
self.taskman = taskman
|
||||
self.task_id = 'arch_make_optm'
|
||||
self.optimizations = bool(arch_config['optimize'])
|
||||
self.create_config = create_config
|
||||
self.taskman.register_task(self.task_id, self.i18n['arch.task.optimizing'].format(bold('makepkg.conf')), get_icon_path())
|
||||
|
||||
def _is_ccache_installed(self) -> bool:
|
||||
return bool(run_cmd('which ccache', print_error=False))
|
||||
|
||||
def _update_progress(self, progress: float, substatus: str = None):
|
||||
if self.taskman:
|
||||
self.taskman.update_progress(self.task_id, progress, substatus)
|
||||
|
||||
if progress == 100:
|
||||
self.taskman.finish_task(self.task_id)
|
||||
code, _ = system.execute(cmd='which ccache', output=False)
|
||||
return code == 0
|
||||
|
||||
def optimize(self):
|
||||
ti = time.time()
|
||||
@@ -271,7 +291,7 @@ class ArchCompilationOptimizer(Thread):
|
||||
else:
|
||||
optimizations.append('MAKEFLAGS="-j$(nproc)"')
|
||||
|
||||
self._update_progress(20)
|
||||
self.taskman.update_progress(self.task_id, 20, None)
|
||||
|
||||
compress_xz = self.re_compress_xz.findall(custom_makepkg or global_makepkg)
|
||||
|
||||
@@ -286,7 +306,7 @@ class ArchCompilationOptimizer(Thread):
|
||||
else:
|
||||
optimizations.append('COMPRESSXZ=(xz -c -z - --threads=0)')
|
||||
|
||||
self._update_progress(40)
|
||||
self.taskman.update_progress(self.task_id, 40, None)
|
||||
|
||||
compress_zst = self.re_compress_zst.findall(custom_makepkg or global_makepkg)
|
||||
|
||||
@@ -301,7 +321,7 @@ class ArchCompilationOptimizer(Thread):
|
||||
else:
|
||||
optimizations.append('COMPRESSZST=(zstd -c -z -q - --threads=0)')
|
||||
|
||||
self._update_progress(60)
|
||||
self.taskman.update_progress(self.task_id, 60, None)
|
||||
|
||||
build_envs = self.re_build_env.findall(custom_makepkg or global_makepkg)
|
||||
|
||||
@@ -331,7 +351,7 @@ class ArchCompilationOptimizer(Thread):
|
||||
self.logger.info('Adding a BUILDENV declaration')
|
||||
optimizations.append('BUILDENV=(ccache)')
|
||||
|
||||
self._update_progress(80)
|
||||
self.taskman.update_progress(self.task_id, 80, None)
|
||||
|
||||
if custom_makepkg and optimizations:
|
||||
generated_by = '# <generated by bauh>\n'
|
||||
@@ -348,43 +368,91 @@ class ArchCompilationOptimizer(Thread):
|
||||
self.logger.info("Removing old optimized 'makepkg.conf' at '{}'".format(CUSTOM_MAKEPKG_FILE))
|
||||
os.remove(CUSTOM_MAKEPKG_FILE)
|
||||
|
||||
self.taskman.update_progress(self.task_id, 100, None)
|
||||
tf = time.time()
|
||||
self._update_progress(100)
|
||||
self.logger.info("Optimizations took {0:.2f} seconds".format(tf - ti))
|
||||
self.logger.info('Finished')
|
||||
self.logger.info('Finished. {0:.2f} seconds'.format(tf - ti))
|
||||
|
||||
def run(self):
|
||||
if not self.optimizations:
|
||||
self.logger.info("Arch packages compilation optimizations are disabled")
|
||||
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()
|
||||
|
||||
if os.path.exists(CUSTOM_MAKEPKG_FILE):
|
||||
self.logger.info("Removing custom 'makepkg.conf' -> '{}'".format(CUSTOM_MAKEPKG_FILE))
|
||||
os.remove(CUSTOM_MAKEPKG_FILE)
|
||||
self.taskman.update_progress(self.task_id, 1, None)
|
||||
|
||||
self.logger.info('Finished')
|
||||
else:
|
||||
if self.taskman:
|
||||
self.taskman.register_task(self.task_id, self.i18n['arch.task.optimizing'].format(bold('makepkg.conf')), get_icon_path())
|
||||
if self.create_config.config['optimize'] and aur.is_supported(self.create_config.config):
|
||||
try:
|
||||
self.optimize()
|
||||
except:
|
||||
self.logger.error("Unexpected exception")
|
||||
traceback.print_exc()
|
||||
self.taskman.update_progress(self.task_id, 100, None)
|
||||
else:
|
||||
self.logger.info("AUR packages compilation optimizations are disabled")
|
||||
|
||||
self.optimize()
|
||||
if os.path.exists(CUSTOM_MAKEPKG_FILE):
|
||||
try:
|
||||
self.logger.info("Removing custom 'makepkg.conf' -> '{}'".format(CUSTOM_MAKEPKG_FILE))
|
||||
os.remove(CUSTOM_MAKEPKG_FILE)
|
||||
except:
|
||||
self.logger.error("Unexpected exception")
|
||||
traceback.print_exc()
|
||||
|
||||
self.taskman.update_progress(self.task_id, 100, self.i18n['arch.task.disabled'])
|
||||
|
||||
tf = time.time()
|
||||
self.taskman.finish_task(self.task_id)
|
||||
self.logger.info('Finished. Took {0:.2f} seconds'.format(tf - ti))
|
||||
|
||||
|
||||
class RefreshMirrors(Thread):
|
||||
|
||||
def __init__(self, taskman: TaskManager, root_password: str, i18n: I18n, sort_limit: int, logger: logging.Logger):
|
||||
def __init__(self, taskman: TaskManager, root_password: str, i18n: I18n, logger: logging.Logger,
|
||||
create_config: CreateConfigFile):
|
||||
super(RefreshMirrors, self).__init__(daemon=True)
|
||||
self.taskman = taskman
|
||||
self.i18n = i18n
|
||||
self.logger = logger
|
||||
self.root_password = root_password
|
||||
self.task_id = "arch_mirrors"
|
||||
self.sort_limit = sort_limit
|
||||
self.create_config = create_config
|
||||
self.refreshed = False
|
||||
self.task_name = self.i18n['arch.task.mirrors']
|
||||
self.taskman.register_task(self.task_id, self.task_name, get_icon_path())
|
||||
|
||||
def _notify_output(self, output: str):
|
||||
self.taskman.update_output(self.task_id, output)
|
||||
|
||||
@staticmethod
|
||||
def is_enabled(arch_config: dict, aur_supported: bool) -> bool:
|
||||
return (arch_config['repositories'] or aur_supported) \
|
||||
and arch_config['refresh_mirrors_startup'] and pacman.is_mirrors_available()
|
||||
|
||||
@classmethod
|
||||
def should_synchronize(cls, arch_config: dict, aur_supported: bool, logger: logging.Logger) -> bool:
|
||||
return cls.is_enabled(arch_config, aur_supported) and mirrors.should_sync(logger)
|
||||
|
||||
def run(self):
|
||||
self.taskman.register_task(self.task_id, self.i18n['arch.task.mirrors'], get_icon_path())
|
||||
ti = time.time()
|
||||
self.taskman.update_progress(self.task_id, 0, self.i18n['task.waiting_task'].format(bold(self.create_config.task_name)))
|
||||
self.create_config.join()
|
||||
|
||||
arch_config = self.create_config.config
|
||||
aur_supported = aur.is_supported(arch_config)
|
||||
|
||||
self.taskman.update_progress(self.task_id, 1, self.i18n['arch.task.checking_settings'])
|
||||
|
||||
if not self.is_enabled(arch_config, aur_supported):
|
||||
self.taskman.update_progress(self.task_id, 100, self.i18n['arch.task.disabled'])
|
||||
self.taskman.finish_task(self.task_id)
|
||||
return
|
||||
|
||||
if not mirrors.should_sync(self.logger):
|
||||
self.taskman.update_progress(self.task_id, 100, self.i18n['arch.task.mirrors.cached'])
|
||||
self.taskman.finish_task(self.task_id)
|
||||
return
|
||||
|
||||
sort_limit = arch_config['mirrors_sort_limit']
|
||||
self.logger.info("Refreshing mirrors")
|
||||
|
||||
handler = ProcessHandler()
|
||||
@@ -394,15 +462,16 @@ class RefreshMirrors(Thread):
|
||||
|
||||
if success:
|
||||
|
||||
if self.sort_limit is not None and self.sort_limit >= 0:
|
||||
if sort_limit is not None and sort_limit >= 0:
|
||||
self.taskman.update_progress(self.task_id, 50, self.i18n['arch.custom_action.refresh_mirrors.status.updating'])
|
||||
try:
|
||||
handler.handle_simple(pacman.sort_fastest_mirrors(self.root_password, self.sort_limit), output_handler=self._notify_output)
|
||||
handler.handle_simple(pacman.sort_fastest_mirrors(self.root_password, sort_limit), output_handler=self._notify_output)
|
||||
except:
|
||||
self.logger.error("Could not sort mirrors by speed")
|
||||
traceback.print_exc()
|
||||
|
||||
mirrors.register_sync(self.logger)
|
||||
self.refreshed = True
|
||||
else:
|
||||
self.logger.error("It was not possible to refresh mirrors")
|
||||
except:
|
||||
@@ -411,12 +480,14 @@ class RefreshMirrors(Thread):
|
||||
|
||||
self.taskman.update_progress(self.task_id, 100, None)
|
||||
self.taskman.finish_task(self.task_id)
|
||||
self.logger.info("Finished")
|
||||
tf = time.time()
|
||||
self.logger.info("Finished. Took {0:.2f} seconds".format(tf - ti))
|
||||
|
||||
|
||||
class SyncDatabases(Thread):
|
||||
|
||||
def __init__(self, taskman: TaskManager, root_password: str, i18n: I18n, logger: logging.Logger, refresh_mirrors: RefreshMirrors = None):
|
||||
def __init__(self, taskman: TaskManager, root_password: str, i18n: I18n, logger: logging.Logger,
|
||||
refresh_mirrors: RefreshMirrors, create_config: CreateConfigFile):
|
||||
super(SyncDatabases, self).__init__(daemon=True)
|
||||
self.task_man = taskman
|
||||
self.i18n = i18n
|
||||
@@ -425,15 +496,46 @@ class SyncDatabases(Thread):
|
||||
self.root_password = root_password
|
||||
self.refresh_mirrors = refresh_mirrors
|
||||
self.logger = logger
|
||||
self.create_config = create_config
|
||||
self.task_name = self.i18n['arch.sync_databases.substatus']
|
||||
self.taskman.register_task(self.task_id, self.task_name, get_icon_path())
|
||||
self.synchronized = False
|
||||
|
||||
@staticmethod
|
||||
def is_enabled(arch_config: dict, aur_supported: bool) -> bool:
|
||||
return arch_config['sync_databases_startup'] and (aur_supported or arch_config['repositories'])
|
||||
|
||||
@classmethod
|
||||
def should_sync(cls, mirrors_refreshed: bool, arch_config: dict, aur_supported: bool, logger: logging.Logger):
|
||||
return mirrors_refreshed or (cls.is_enabled(arch_config, aur_supported) and database.should_sync(arch_config, aur_supported, None, logger))
|
||||
|
||||
def run(self) -> None:
|
||||
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.taskman.update_progress(self.task_id, 0, self.i18n['task.waiting_task'].format(bold(self.refresh_mirrors.task_name)))
|
||||
self.refresh_mirrors.join()
|
||||
|
||||
self.taskman.update_progress(self.task_id, 1, self.i18n['arch.task.checking_settings'])
|
||||
|
||||
arch_config = self.create_config.config
|
||||
aur_supported = aur.is_supported(arch_config)
|
||||
if not self.is_enabled(arch_config, aur_supported):
|
||||
self.taskman.update_progress(self.task_id, 100, self.i18n['arch.task.disabled'])
|
||||
self.taskman.finish_task(self.task_id)
|
||||
return
|
||||
|
||||
shoud_sync = self.refresh_mirrors.refreshed or (database.should_sync(arch_config, aur_supported, None, self.logger))
|
||||
|
||||
if not shoud_sync:
|
||||
self.taskman.update_progress(self.task_id, 100, self.i18n['arch.sync_databases.substatus.synchronized'])
|
||||
self.taskman.finish_task(self.task_id)
|
||||
self.synchronized = True
|
||||
return
|
||||
|
||||
self.logger.info("Synchronizing databases")
|
||||
self.taskman.register_task(self.task_id, self.i18n['arch.sync_databases.substatus'], get_icon_path())
|
||||
|
||||
if self.refresh_mirrors and self.refresh_mirrors.is_alive():
|
||||
self.taskman.update_progress(self.task_id, 0, self.i18n['arch.task.sync_databases.waiting'].format('"{}"'.format(self.i18n['arch.task.mirrors'])))
|
||||
self.refresh_mirrors.join()
|
||||
|
||||
progress = 10
|
||||
dbs = pacman.get_databases()
|
||||
self.taskman.update_progress(self.task_id, progress, None)
|
||||
@@ -472,6 +574,7 @@ class SyncDatabases(Thread):
|
||||
|
||||
if p.returncode == 0:
|
||||
database.register_sync(self.logger)
|
||||
self.synchronized = True
|
||||
else:
|
||||
self.logger.error("Could not synchronize database")
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import os
|
||||
from pathlib import Path
|
||||
|
||||
from bauh.api.constants import CONFIG_PATH
|
||||
from bauh.commons import resource
|
||||
|
||||
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
SUGGESTIONS_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/flatpak/suggestions.txt'
|
||||
@@ -9,3 +10,7 @@ CONFIG_FILE = '{}/flatpak.yml'.format(CONFIG_PATH)
|
||||
CONFIG_DIR = '{}/flatpak'.format(CONFIG_PATH)
|
||||
UPDATES_IGNORED_FILE = '{}/updates_ignored.txt'.format(CONFIG_DIR)
|
||||
EXPORTS_PATH = '{}/.local/share/flatpak/exports/share'.format(str(Path.home()))
|
||||
|
||||
|
||||
def get_icon_path() -> str:
|
||||
return resource.get_path('img/flatpak.svg', ROOT_DIR)
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
from bauh.commons.config import read_config as read
|
||||
from bauh.commons.config import YAMLConfigManager
|
||||
from bauh.gems.flatpak import CONFIG_FILE
|
||||
|
||||
|
||||
def read_config(update_file: bool = False) -> dict:
|
||||
template = {'installation_level': None}
|
||||
return read(CONFIG_FILE, template, update_file=update_file)
|
||||
class FlatpakConfigManager(YAMLConfigManager):
|
||||
|
||||
def __init__(self):
|
||||
super(FlatpakConfigManager, self).__init__(config_file_path=CONFIG_FILE)
|
||||
|
||||
def get_default_config(self) -> dict:
|
||||
return {'installation_level': None}
|
||||
|
||||
@@ -16,11 +16,12 @@ from bauh.api.abstract.model import PackageHistory, PackageUpdate, SoftwarePacka
|
||||
from bauh.api.abstract.view import MessageType, FormComponent, SingleSelectComponent, InputOption, SelectViewType, \
|
||||
ViewComponent, PanelComponent
|
||||
from bauh.commons import user
|
||||
from bauh.commons.config import save_config
|
||||
from bauh.commons.boot import CreateConfigFile
|
||||
from bauh.commons.html import strip_html, bold
|
||||
from bauh.commons.system import ProcessHandler
|
||||
from bauh.gems.flatpak import flatpak, SUGGESTIONS_FILE, CONFIG_FILE, UPDATES_IGNORED_FILE, CONFIG_DIR, EXPORTS_PATH
|
||||
from bauh.gems.flatpak.config import read_config
|
||||
from bauh.gems.flatpak import flatpak, SUGGESTIONS_FILE, CONFIG_FILE, UPDATES_IGNORED_FILE, CONFIG_DIR, EXPORTS_PATH, \
|
||||
get_icon_path
|
||||
from bauh.gems.flatpak.config import FlatpakConfigManager
|
||||
from bauh.gems.flatpak.constants import FLATHUB_API_URL
|
||||
from bauh.gems.flatpak.model import FlatpakApplication
|
||||
from bauh.gems.flatpak.worker import FlatpakAsyncDataLoader, FlatpakUpdateLoader
|
||||
@@ -41,6 +42,7 @@ class FlatpakManager(SoftwareManager):
|
||||
self.http_client = context.http_client
|
||||
self.suggestions_cache = context.cache_factory.new()
|
||||
self.logger = context.logger
|
||||
self.configman = FlatpakConfigManager()
|
||||
|
||||
def get_managed_types(self) -> Set["type"]:
|
||||
return {FlatpakApplication}
|
||||
@@ -337,9 +339,9 @@ class FlatpakManager(SoftwareManager):
|
||||
return True
|
||||
|
||||
def install(self, pkg: FlatpakApplication, root_password: str, disk_loader: DiskCacheLoader, watcher: ProcessWatcher) -> TransactionResult:
|
||||
config = read_config()
|
||||
flatpak_config = self.configman.get_config()
|
||||
|
||||
install_level = config['installation_level']
|
||||
install_level = flatpak_config['installation_level']
|
||||
|
||||
if install_level is not None:
|
||||
self.logger.info("Default Flaptak installation level defined: {}".format(install_level))
|
||||
@@ -453,7 +455,8 @@ class FlatpakManager(SoftwareManager):
|
||||
return action == SoftwareAction.DOWNGRADE and pkg.installation == 'system'
|
||||
|
||||
def prepare(self, task_manager: TaskManager, root_password: str, internet_available: bool):
|
||||
Thread(target=read_config, args=(True,), daemon=True).start()
|
||||
CreateConfigFile(taskman=task_manager, configman=self.configman, i18n=self.i18n,
|
||||
task_icon_path=get_icon_path(), logger=self.logger).start()
|
||||
|
||||
def list_updates(self, internet_available: bool) -> List[PackageUpdate]:
|
||||
updates = []
|
||||
@@ -555,7 +558,7 @@ class FlatpakManager(SoftwareManager):
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent:
|
||||
fields = []
|
||||
|
||||
config = read_config()
|
||||
flatpak_config = self.configman.get_config()
|
||||
|
||||
install_opts = [InputOption(label=self.i18n['flatpak.config.install_level.system'].capitalize(),
|
||||
value='system',
|
||||
@@ -568,7 +571,7 @@ class FlatpakManager(SoftwareManager):
|
||||
tooltip=self.i18n['flatpak.config.install_level.ask.tip'].format(app=self.context.app_name))]
|
||||
fields.append(SingleSelectComponent(label=self.i18n['flatpak.config.install_level'],
|
||||
options=install_opts,
|
||||
default_option=[o for o in install_opts if o.value == config['installation_level']][0],
|
||||
default_option=[o for o in install_opts if o.value == flatpak_config['installation_level']][0],
|
||||
max_per_line=len(install_opts),
|
||||
max_width=floor(screen_width * 0.22),
|
||||
type_=SelectViewType.RADIO))
|
||||
@@ -576,11 +579,11 @@ class FlatpakManager(SoftwareManager):
|
||||
return PanelComponent([FormComponent(fields, self.i18n['installation'].capitalize())])
|
||||
|
||||
def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
config = read_config()
|
||||
config['installation_level'] = component.components[0].components[0].get_selected()
|
||||
flatpak_config = self.configman.get_config()
|
||||
flatpak_config['installation_level'] = component.components[0].components[0].get_selected()
|
||||
|
||||
try:
|
||||
save_config(config, CONFIG_FILE)
|
||||
self.configman.save_config(flatpak_config)
|
||||
return True, None
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
from bauh.commons.config import read_config as read
|
||||
from bauh.commons.config import YAMLConfigManager
|
||||
from bauh.gems.snap import CONFIG_FILE
|
||||
|
||||
|
||||
def read_config(update_file: bool = False) -> dict:
|
||||
template = {'install_channel': False, 'categories_exp': 24}
|
||||
return read(CONFIG_FILE, template, update_file=update_file)
|
||||
class SnapConfigManager(YAMLConfigManager):
|
||||
|
||||
def __init__(self):
|
||||
super(SnapConfigManager, self).__init__(config_file_path=CONFIG_FILE)
|
||||
|
||||
def get_default_config(self) -> dict:
|
||||
return {'install_channel': False, 'categories_exp': 24}
|
||||
|
||||
@@ -14,14 +14,14 @@ from bauh.api.abstract.view import SingleSelectComponent, SelectViewType, InputO
|
||||
FormComponent, TextInputComponent
|
||||
from bauh.api.exception import NoInternetException
|
||||
from bauh.commons import resource
|
||||
from bauh.commons.boot import CreateConfigFile
|
||||
from bauh.commons.category import CategoriesDownloader
|
||||
from bauh.commons.config import save_config
|
||||
from bauh.commons.html import bold
|
||||
from bauh.commons.system import SystemProcess, ProcessHandler, new_root_subprocess, get_human_size_str
|
||||
from bauh.commons.view_utils import new_select
|
||||
from bauh.gems.snap import snap, URL_CATEGORIES_FILE, CATEGORIES_FILE_PATH, SUGGESTIONS_FILE, \
|
||||
get_icon_path, snapd, CONFIG_FILE, ROOT_DIR
|
||||
from bauh.gems.snap.config import read_config
|
||||
get_icon_path, snapd, ROOT_DIR
|
||||
from bauh.gems.snap.config import SnapConfigManager
|
||||
from bauh.gems.snap.model import SnapApplication
|
||||
from bauh.gems.snap.snapd import SnapdClient
|
||||
|
||||
@@ -42,6 +42,7 @@ class SnapManager(SoftwareManager):
|
||||
self.categories = {}
|
||||
self.suggestions_cache = context.cache_factory.new()
|
||||
self.info_path = None
|
||||
self.configman = SnapConfigManager()
|
||||
self.custom_actions = [
|
||||
CustomSoftwareAction(i18n_status_key='snap.action.refresh.status',
|
||||
i18n_label_key='snap.action.refresh.label',
|
||||
@@ -187,7 +188,7 @@ class SnapManager(SoftwareManager):
|
||||
installed_names = {s['name'] for s in SnapdClient(self.logger).list_all_snaps()}
|
||||
|
||||
client = SnapdClient(self.logger)
|
||||
snap_config = read_config()
|
||||
snap_config = self.configman.get_config()
|
||||
|
||||
try:
|
||||
channel = self._request_channel_installation(pkg=pkg, snap_config=snap_config, snapd_client=client, watcher=watcher)
|
||||
@@ -283,27 +284,35 @@ class SnapManager(SoftwareManager):
|
||||
except:
|
||||
return False
|
||||
|
||||
def _start_category_task(self, task_man: TaskManager):
|
||||
if task_man:
|
||||
task_man.register_task('snap_cats', self.i18n['task.download_categories'], get_icon_path())
|
||||
task_man.update_progress('snap_cats', 50, None)
|
||||
def _start_category_task(self, taskman: TaskManager, create_config: CreateConfigFile, downloader: CategoriesDownloader):
|
||||
if taskman:
|
||||
taskman.update_progress('snap_cats', 0, self.i18n['task.waiting_task'].format(bold(create_config.task_name)))
|
||||
create_config.join()
|
||||
|
||||
def _finish_category_task(self, task_man: TaskManager):
|
||||
if task_man:
|
||||
task_man.update_progress('snap_cats', 100, None)
|
||||
task_man.finish_task('snap_cats')
|
||||
categories_exp = create_config.config['categories_exp']
|
||||
downloader.expiration = categories_exp if isinstance(categories_exp, int) else None
|
||||
taskman.update_progress('snap_cats', 1, None)
|
||||
|
||||
def _finish_category_task(self, taskman: TaskManager):
|
||||
if taskman:
|
||||
taskman.update_progress('snap_cats', 100, None)
|
||||
taskman.finish_task('snap_cats')
|
||||
|
||||
def prepare(self, task_manager: TaskManager, root_password: str, internet_available: bool):
|
||||
snap_config = read_config()
|
||||
create_config = CreateConfigFile(taskman=task_manager, configman=self.configman, i18n=self.i18n,
|
||||
task_icon_path=get_icon_path(), logger=self.logger)
|
||||
create_config.start()
|
||||
|
||||
CategoriesDownloader(id_='snap', manager=self, http_client=self.http_client, logger=self.logger,
|
||||
url_categories_file=URL_CATEGORIES_FILE,
|
||||
categories_path=CATEGORIES_FILE_PATH,
|
||||
expiration=snap_config['categories_exp'] if isinstance(snap_config['categories_exp'], int) else 0,
|
||||
internet_connection=internet_available,
|
||||
internet_checker=self.context.internet_checker,
|
||||
before=lambda: self._start_category_task(task_manager),
|
||||
after=lambda: self._finish_category_task(task_manager)).start()
|
||||
task_manager.register_task('snap_cats', self.i18n['task.download_categories'], get_icon_path())
|
||||
category_downloader = CategoriesDownloader(id_='snap', manager=self, http_client=self.http_client,
|
||||
logger=self.logger,
|
||||
url_categories_file=URL_CATEGORIES_FILE,
|
||||
categories_path=CATEGORIES_FILE_PATH,
|
||||
internet_connection=internet_available,
|
||||
internet_checker=self.context.internet_checker,
|
||||
after=lambda: self._finish_category_task(task_manager))
|
||||
category_downloader.before = lambda: self._start_category_task(task_manager, create_config, category_downloader)
|
||||
category_downloader.start()
|
||||
|
||||
def list_updates(self, internet_available: bool) -> List[PackageUpdate]:
|
||||
pass
|
||||
@@ -436,7 +445,7 @@ class SnapManager(SoftwareManager):
|
||||
return pkg.screenshots if pkg.has_screenshots() else []
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent:
|
||||
snap_config = read_config()
|
||||
snap_config = self.configman.get_config()
|
||||
max_width = 200
|
||||
|
||||
install_channel = new_select(label=self.i18n['snap.config.install_channel'],
|
||||
@@ -457,14 +466,14 @@ class SnapManager(SoftwareManager):
|
||||
return PanelComponent([FormComponent([install_channel, categories_exp], self.i18n['installation'].capitalize())])
|
||||
|
||||
def save_settings(self, component: ViewComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
config = read_config()
|
||||
snap_config = self.configman.get_config()
|
||||
|
||||
panel = component.components[0]
|
||||
config['install_channel'] = panel.get_component('snap_install_channel').get_selected()
|
||||
config['categories_exp'] = panel.get_component('snap_cat_exp').get_int_value()
|
||||
snap_config['install_channel'] = panel.get_component('snap_install_channel').get_selected()
|
||||
snap_config['categories_exp'] = panel.get_component('snap_cat_exp').get_int_value()
|
||||
|
||||
try:
|
||||
save_config(config, CONFIG_FILE)
|
||||
self.configman.save_config(snap_config)
|
||||
return True, None
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
from bauh.commons.config import read_config as read
|
||||
from bauh.commons.config import YAMLConfigManager
|
||||
from bauh.gems.web import CONFIG_FILE
|
||||
|
||||
|
||||
def read_config(update_file: bool = False) -> dict:
|
||||
default_config = {
|
||||
'environment': {
|
||||
'system': False,
|
||||
'electron': {'version': None},
|
||||
'cache_exp': 1440
|
||||
class WebConfigManager(YAMLConfigManager):
|
||||
|
||||
def __init__(self):
|
||||
super(WebConfigManager, self).__init__(config_file_path=CONFIG_FILE)
|
||||
|
||||
def get_default_config(self) -> dict:
|
||||
return {
|
||||
'environment': {
|
||||
'system': False,
|
||||
'electron': {'version': None},
|
||||
'cache_exp': 1440
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return read(CONFIG_FILE, default_config, update_file)
|
||||
|
||||
|
||||
|
||||
@@ -28,15 +28,17 @@ from bauh.api.abstract.view import MessageType, MultipleSelectComponent, InputOp
|
||||
SelectViewType, TextInputComponent, FormComponent, FileChooserComponent, ViewComponent, PanelComponent
|
||||
from bauh.api.constants import DESKTOP_ENTRIES_DIR
|
||||
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 ProcessHandler, get_dir_size, get_human_size_str, SimpleProcess
|
||||
from bauh.gems.web import INSTALLED_PATH, nativefier, DESKTOP_ENTRY_PATH_PATTERN, URL_FIX_PATTERN, ENV_PATH, UA_CHROME, \
|
||||
SEARCH_INDEX_FILE, SUGGESTIONS_CACHE_FILE, ROOT_DIR, CONFIG_FILE, TEMP_PATH, FIXES_PATH, ELECTRON_PATH
|
||||
from bauh.gems.web.config import read_config
|
||||
SEARCH_INDEX_FILE, SUGGESTIONS_CACHE_FILE, ROOT_DIR, TEMP_PATH, FIXES_PATH, ELECTRON_PATH, \
|
||||
get_icon_path
|
||||
from bauh.gems.web.config import WebConfigManager
|
||||
from bauh.gems.web.environment import EnvironmentUpdater, EnvironmentComponent
|
||||
from bauh.gems.web.model import WebApplication
|
||||
from bauh.gems.web.worker import SuggestionsDownloader, SearchIndexGenerator
|
||||
from bauh.gems.web.worker import SuggestionsManager, UpdateEnvironmentSettings, \
|
||||
SuggestionsLoader, SearchIndexGenerator
|
||||
|
||||
try:
|
||||
from bs4 import BeautifulSoup, SoupStrainer
|
||||
@@ -58,7 +60,7 @@ RE_SYMBOLS_SPLIT = re.compile(r'[\-|_\s:.]')
|
||||
|
||||
class WebApplicationManager(SoftwareManager):
|
||||
|
||||
def __init__(self, context: ApplicationContext, suggestions_downloader: Thread = None):
|
||||
def __init__(self, context: ApplicationContext, suggestions_loader: Optional[SuggestionsLoader] = None):
|
||||
super(WebApplicationManager, self).__init__(context=context)
|
||||
self.http_client = context.http_client
|
||||
self.env_updater = EnvironmentUpdater(logger=context.logger, http_client=context.http_client,
|
||||
@@ -67,8 +69,9 @@ class WebApplicationManager(SoftwareManager):
|
||||
self.i18n = context.i18n
|
||||
self.logger = context.logger
|
||||
self.env_thread = None
|
||||
self.suggestions_downloader = suggestions_downloader
|
||||
self.suggestions_loader = suggestions_loader
|
||||
self.suggestions = {}
|
||||
self.configman = WebConfigManager()
|
||||
self.custom_actions = [CustomSoftwareAction(i18n_label_key='web.custom_action.clean_env',
|
||||
i18n_status_key='web.custom_action.clean_env.status',
|
||||
manager=self,
|
||||
@@ -254,8 +257,8 @@ class WebApplicationManager(SoftwareManager):
|
||||
|
||||
index = self._read_search_index()
|
||||
|
||||
if not index and self.suggestions_downloader and self.suggestions_downloader.is_alive():
|
||||
self.suggestions_downloader.join()
|
||||
if not index and self.suggestions_loader and self.suggestions_loader.is_alive():
|
||||
self.suggestions_loader.join()
|
||||
index = self._read_search_index()
|
||||
|
||||
if index:
|
||||
@@ -634,7 +637,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
watcher.change_substatus(self.i18n['web.env.checking'])
|
||||
handler = ProcessHandler(watcher)
|
||||
|
||||
web_config = read_config()
|
||||
web_config = self.configman.get_config()
|
||||
env_settings = self.env_updater.read_settings(web_config=web_config)
|
||||
|
||||
if web_config['environment']['system'] and not nativefier.is_available():
|
||||
@@ -796,7 +799,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
|
||||
def can_work(self) -> bool:
|
||||
if BS4_AVAILABLE and LXML_AVAILABLE:
|
||||
config = read_config(update_file=True)
|
||||
config = self.configman.get_config()
|
||||
use_system_env = config['environment']['system']
|
||||
|
||||
if not use_system_env:
|
||||
@@ -809,28 +812,37 @@ class WebApplicationManager(SoftwareManager):
|
||||
def requires_root(self, action: SoftwareAction, pkg: SoftwarePackage) -> bool:
|
||||
return False
|
||||
|
||||
def _download_suggestions(self, downloader: SuggestionsDownloader):
|
||||
self.suggestions = downloader.download()
|
||||
|
||||
if self.suggestions:
|
||||
index_gen = SearchIndexGenerator(logger=self.logger)
|
||||
Thread(target=index_gen.generate_index, args=(self.suggestions,), daemon=True).start()
|
||||
def _assign_suggestions(self, suggestions: dict):
|
||||
self.suggestions = suggestions
|
||||
|
||||
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()
|
||||
|
||||
if internet_available:
|
||||
downloader = SuggestionsDownloader(logger=self.logger, http_client=self.http_client,
|
||||
i18n=self.i18n, taskman=task_manager)
|
||||
downloader.register_task()
|
||||
UpdateEnvironmentSettings(env_updater=EnvironmentUpdater(logger=self.context.logger,
|
||||
i18n=self.i18n,
|
||||
http_client=self.http_client,
|
||||
file_downloader=self.context.file_downloader,
|
||||
taskman=task_manager),
|
||||
taskman=task_manager,
|
||||
create_config=create_config,
|
||||
i18n=self.i18n).start()
|
||||
|
||||
self.suggestions_downloader = Thread(target=self._download_suggestions, args=(downloader,), daemon=True)
|
||||
self.suggestions_downloader.start()
|
||||
self.suggestions_loader = SuggestionsLoader(manager=SuggestionsManager(logger=self.logger,
|
||||
http_client=self.http_client,
|
||||
i18n=self.i18n),
|
||||
logger=self.logger,
|
||||
i18n=self.i18n,
|
||||
taskman=task_manager,
|
||||
suggestions_callback=self._assign_suggestions)
|
||||
self.suggestions_loader.start()
|
||||
|
||||
web_config = read_config()
|
||||
|
||||
if self.env_updater.should_download_settings(web_config):
|
||||
self.env_updater.register_task_read_settings(taskman=task_manager)
|
||||
self.env_thread = Thread(target=self.env_updater.read_settings, args=(web_config, False, task_manager), daemon=True)
|
||||
self.env_thread.start()
|
||||
SearchIndexGenerator(taskman=task_manager,
|
||||
suggestions_loader=self.suggestions_loader,
|
||||
i18n=self.i18n,
|
||||
logger=self.logger).start()
|
||||
|
||||
def list_updates(self, internet_available: bool) -> List[PackageUpdate]:
|
||||
pass
|
||||
@@ -893,7 +905,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
return PackageSuggestion(priority=SuggestionPriority(suggestion['priority']), package=app)
|
||||
|
||||
def _fill_config_async(self, output: dict):
|
||||
output.update(read_config())
|
||||
output.update(self.configman.get_config())
|
||||
|
||||
def list_suggestions(self, limit: int, filter_installed: bool) -> List[PackageSuggestion]:
|
||||
web_config = {}
|
||||
@@ -903,14 +915,14 @@ class WebApplicationManager(SoftwareManager):
|
||||
|
||||
if self.suggestions:
|
||||
suggestions = self.suggestions
|
||||
elif self.suggestions_downloader:
|
||||
self.suggestions_downloader.join(5)
|
||||
elif self.suggestions_loader:
|
||||
self.suggestions_loader.join(5)
|
||||
suggestions = self.suggestions
|
||||
else:
|
||||
suggestions = SuggestionsDownloader(logger=self.logger, http_client=self.http_client, i18n=self.i18n).download()
|
||||
suggestions = SuggestionsManager(logger=self.logger, http_client=self.http_client, i18n=self.i18n).download()
|
||||
|
||||
# cleaning memory
|
||||
self.suggestions_downloader = None
|
||||
self.suggestions_loader = None
|
||||
self.suggestions = None
|
||||
|
||||
if suggestions:
|
||||
@@ -981,7 +993,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
traceback.print_exc()
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent:
|
||||
web_config = read_config()
|
||||
web_config = self.configman.get_config()
|
||||
max_width = floor(screen_width * 0.15)
|
||||
|
||||
input_electron = TextInputComponent(label=self.i18n['web.settings.electron.version.label'],
|
||||
@@ -1018,7 +1030,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
return PanelComponent([form_env])
|
||||
|
||||
def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
web_config = read_config()
|
||||
web_config = self.configman.get_config()
|
||||
|
||||
form_env = component.components[0]
|
||||
|
||||
@@ -1036,7 +1048,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
web_config['environment']['cache_exp'] = form_env.get_component('web_cache_exp').get_int_value()
|
||||
|
||||
try:
|
||||
save_config(web_config, CONFIG_FILE)
|
||||
self.configman.save_config(web_config)
|
||||
return True, None
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
|
||||
@@ -41,12 +41,13 @@ class EnvironmentComponent:
|
||||
|
||||
class EnvironmentUpdater:
|
||||
|
||||
def __init__(self, logger: logging.Logger, http_client: HttpClient, file_downloader: FileDownloader, i18n: I18n):
|
||||
def __init__(self, logger: logging.Logger, http_client: HttpClient, file_downloader: FileDownloader, i18n: I18n, taskman: Optional[TaskManager] = None):
|
||||
self.logger = logger
|
||||
self.file_downloader = file_downloader
|
||||
self.i18n = i18n
|
||||
self.http_client = http_client
|
||||
self.task_read_settings_id = 'web_read_settings'
|
||||
self.taskman = taskman
|
||||
|
||||
def _download_and_install(self, version: str, version_url: str, watcher: ProcessWatcher) -> bool:
|
||||
self.logger.info("Downloading NodeJS {}: {}".format(version, version_url))
|
||||
@@ -267,10 +268,10 @@ class EnvironmentUpdater:
|
||||
|
||||
return res
|
||||
|
||||
def _finish_task_download_settings(self, task_man: TaskManager):
|
||||
if task_man:
|
||||
task_man.update_progress(self.task_read_settings_id, 100, None)
|
||||
task_man.finish_task(self.task_read_settings_id)
|
||||
def _finish_task_download_settings(self):
|
||||
if self.taskman:
|
||||
self.taskman.update_progress(self.task_read_settings_id, 100, None)
|
||||
self.taskman.finish_task(self.task_read_settings_id)
|
||||
|
||||
def should_download_settings(self, web_config: dict) -> bool:
|
||||
try:
|
||||
@@ -302,7 +303,14 @@ class EnvironmentUpdater:
|
||||
self.logger.error("Could not parse environment settings file timestamp: {}".format(env_ts_str))
|
||||
return True
|
||||
|
||||
return env_timestamp + timedelta(minutes=settings_exp) <= datetime.utcnow()
|
||||
expired = env_timestamp + timedelta(minutes=settings_exp) <= datetime.utcnow()
|
||||
|
||||
if expired:
|
||||
self.logger.info("Environment settings file has expired. It should be re-downloaded")
|
||||
return True
|
||||
else:
|
||||
self.logger.info("Cached environment settings file is up to date")
|
||||
return False
|
||||
|
||||
def read_cached_settings(self, web_config: dict) -> Optional[dict]:
|
||||
if not self.should_download_settings(web_config):
|
||||
@@ -314,32 +322,33 @@ class EnvironmentUpdater:
|
||||
except yaml.YAMLError:
|
||||
self.logger.error('Could not parse the cache environment settings file: {}'.format(cached_settings_str))
|
||||
|
||||
def register_task_read_settings(self, taskman: TaskManager):
|
||||
taskman.register_task(self.task_read_settings_id, self.i18n['web.task.download_settings'], get_icon_path())
|
||||
def read_settings(self, web_config: dict, cache: bool = True) -> Optional[dict]:
|
||||
if self.taskman:
|
||||
self.taskman.register_task(self.task_read_settings_id, self.i18n['web.task.download_settings'], get_icon_path())
|
||||
self.taskman.update_progress(self.task_read_settings_id, 1, None)
|
||||
|
||||
def read_settings(self, web_config: dict, cache: bool = True, taskman: Optional[TaskManager] = None) -> Optional[dict]:
|
||||
cached_settings = self.read_cached_settings(web_config) if cache else None
|
||||
|
||||
if cached_settings:
|
||||
return cached_settings
|
||||
|
||||
try:
|
||||
if taskman:
|
||||
taskman.update_progress(self.task_read_settings_id, 10, None)
|
||||
if self.taskman:
|
||||
self.taskman.update_progress(self.task_read_settings_id, 10, None)
|
||||
|
||||
self.logger.info("Downloading environment settings")
|
||||
res = self.http_client.get(URL_ENVIRONMENT_SETTINGS)
|
||||
|
||||
if not res:
|
||||
self.logger.warning('Could not retrieve the environments settings from the cloud')
|
||||
self._finish_task_download_settings(taskman)
|
||||
self._finish_task_download_settings()
|
||||
return
|
||||
|
||||
try:
|
||||
settings = yaml.safe_load(res.content)
|
||||
except yaml.YAMLError:
|
||||
self.logger.error('Could not parse environment settings: {}'.format(res.text))
|
||||
self._finish_task_download_settings(taskman)
|
||||
self._finish_task_download_settings()
|
||||
return
|
||||
|
||||
self.logger.info("Caching environment settings to disk")
|
||||
@@ -350,7 +359,7 @@ class EnvironmentUpdater:
|
||||
except OSError:
|
||||
self.logger.error("Could not create Web cache directory: {}".format(cache_dir))
|
||||
self.logger.info('Finished')
|
||||
self._finish_task_download_settings(taskman)
|
||||
self._finish_task_download_settings()
|
||||
return
|
||||
|
||||
cache_timestamp = datetime.utcnow().timestamp()
|
||||
@@ -360,12 +369,12 @@ class EnvironmentUpdater:
|
||||
with open(ENVIRONMENT_SETTINGS_TS_FILE, 'w+') as f:
|
||||
f.write(str(cache_timestamp))
|
||||
|
||||
self._finish_task_download_settings(taskman)
|
||||
self._finish_task_download_settings()
|
||||
self.logger.info("Finished")
|
||||
return settings
|
||||
|
||||
except requests.exceptions.ConnectionError:
|
||||
self._finish_task_download_settings(taskman)
|
||||
self._finish_task_download_settings()
|
||||
return
|
||||
|
||||
def _check_and_fill_electron(self, pkg: WebApplication, env: dict, local_config: dict, x86_x64: bool, widevine: bool, output: List[EnvironmentComponent]):
|
||||
|
||||
@@ -73,7 +73,9 @@ web.settings.nativefier.system.tooltip=The Nativefier version installed on your
|
||||
web.settings.nativefier.system=system
|
||||
web.settings.nativefier.tip=Defines which Nativefier version should be used to generate the Web applications
|
||||
web.task.download_settings=Updating environment settings
|
||||
web.task.suggestions=Downloading applications suggestions list
|
||||
web.task.search_index=Indexing suggestions
|
||||
web.task.suggestions=Downloading suggestions
|
||||
web.task.suggestions.saving=Saving to disk
|
||||
web.uninstall.error.install_dir.not_found=The installation directory {} was not found
|
||||
web.uninstall.error.remove_dir=It was not possible to remove {}
|
||||
web.waiting.env_updater=Updating environment
|
||||
@@ -73,7 +73,9 @@ web.settings.nativefier.system.tooltip=The Nativefier version installed on your
|
||||
web.settings.nativefier.system=system
|
||||
web.settings.nativefier.tip=Defines which Nativefier version should be used to generate the Web applications
|
||||
web.task.download_settings=Updating environment settings
|
||||
web.task.suggestions=Downloading applications suggestions list
|
||||
web.task.search_index=Indexing suggestions
|
||||
web.task.suggestions=Downloading suggestions
|
||||
web.task.suggestions.saving=Saving to disk
|
||||
web.uninstall.error.install_dir.not_found=The installation directory {} was not found
|
||||
web.uninstall.error.remove_dir=It was not possible to remove {}
|
||||
web.waiting.env_updater=Updating environment
|
||||
@@ -73,7 +73,9 @@ web.settings.nativefier.system.tooltip=Se utilizará la versión de Nativefier i
|
||||
web.settings.nativefier.system=sistema
|
||||
web.settings.nativefier.tip=Define qué versión de Nativefier debe usarse para generar las aplicaciones Web
|
||||
web.task.download_settings=Actualizando configuraciones de ambiente
|
||||
web.task.suggestions=Descargando la lista de sugerencias de aplicaciones
|
||||
web.task.search_index=Indexando sugerencias
|
||||
web.task.suggestions=Descargando sugerencias
|
||||
web.task.suggestions.saving=Guardando en disco
|
||||
web.uninstall.error.install_dir.not_found=No se encontró el directorio de instalación {}
|
||||
web.uninstall.error.remove_dir=No fue posible eliminar {}
|
||||
web.waiting.env_updater=Actualizando el ambiente
|
||||
@@ -73,7 +73,9 @@ web.settings.nativefier.system.tooltip=La version de Nativefier installée sur v
|
||||
web.settings.nativefier.system=système
|
||||
web.settings.nativefier.tip=Definit quelle version de Nativefier doit être utilisée pour géner les applications Web
|
||||
web.task.download_settings=Mise à jour des paramètres d'environnement
|
||||
web.task.suggestions=Téléchargement de la liste de suggestions d'applications
|
||||
web.task.search_index=Indexing suggestions
|
||||
web.task.suggestions=Téléchargement de suggestions
|
||||
web.task.suggestions.saving=Saving to disk
|
||||
web.uninstall.error.install_dir.not_found=Impossible de trouver le dossier d'installation {}
|
||||
web.uninstall.error.remove_dir=Impossible d'enlever {}
|
||||
web.waiting.env_updater=Mise à jour de l'environnement
|
||||
|
||||
@@ -73,7 +73,9 @@ web.settings.nativefier.system.tooltip=The Nativefier version installed on your
|
||||
web.settings.nativefier.system=system
|
||||
web.settings.nativefier.tip=Defines which Nativefier version should be used to generate the Web applications
|
||||
web.task.download_settings=Updating environment settings
|
||||
web.task.suggestions=Downloading applications suggestions list
|
||||
web.task.search_index=Indexing suggestions
|
||||
web.task.suggestions=Downloading suggestions
|
||||
web.task.suggestions.saving=Saving to disk
|
||||
web.uninstall.error.install_dir.not_found=The installation directory {} was not found
|
||||
web.uninstall.error.remove_dir=It was not possible to remove {}
|
||||
web.waiting.env_updater=Updating environment
|
||||
@@ -72,7 +72,9 @@ web.settings.nativefier.system.tooltip=A versão do Nativefier instalada no seu
|
||||
web.settings.nativefier.system=sistema
|
||||
web.settings.nativefier.tip=Define qual versão do Nativefier será utilizada para gerar os aplicativos Web
|
||||
web.task.download_settings=Atualizando configurações de ambiente
|
||||
web.task.suggestions=Baixando lista de sugestões de aplicativos
|
||||
web.task.search_index=Indexando sugestões
|
||||
web.task.suggestions=Baixando sugestões
|
||||
web.task.suggestions.saving=Salvando em disco
|
||||
web.uninstall.error.install_dir.not_found=O diretório de instalação {} não foi encontrado
|
||||
web.uninstall.error.remove=Não foi possível remover {}
|
||||
web.waiting.env_updater=Atualizando ambiente
|
||||
|
||||
@@ -73,7 +73,9 @@ web.settings.nativefier.system=Из системы
|
||||
web.settings.nativefier.system.tooltip=Будет использоваться версия Nativefier установленная в Вашей системе
|
||||
web.settings.nativefier.tip=Определяет, какие Nativefier версии должны быдут использованы для установки веб-приложений
|
||||
web.task.download_settings=Updating environment settings
|
||||
web.task.suggestions=Downloading applications suggestions list
|
||||
web.task.search_index=Indexing suggestions
|
||||
web.task.suggestions=Downloading suggestions
|
||||
web.task.suggestions.saving=Saving to disk
|
||||
web.uninstall.error.install_dir.not_found=Каталог установки {} не найден
|
||||
web.uninstall.error.remove_dir=Не удалось удалить {}
|
||||
web.waiting.env_updater=Обнавляется Веб-среда
|
||||
@@ -73,7 +73,9 @@ web.settings.nativefier.system.tooltip=Sisteminizde yüklü olan Nativefier sür
|
||||
web.settings.nativefier.system=sistem
|
||||
web.settings.nativefier.tip=Web uygulamalarını oluşturmak için hangi Nativefier sürümünün kullanılması gerektiğini tanımlar
|
||||
web.task.download_settings=Ortam ayarları güncelleniyor
|
||||
web.task.suggestions=Uygulama öneri listesi indiriliyor
|
||||
web.task.search_index=Indexing suggestions
|
||||
web.task.suggestions=Downloading suggestions
|
||||
web.task.suggestions.saving=Saving to disk
|
||||
web.uninstall.error.install_dir.not_found={} kurulum dizini bulunamadı
|
||||
web.uninstall.error.remove_dir={} kaldırmak mümkün olmadı
|
||||
web.waiting.env_updater=Ortam güncelleniyor
|
||||
|
||||
59
bauh/gems/web/suggestions.py
Normal file
59
bauh/gems/web/suggestions.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import os
|
||||
import traceback
|
||||
from logging import Logger
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
import yaml
|
||||
|
||||
from bauh.api.http import HttpClient
|
||||
from bauh.gems.web import URL_SUGGESTIONS, SUGGESTIONS_CACHE_FILE
|
||||
from bauh.view.util.translation import I18n
|
||||
|
||||
|
||||
class SuggestionsManager:
|
||||
|
||||
def __init__(self, http_client: HttpClient, logger: Logger, i18n: I18n):
|
||||
self.http_client = http_client
|
||||
self.logger = logger
|
||||
self.i18n = i18n
|
||||
|
||||
def download(self) -> dict:
|
||||
self.logger.info("Reading suggestions from {}".format(URL_SUGGESTIONS))
|
||||
try:
|
||||
suggestions = self.http_client.get_yaml(URL_SUGGESTIONS, session=False)
|
||||
|
||||
if suggestions:
|
||||
self.logger.info("{} suggestions successfully read".format(len(suggestions)))
|
||||
else:
|
||||
self.logger.warning("Could not read suggestions from {}".format(URL_SUGGESTIONS))
|
||||
|
||||
except (requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout):
|
||||
self.logger.warning("Internet seems to be off: it was not possible to retrieve the suggestions")
|
||||
suggestions = {}
|
||||
|
||||
self.logger.info("Finished")
|
||||
return suggestions
|
||||
|
||||
def save_to_disk(self, suggestions: dict):
|
||||
if not suggestions:
|
||||
return
|
||||
|
||||
self.logger.info('Caching {} suggestions to the disk'.format(len(suggestions)))
|
||||
suggestions_file_dir = os.path.dirname(SUGGESTIONS_CACHE_FILE)
|
||||
try:
|
||||
Path(suggestions_file_dir).mkdir(parents=True, exist_ok=True)
|
||||
except OSError:
|
||||
self.logger.error("Could not generate the directory {}".format(suggestions_file_dir))
|
||||
traceback.print_exc()
|
||||
return
|
||||
|
||||
try:
|
||||
with open(SUGGESTIONS_CACHE_FILE, 'w+') as f:
|
||||
f.write(yaml.safe_dump(suggestions))
|
||||
|
||||
self.logger.info("{} suggestions successfully cached to file '{}'".format(len(suggestions), SUGGESTIONS_CACHE_FILE))
|
||||
except:
|
||||
self.logger.error("Could write to {}".format(SUGGESTIONS_CACHE_FILE))
|
||||
traceback.print_exc()
|
||||
return
|
||||
@@ -1,87 +1,85 @@
|
||||
import logging
|
||||
import time
|
||||
import traceback
|
||||
from pathlib import Path
|
||||
from threading import Thread
|
||||
from typing import Optional
|
||||
|
||||
import requests
|
||||
import yaml
|
||||
|
||||
from bauh.api.abstract.handler import TaskManager
|
||||
from bauh.api.http import HttpClient
|
||||
from bauh.gems.web import URL_SUGGESTIONS, TEMP_PATH, SEARCH_INDEX_FILE, SUGGESTIONS_CACHE_FILE, get_icon_path
|
||||
from bauh.commons.boot import CreateConfigFile
|
||||
from bauh.commons.html import bold
|
||||
from bauh.gems.web import SEARCH_INDEX_FILE, get_icon_path
|
||||
from bauh.gems.web.environment import EnvironmentUpdater
|
||||
from bauh.gems.web.suggestions import SuggestionsManager
|
||||
from bauh.view.util.translation import I18n
|
||||
|
||||
|
||||
class SuggestionsDownloader:
|
||||
class SuggestionsLoader(Thread):
|
||||
|
||||
def __init__(self, http_client: HttpClient, logger: logging.Logger, i18n: I18n, taskman: TaskManager = None):
|
||||
super(SuggestionsDownloader, self).__init__()
|
||||
self.http_client = http_client
|
||||
self.logger = logger
|
||||
def __init__(self, taskman: TaskManager, manager: SuggestionsManager,
|
||||
i18n: I18n, logger: logging.Logger, suggestions_callback, suggestions: Optional[dict] = None):
|
||||
super(SuggestionsLoader, self).__init__(daemon=True)
|
||||
self.taskman = taskman
|
||||
self.i18n = i18n
|
||||
self.task_id = 'web_sugs'
|
||||
self._task_registered = False
|
||||
self._task_finished = False
|
||||
self.manager = manager
|
||||
self.suggestions_callback = suggestions_callback
|
||||
self.i18n = i18n
|
||||
self.logger = logger
|
||||
self.suggestions = suggestions
|
||||
self.task_name = self.i18n['web.task.suggestions']
|
||||
self.taskman.register_task(self.task_id, self.task_name, get_icon_path())
|
||||
|
||||
def _finish_task(self):
|
||||
if self.taskman:
|
||||
def run(self):
|
||||
ti = time.time()
|
||||
self.taskman.update_progress(self.task_id, 10, None)
|
||||
try:
|
||||
self.suggestions = self.manager.download()
|
||||
|
||||
if self.suggestions_callback:
|
||||
self.suggestions_callback(self.suggestions)
|
||||
|
||||
if self.suggestions:
|
||||
self.taskman.update_progress(self.task_id, 50, self.i18n['web.task.suggestions.saving'])
|
||||
self.manager.save_to_disk(self.suggestions)
|
||||
|
||||
except:
|
||||
self.logger.error("Unexpected exception")
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
self.taskman.update_progress(self.task_id, 100, None)
|
||||
self.taskman.finish_task(self.task_id)
|
||||
self._task_finished = True
|
||||
self.logger.info("Finished")
|
||||
|
||||
def register_task(self):
|
||||
if self.taskman and not self._task_registered and not self._task_finished:
|
||||
self.taskman.register_task(self.task_id, self.i18n['web.task.suggestions'], get_icon_path())
|
||||
self._task_registered = True
|
||||
|
||||
def download(self) -> dict:
|
||||
if self.taskman:
|
||||
self.taskman.update_progress(self.task_id, 10, None)
|
||||
|
||||
self.logger.info("Reading suggestions from {}".format(URL_SUGGESTIONS))
|
||||
try:
|
||||
suggestions = self.http_client.get_yaml(URL_SUGGESTIONS, session=False)
|
||||
|
||||
if suggestions:
|
||||
self.logger.info("{} suggestions successfully read".format(len(suggestions)))
|
||||
else:
|
||||
self.logger.warning("Could not read suggestions from {}".format(URL_SUGGESTIONS))
|
||||
|
||||
except (requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout):
|
||||
self.logger.warning("Internet seems to be off: it was not possible to retrieve the suggestions")
|
||||
self._finish_task()
|
||||
return {}
|
||||
|
||||
self._finish_task()
|
||||
return suggestions
|
||||
tf = time.time()
|
||||
self.logger.info("Finished. Took {0:.2f} seconds".format(tf - ti))
|
||||
|
||||
|
||||
class SearchIndexGenerator:
|
||||
class SearchIndexGenerator(Thread):
|
||||
|
||||
def __init__(self, logger: logging.Logger):
|
||||
def __init__(self, taskman: TaskManager, suggestions_loader: SuggestionsLoader, i18n: I18n, logger: logging.Logger):
|
||||
super(SearchIndexGenerator, self).__init__(daemon=True)
|
||||
self.taskman = taskman
|
||||
self.i18n = i18n
|
||||
self.logger = logger
|
||||
self.suggestions_loader = suggestions_loader
|
||||
self.task_id = 'web_idx_gen'
|
||||
self.taskman.register_task(self.task_id, self.i18n['web.task.search_index'], get_icon_path())
|
||||
|
||||
def run(self):
|
||||
ti = time.time()
|
||||
self.taskman.update_progress(self.task_id, 0, self.i18n['task.waiting_task'].format(bold(self.suggestions_loader.task_name)))
|
||||
self.suggestions_loader.join()
|
||||
|
||||
if self.suggestions_loader.suggestions:
|
||||
self.generate_index(self.suggestions_loader.suggestions)
|
||||
else:
|
||||
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))
|
||||
|
||||
def generate_index(self, suggestions: dict):
|
||||
self.logger.info('Caching {} suggestions to the disk'.format(len(suggestions)))
|
||||
|
||||
try:
|
||||
Path(TEMP_PATH).mkdir(parents=True, exist_ok=True)
|
||||
except:
|
||||
self.logger.error("Could not generate the directory {}".format(TEMP_PATH))
|
||||
traceback.print_exc()
|
||||
return
|
||||
|
||||
try:
|
||||
with open(SUGGESTIONS_CACHE_FILE, 'w+') as f:
|
||||
f.write(yaml.safe_dump(suggestions))
|
||||
|
||||
self.logger.info('{} successfully cached to the disk as {}'.format(len(suggestions), SUGGESTIONS_CACHE_FILE))
|
||||
except:
|
||||
self.logger.error("Could write to {}".format(SUGGESTIONS_CACHE_FILE))
|
||||
traceback.print_exc()
|
||||
return
|
||||
|
||||
self.taskman.update_progress(self.task_id, 1, None)
|
||||
self.logger.info('Indexing suggestions')
|
||||
index = {}
|
||||
|
||||
@@ -102,6 +100,7 @@ class SearchIndexGenerator:
|
||||
mapped.add(key)
|
||||
|
||||
if index:
|
||||
self.taskman.update_progress(self.task_id, 50, self.i18n['web.task.suggestions.saving'])
|
||||
self.logger.info('Preparing search index for writing')
|
||||
|
||||
for key in index.keys():
|
||||
@@ -115,3 +114,29 @@ class SearchIndexGenerator:
|
||||
except:
|
||||
self.logger.error("Could not write the seach index to {}".format(SEARCH_INDEX_FILE))
|
||||
traceback.print_exc()
|
||||
|
||||
self.taskman.update_progress(self.task_id, 100, None)
|
||||
self.taskman.finish_task(self.task_id)
|
||||
|
||||
|
||||
class UpdateEnvironmentSettings(Thread):
|
||||
|
||||
def __init__(self, env_updater: EnvironmentUpdater, taskman: TaskManager, i18n: I18n, create_config: CreateConfigFile):
|
||||
super(UpdateEnvironmentSettings, self).__init__(daemon=True)
|
||||
self.env_updater = env_updater
|
||||
self.taskman = taskman
|
||||
self.create_config = create_config
|
||||
self.task_id = env_updater.task_read_settings_id
|
||||
self.i18n = i18n
|
||||
|
||||
def run(self):
|
||||
self.taskman.register_task(self.task_id, self.i18n['web.task.download_settings'], get_icon_path())
|
||||
self.taskman.update_progress(self.task_id, 1, self.i18n['task.waiting_task'].format(bold(self.create_config.task_name)))
|
||||
self.create_config.join()
|
||||
|
||||
web_config = self.create_config.config
|
||||
if self.env_updater.should_download_settings(web_config):
|
||||
self.env_updater.read_settings(web_config=web_config, cache=False)
|
||||
else:
|
||||
self.taskman.update_progress(self.task_id, 100, None)
|
||||
self.taskman.finish_task(self.task_id)
|
||||
|
||||
Reference in New Issue
Block a user