[arch][snap] improvement -> caching categories file for 24 hours

This commit is contained in:
Vinicius Moreira
2020-12-28 10:41:54 -03:00
parent 487f019573
commit 01bd532465
36 changed files with 226 additions and 83 deletions

View File

@@ -3,5 +3,5 @@ from bauh.gems.snap import CONFIG_FILE
def read_config(update_file: bool = False) -> dict:
template = {'install_channel': False}
template = {'install_channel': False, 'categories_exp': 24}
return read(CONFIG_FILE, template, update_file=update_file)

View File

@@ -11,7 +11,7 @@ from bauh.api.abstract.handler import ProcessWatcher, TaskManager
from bauh.api.abstract.model import SoftwarePackage, PackageHistory, PackageUpdate, PackageSuggestion, \
SuggestionPriority, CustomSoftwareAction, PackageStatus
from bauh.api.abstract.view import SingleSelectComponent, SelectViewType, InputOption, ViewComponent, PanelComponent, \
FormComponent
FormComponent, TextInputComponent
from bauh.api.exception import NoInternetException
from bauh.commons import resource
from bauh.commons.category import CategoriesDownloader
@@ -19,7 +19,7 @@ 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, SNAP_CACHE_PATH, CATEGORIES_FILE_PATH, SUGGESTIONS_FILE, \
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
from bauh.gems.snap.model import SnapApplication
@@ -285,7 +285,7 @@ class SnapManager(SoftwareManager):
def _start_category_task(self, task_man: TaskManager):
if task_man:
task_man.register_task('snap_cats', self.i18n['task.download_categories'].format('Snap'), get_icon_path())
task_man.register_task('snap_cats', self.i18n['task.download_categories'], get_icon_path())
task_man.update_progress('snap_cats', 50, None)
def _finish_category_task(self, task_man: TaskManager):
@@ -294,11 +294,14 @@ class SnapManager(SoftwareManager):
task_man.finish_task('snap_cats')
def prepare(self, task_manager: TaskManager, root_password: str, internet_available: bool):
Thread(target=read_config, args=(True,), daemon=True).start()
snap_config = read_config()
CategoriesDownloader(id_='snap', manager=self, http_client=self.http_client, logger=self.logger,
url_categories_file=URL_CATEGORIES_FILE, disk_cache_dir=SNAP_CACHE_PATH,
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()
@@ -434,20 +437,31 @@ class SnapManager(SoftwareManager):
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent:
snap_config = read_config()
max_width = 200
install_channel = new_select(label=self.i18n['snap.config.install_channel'],
opts=[(self.i18n['yes'].capitalize(), True, None),
(self.i18n['no'].capitalize(), False, None)],
value=bool(snap_config['install_channel']),
id_='install_channel',
max_width=200,
id_='snap_install_channel',
max_width=max_width,
tip=self.i18n['snap.config.install_channel.tip'])
return PanelComponent([FormComponent([install_channel], self.i18n['installation'].capitalize())])
categories_exp = TextInputComponent(id_='snap_cat_exp',
value=snap_config['categories_exp'] if isinstance(snap_config['categories_exp'], int) else '',
max_width=max_width,
only_int=True,
label=self.i18n['snap.config.categories_exp'],
tooltip=self.i18n['snap.config.categories_exp.tip'])
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()
config['install_channel'] = component.components[0].components[0].get_selected()
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()
try:
save_config(config, CONFIG_FILE)

View File

@@ -6,6 +6,8 @@ snap.action.channel.status=Changing channel of
snap.action.refresh.confirm=Actualitza {} ?
snap.action.refresh.label=Actualitza
snap.action.refresh.status=Sestà actualitzant
snap.config.categories_exp=Categories expiration
snap.config.categories_exp.tip=It defines the expiration time (in HOURS) of the Snaps categories mapping file stored in disc. Use 0 so that it is always updated during initialization.
snap.config.install_channel=Display channels
snap.config.install_channel.tip=It allows to select one of the available channels for the given application to be installed
snap.info.channel=channel

View File

@@ -6,6 +6,8 @@ snap.action.channel.status=Changing channel of
snap.action.refresh.confirm=Erneuern {} ?
snap.action.refresh.label=Erneuern
snap.action.refresh.status=Erneuern
snap.config.categories_exp=Categories expiration
snap.config.categories_exp.tip=It defines the expiration time (in HOURS) of the Snaps categories mapping file stored in disc. Use 0 so that it is always updated during initialization.
snap.config.install_channel=Display channels
snap.config.install_channel.tip=It allows to select one of the available channels for the given application to be installed
snap.info.channel=channel

View File

@@ -6,6 +6,8 @@ snap.action.channel.status=Changing channel of
snap.action.refresh.confirm=Refresh {} ?
snap.action.refresh.label=Refresh
snap.action.refresh.status=Refreshing
snap.config.categories_exp=Categories expiration
snap.config.categories_exp.tip=It defines the expiration time (in HOURS) of the Snaps categories mapping file stored in disc. Use 0 so that it is always updated during initialization.
snap.config.install_channel=Display channels
snap.config.install_channel.tip=It allows to select one of the available channels for the given application to be installed
snap.info.channel=channel

View File

@@ -6,6 +6,8 @@ snap.action.channel.label=Cambiar canal
snap.action.refresh.confirm=Actualizar {} ?
snap.action.refresh.label=Actualizar
snap.action.refresh.status=Actualizando
snap.config.categories_exp=Expiración de categorías
snap.config.categories_exp.tip=Define el tiempo de vencimiento (en HORAS) del archivo de mapeo de categorías de Snaps almacenado en el disco. Utilice 0 para que siempre se actualice durante la inicialización.
snap.config.install_channel=Mostrar canales
snap.config.install_channel.tip=Permite seleccionar uno de los canales disponibles para la aplicación a instalar
snap.info.channel=canal

View File

@@ -6,6 +6,8 @@ snap.action.channel.status=Changement de canal de
snap.action.refresh.confirm=Actualiser {} ?
snap.action.refresh.label=Actualiser
snap.action.refresh.status=Actualisation
snap.config.categories_exp=Categories expiration
snap.config.categories_exp.tip=It defines the expiration time (in HOURS) of the Snaps categories mapping file stored in disc. Use 0 so that it is always updated during initialization.
snap.config.install_channel=Afficher les canaux
snap.config.install_channel.tip=Permet de sélectionner un des canaux disponibles pour l'application à installer
snap.info.channel=canal

View File

@@ -6,6 +6,8 @@ snap.action.channel.status=Changing channel of
snap.action.refresh.confirm=Ripristina {} ?
snap.action.refresh.label=Ripristina
snap.action.refresh.status=Ripristinare
snap.config.categories_exp=Categories expiration
snap.config.categories_exp.tip=It defines the expiration time (in HOURS) of the Snaps categories mapping file stored in disc. Use 0 so that it is always updated during initialization.
snap.config.install_channel=Display channels
snap.config.install_channel.tip=It allows to select one of the available channels for the given application to be installed
snap.info.channel=channel

View File

@@ -6,6 +6,8 @@ snap.action.channel.status=Alterando canal de
snap.action.refresh.confirm=Atualizar {} ?
snap.action.refresh.label=Atualizar
snap.action.refresh.status=Atualizando
snap.config.categories_exp=Expiração de categorias
snap.config.categories_exp.tip=Define o tempo de expiração (em HORAS) do arquivo de mapeamento de categorias Snap armazenado em disco. Utilize 0 para que ele seja sempre atualizado durante a inicialização.
snap.config.install_channel=Exibir canais
snap.config.install_channel.tip=Permite-se selecionar um dos canais disponíveis para o aplicativo a ser instalado
snap.info.channel=canal

View File

@@ -6,6 +6,8 @@ snap.action.channel.status=Changing channel of
snap.action.refresh.confirm=Обновить {} ?
snap.action.refresh.label=Обновить
snap.action.refresh.status=Обновляется
snap.config.categories_exp=Categories expiration
snap.config.categories_exp.tip=It defines the expiration time (in HOURS) of the Snaps categories mapping file stored in disc. Use 0 so that it is always updated during initialization.
snap.config.install_channel=Display channels
snap.config.install_channel.tip=It allows to select one of the available channels for the given application to be installed
snap.info.channel=channel

View File

@@ -6,6 +6,8 @@ snap.action.channel.status=Changing channel of
snap.action.refresh.confirm=Yenile {} ?
snap.action.refresh.label=Yenile
snap.action.refresh.status=Yenileniyor
snap.config.categories_exp=Categories expiration
snap.config.categories_exp.tip=It defines the expiration time (in HOURS) of the Snaps categories mapping file stored in disc. Use 0 so that it is always updated during initialization.
snap.config.install_channel=Display channels
snap.config.install_channel.tip=It allows to select one of the available channels for the given application to be installed
snap.info.channel=channel