From e4e4567fbae91882d8e916225882ce83801170fb Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Sat, 11 Jan 2020 18:10:07 -0300 Subject: [PATCH] [feature][flatpak] config file --- CHANGELOG.md | 3 ++- README.md | 5 +++++ bauh/gems/flatpak/__init__.py | 3 +++ bauh/gems/flatpak/config.py | 7 +++++++ bauh/gems/flatpak/controller.py | 30 ++++++++++++++++++++------- bauh/gems/flatpak/resources/locale/ca | 3 ++- bauh/gems/flatpak/resources/locale/de | 3 ++- bauh/gems/flatpak/resources/locale/en | 3 ++- bauh/gems/flatpak/resources/locale/es | 3 ++- bauh/gems/flatpak/resources/locale/it | 3 ++- bauh/gems/flatpak/resources/locale/pt | 3 ++- bauh/view/resources/locale/ca | 3 ++- bauh/view/resources/locale/de | 3 ++- bauh/view/resources/locale/en | 3 ++- bauh/view/resources/locale/es | 3 ++- bauh/view/resources/locale/it | 3 ++- bauh/view/resources/locale/pt | 3 ++- 17 files changed, 64 insertions(+), 20 deletions(-) create mode 100644 bauh/gems/flatpak/config.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d39df47..92e904b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [0.8.1] ### Features: - Flatpak: - - allow the user to choose the installation level: user or system + - allow the user to choose the installation level: **user** or **system** - able to deal with user and system applications / runtimes + - new configuration file located at **~/.config/bauh/flatpak.yml** ( it allows to define a default installation level ) ### Improvements - All icons are now SVG files diff --git a/README.md b/README.md index afa95cb8..4135b682 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,11 @@ Before uninstalling bauh via your package manager, consider executing `bauh --re ![flatpak_search](https://raw.githubusercontent.com/vinifmor/bauh/staging/pictures/flatpak/search.gif) +- The configuration file is located at **~/.config/bauh/flatpak.yml** and it allows the following customizations: +``` +installation_level: null # defines a default installation level: user or system. ( the popup will not be displayed if a value is defined ) +``` + - Required dependencies: - Any distro: **flatpak** diff --git a/bauh/gems/flatpak/__init__.py b/bauh/gems/flatpak/__init__.py index b39f2445..9d497cb2 100644 --- a/bauh/gems/flatpak/__init__.py +++ b/bauh/gems/flatpak/__init__.py @@ -1,3 +1,6 @@ import os +from pathlib import Path + ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) SUGGESTIONS_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/flatpak/suggestions.txt' +CONFIG_FILE = '{}/.config/bauh/flatpak.yml'.format(Path.home()) diff --git a/bauh/gems/flatpak/config.py b/bauh/gems/flatpak/config.py new file mode 100644 index 00000000..c6c9dcff --- /dev/null +++ b/bauh/gems/flatpak/config.py @@ -0,0 +1,7 @@ +from bauh.commons.config import read_config as read +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) diff --git a/bauh/gems/flatpak/controller.py b/bauh/gems/flatpak/controller.py index 0232d98d..c5f3c0a9 100644 --- a/bauh/gems/flatpak/controller.py +++ b/bauh/gems/flatpak/controller.py @@ -11,7 +11,8 @@ from bauh.api.abstract.model import PackageHistory, PackageUpdate, SoftwarePacka from bauh.api.abstract.view import MessageType from bauh.commons.html import strip_html, bold from bauh.commons.system import SystemProcess, ProcessHandler, SimpleProcess -from bauh.gems.flatpak import flatpak, SUGGESTIONS_FILE +from bauh.gems.flatpak import flatpak, SUGGESTIONS_FILE, CONFIG_FILE +from bauh.gems.flatpak.config import read_config from bauh.gems.flatpak.constants import FLATHUB_API_URL from bauh.gems.flatpak.model import FlatpakApplication from bauh.gems.flatpak.worker import FlatpakAsyncDataLoader, FlatpakUpdateLoader @@ -220,16 +221,31 @@ class FlatpakManager(SoftwareManager): def install(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher) -> bool: - user_level = watcher.request_confirmation(title=self.i18n['flatpak.install.install_level.title'], - body=self.i18n['flatpak.install.install_level.body'].format(bold(pkg.name)), - confirmation_label=self.i18n['no'].capitalize(), - deny_label=self.i18n['yes'].capitalize()) + config = read_config() - pkg.installation = 'user' if user_level else 'system' + install_level = config['installation_level'] + + if install_level is not None: + self.logger.info("Default Flaptak installation level defined: {}".format(install_level)) + + if install_level not in ('user', 'system'): + watcher.show_message(title=self.i18n['error'].capitalize(), + body=self.i18n['flatpak.install.bad_install_level.body'].format(field=bold('installation_level'), + file=bold(CONFIG_FILE)), + type_=MessageType.ERROR) + return False + + pkg.installation = install_level + else: + user_level = watcher.request_confirmation(title=self.i18n['flatpak.install.install_level.title'], + body=self.i18n['flatpak.install.install_level.body'].format(bold(pkg.name)), + confirmation_label=self.i18n['no'].capitalize(), + deny_label=self.i18n['yes'].capitalize()) + pkg.installation = 'user' if user_level else 'system' handler = ProcessHandler(watcher) - if user_level: + if pkg.installation == 'user': if not handler.handle_simple(flatpak.register_flathub('user')): return False diff --git a/bauh/gems/flatpak/resources/locale/ca b/bauh/gems/flatpak/resources/locale/ca index 6d4ced3a..c82658a6 100644 --- a/bauh/gems/flatpak/resources/locale/ca +++ b/bauh/gems/flatpak/resources/locale/ca @@ -43,4 +43,5 @@ flatpak.info.projectlicense=llicència flatpak.info.translateurl=Traducció flatpak.info.developername=desenvolupador flatpak.install.install_level.title=Tipus d'instal·lació -flatpak.install.install_level.body=S'ha d'instal·lar {} per a tots els usuaris del dispositiu ( sistema ) ? \ No newline at end of file +flatpak.install.install_level.body=S'ha d'instal·lar {} per a tots els usuaris del dispositiu ( sistema ) ? +flatpak.install.bad_install_level.body=Valor invàlid per a {field} al fitxer de configuració {file} \ No newline at end of file diff --git a/bauh/gems/flatpak/resources/locale/de b/bauh/gems/flatpak/resources/locale/de index 869e00d5..b25fa3b1 100644 --- a/bauh/gems/flatpak/resources/locale/de +++ b/bauh/gems/flatpak/resources/locale/de @@ -42,4 +42,5 @@ flatpak.info.version=Version flatpak.history.date=Datum flatpak.history.commit=Commit flatpak.install.install_level.title=Installationstyp -flatpak.install.install_level.body=Sollte {} für alle Gerätebenutzer installiert werden ( system ) ? \ No newline at end of file +flatpak.install.install_level.body=Sollte {} für alle Gerätebenutzer installiert werden ( system ) ? +flatpak.install.bad_install_level.body=Ungültiger Wert für {field} in der Konfigurationsdatei {file} \ No newline at end of file diff --git a/bauh/gems/flatpak/resources/locale/en b/bauh/gems/flatpak/resources/locale/en index 02d43556..3cb1c488 100644 --- a/bauh/gems/flatpak/resources/locale/en +++ b/bauh/gems/flatpak/resources/locale/en @@ -42,4 +42,5 @@ flatpak.info.version=version flatpak.history.date=date flatpak.history.commit=commit flatpak.install.install_level.title=Installation type -flatpak.install.install_level.body=Should {} be installed for all the device users ( system ) ? \ No newline at end of file +flatpak.install.install_level.body=Should {} be installed for all the device users ( system ) ? +flatpak.install.bad_install_level.body=Invalid value for {field} in the configuration file {file} \ No newline at end of file diff --git a/bauh/gems/flatpak/resources/locale/es b/bauh/gems/flatpak/resources/locale/es index 2ea4939c..3b77bb87 100644 --- a/bauh/gems/flatpak/resources/locale/es +++ b/bauh/gems/flatpak/resources/locale/es @@ -43,4 +43,5 @@ flatpak.info.projectlicense=licencia flatpak.info.translateurl=Traducción flatpak.info.developername=desarrollador flatpak.install.install_level.title=Tipo de instalación -flatpak.install.install_level.body=¿Debería {} estar instalado para todos los usuarios del dispositivo ( sistema )? \ No newline at end of file +flatpak.install.install_level.body=¿Debería {} estar instalado para todos los usuarios del dispositivo ( sistema )? +flatpak.install.bad_install_level.body=Valor inválido para {field} en el archivo de configuración {file} \ No newline at end of file diff --git a/bauh/gems/flatpak/resources/locale/it b/bauh/gems/flatpak/resources/locale/it index 0e39d6e0..a7823990 100644 --- a/bauh/gems/flatpak/resources/locale/it +++ b/bauh/gems/flatpak/resources/locale/it @@ -22,4 +22,5 @@ flatpak.info.installation=installazione flatpak.info.installation.user=utente flatpak.info.installation.system=sistema flatpak.install.install_level.title=Tipo di installazione -flatpak.install.install_level.body={} deve essere installato per tutti gli utenti del dispositivo ( sistema ) ? \ No newline at end of file +flatpak.install.install_level.body={} deve essere installato per tutti gli utenti del dispositivo ( sistema ) ? +flatpak.install.bad_install_level.body=Valore non valido per {field} nel file di configurazione {file} \ No newline at end of file diff --git a/bauh/gems/flatpak/resources/locale/pt b/bauh/gems/flatpak/resources/locale/pt index 8d4ab950..a18fc962 100644 --- a/bauh/gems/flatpak/resources/locale/pt +++ b/bauh/gems/flatpak/resources/locale/pt @@ -43,4 +43,5 @@ flatpak.info.projectlicense=licença flatpak.info.translateurl=tradução flatpak.info.developername=desenvolvedor flatpak.install.install_level.title=Tipo de instalação -flatpak.install.install_level.body={} deve ser instalado para todos os usuários desse dispositivo ( sistema ) ? \ No newline at end of file +flatpak.install.install_level.body={} deve ser instalado para todos os usuários desse dispositivo ( sistema ) ? +flatpak.install.bad_install_level.body=Valor inválido para {field} no arquivo de configuração {file} \ No newline at end of file diff --git a/bauh/view/resources/locale/ca b/bauh/view/resources/locale/ca index e44ebf72..fc3565f7 100644 --- a/bauh/view/resources/locale/ca +++ b/bauh/view/resources/locale/ca @@ -218,4 +218,5 @@ all_files=tots els fitxers file_chooser.title=Selector de fitxers message.file.not_exist=Fitxer no existeix message.file.not_exist.body=El fitxer {} sembla no existir -icon_button.tooltip.disabled=Aquesta acció no està disponible \ No newline at end of file +icon_button.tooltip.disabled=Aquesta acció no està disponible +user=usuari \ No newline at end of file diff --git a/bauh/view/resources/locale/de b/bauh/view/resources/locale/de index 483bff89..d61f0295 100644 --- a/bauh/view/resources/locale/de +++ b/bauh/view/resources/locale/de @@ -173,4 +173,5 @@ file_chooser.title=Dateiauswahl message.file.not_exist=Datei existiert nicht message.file.not_exist.body=Die Datei {} scheint nicht zu existieren development=Entwicklung -icon_button.tooltip.disabled=Diese Aktion ist nicht verfügbar \ No newline at end of file +icon_button.tooltip.disabled=Diese Aktion ist nicht verfügbar +user=Benutzer \ No newline at end of file diff --git a/bauh/view/resources/locale/en b/bauh/view/resources/locale/en index 080408aa..2c30bb91 100644 --- a/bauh/view/resources/locale/en +++ b/bauh/view/resources/locale/en @@ -177,4 +177,5 @@ file_chooser.title=File selector message.file.not_exist=File does not exist message.file.not_exist.body=The file {} seems not to exist development=development -icon_button.tooltip.disabled=This action is unavailable \ No newline at end of file +icon_button.tooltip.disabled=This action is unavailable +user=user \ No newline at end of file diff --git a/bauh/view/resources/locale/es b/bauh/view/resources/locale/es index 9f818708..d3b46dd1 100644 --- a/bauh/view/resources/locale/es +++ b/bauh/view/resources/locale/es @@ -217,4 +217,5 @@ all_files=todos los archivos file_chooser.title=Selector de archivos message.file.not_exist=Archivo no existe message.file.not_exist.body=El archivo {} parece no existir -icon_button.tooltip.disabled=This action is unavailable \ No newline at end of file +icon_button.tooltip.disabled=This action is unavailable +user=usuario \ No newline at end of file diff --git a/bauh/view/resources/locale/it b/bauh/view/resources/locale/it index 3b451471..7fec700b 100644 --- a/bauh/view/resources/locale/it +++ b/bauh/view/resources/locale/it @@ -174,4 +174,5 @@ file_chooser.title=Selettore file message.file.not_exist=File non esiste message.file.not_exist.body=Il file {} sembra non esistere development=sviluppo -icon_button.tooltip.disabled=Questa azione non è disponibile \ No newline at end of file +icon_button.tooltip.disabled=Questa azione non è disponibile +user=utente \ No newline at end of file diff --git a/bauh/view/resources/locale/pt b/bauh/view/resources/locale/pt index 68cb5e4b..bd82a25c 100644 --- a/bauh/view/resources/locale/pt +++ b/bauh/view/resources/locale/pt @@ -220,4 +220,5 @@ all_files=todos os arquivos file_chooser.title=Seletor arquivos message.file.not_exist=Arquivo não existe message.file.not_exist.body=O arquivo {} parece não existir -icon_button.tooltip.disabled=Esta ação está indisponível \ No newline at end of file +icon_button.tooltip.disabled=Esta ação está indisponível +user=usuário \ No newline at end of file