[feature][flatpak] registering Flathub at system level

This commit is contained in:
Vinícius Moreira
2020-01-13 14:41:01 -03:00
parent 9f15b1b244
commit 8dd114da85
13 changed files with 84 additions and 24 deletions

View File

@@ -9,6 +9,7 @@ from bauh.api.abstract.handler import ProcessWatcher
from bauh.api.abstract.model import PackageHistory, PackageUpdate, SoftwarePackage, PackageSuggestion, \
SuggestionPriority
from bauh.api.abstract.view import MessageType
from bauh.commons import user
from bauh.commons.html import strip_html, bold
from bauh.commons.system import SystemProcess, ProcessHandler, SimpleProcess
from bauh.gems.flatpak import flatpak, SUGGESTIONS_FILE, CONFIG_FILE
@@ -67,7 +68,7 @@ class FlatpakManager(SoftwareManager):
remote_level = 'user'
else:
remote_level = 'user'
flatpak.set_default_remotes(remote_level)
ProcessHandler().handle_simple(flatpak.set_default_remotes(remote_level))
return remote_level
@@ -264,8 +265,28 @@ class FlatpakManager(SoftwareManager):
deny_label=self.i18n['yes'].capitalize())
pkg.installation = 'user' if user_level else 'system'
remotes = flatpak.list_remotes()
handler = ProcessHandler(watcher)
if pkg.installation == 'user' and not remotes['user']:
handler.handle_simple(flatpak.set_default_remotes('user'))
elif pkg.installation == 'system' and not remotes['system']:
if user.is_root():
handler.handle_simple(flatpak.set_default_remotes('system'))
else:
user_password, valid = watcher.request_root_password()
if not valid:
watcher.print('Operation aborted')
return False
else:
if not handler.handle_simple(flatpak.set_default_remotes('system', user_password)):
watcher.show_message(title=self.i18n['error'].capitalize(),
body=self.i18n['flatpak.remotes.system_flathub.error'],
type_=MessageType.ERROR)
watcher.print("Operation cancelled")
return False
if pkg.installation == 'user':
if not handler.handle_simple(flatpak.register_flathub('user')):
return False
@@ -318,7 +339,7 @@ class FlatpakManager(SoftwareManager):
loader.join()
for app in to_update:
updates.append(PackageUpdate(pkg_id='{}:{}'.format(app.id, app.branch),
updates.append(PackageUpdate(pkg_id='{}:{}:{}'.format(app.id, app.branch, app.installation),
pkg_type='flatpak',
version=app.version))

View File

@@ -6,7 +6,7 @@ from io import StringIO
from typing import List, Dict, Set
from bauh.api.exception import NoInternetException
from bauh.commons.system import new_subprocess, run_cmd, new_root_subprocess, SimpleProcess
from bauh.commons.system import new_subprocess, run_cmd, new_root_subprocess, SimpleProcess, SystemProcess
BASE_CMD = 'flatpak'
RE_SEVERAL_SPACES = re.compile(r'\s+')
@@ -343,8 +343,9 @@ def install(app_id: str, origin: str, installation: str):
return new_subprocess([BASE_CMD, 'install', origin, app_id, '-y', '--{}'.format(installation)])
def set_default_remotes(installation: str):
run_cmd('{} remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo --{}'.format(BASE_CMD, installation))
def set_default_remotes(installation: str, root_password: str = None) -> SimpleProcess:
cmd = [BASE_CMD, 'remote-add', '--if-not-exists', 'flathub', 'https://flathub.org/repo/flathub.flatpakrepo', '--{}'.format(installation)]
return SimpleProcess(cmd, root_password=root_password)
def has_remotes_set() -> bool:

View File

@@ -44,4 +44,5 @@ 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 ) ?
flatpak.install.bad_install_level.body=Valor invàlid per a {field} al fitxer de configuració {file}
flatpak.install.bad_install_level.body=Valor invàlid per a {field} al fitxer de configuració {file}
flatpak.remotes.system_flathub.error=No s'ha pogut afegir Flathub com a dipòsit del sistema ( remote )

View File

@@ -43,4 +43,5 @@ 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 ) ?
flatpak.install.bad_install_level.body=Ungültiger Wert für {field} in der Konfigurationsdatei {file}
flatpak.install.bad_install_level.body=Ungültiger Wert für {field} in der Konfigurationsdatei {file}
flatpak.remotes.system_flathub.error=Flathub konnte nicht als System-Repository ( remote ) hinzugefügt werden

View File

@@ -43,4 +43,5 @@ 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 ) ?
flatpak.install.bad_install_level.body=Invalid value for {field} in the configuration file {file}
flatpak.install.bad_install_level.body=Invalid value for {field} in the configuration file {file}
flatpak.remotes.system_flathub.error=It was not possible to add Flathub as a system repository ( remote )

View File

@@ -44,4 +44,5 @@ 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 )?
flatpak.install.bad_install_level.body=Valor inválido para {field} en el archivo de configuración {file}
flatpak.install.bad_install_level.body=Valor inválido para {field} en el archivo de configuración {file}
flatpak.remotes.system_flathub.error=No fue posible agregar Flathub como repositorio del sistema ( remote )

View File

@@ -23,4 +23,5 @@ 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 ) ?
flatpak.install.bad_install_level.body=Valore non valido per {field} nel file di configurazione {file}
flatpak.install.bad_install_level.body=Valore non valido per {field} nel file di configurazione {file}
flatpak.remotes.system_flathub.error=Non è stato possibile aggiungere Flathub come repository di sistema ( remote )

View File

@@ -44,4 +44,5 @@ 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 ) ?
flatpak.install.bad_install_level.body=Valor inválido para {field} no arquivo de configuração {file}
flatpak.install.bad_install_level.body=Valor inválido para {field} no arquivo de configuração {file}
flatpak.remotes.system_flathub.error=Não foi possível adicionar o Flathub como um repositório do sistema ( remote )