[flatpak] initial user installation level support

This commit is contained in:
Vinícius Moreira
2020-01-09 15:16:31 -03:00
parent 8b77c87dab
commit f65e77872b
3 changed files with 29 additions and 14 deletions

View File

@@ -121,7 +121,7 @@ class FlatpakManager(SoftwareManager):
watcher.change_progress(10) watcher.change_progress(10)
watcher.change_substatus(self.i18n['flatpak.downgrade.commits']) watcher.change_substatus(self.i18n['flatpak.downgrade.commits'])
commits = flatpak.get_app_commits(pkg.ref, pkg.origin) commits = flatpak.get_app_commits(pkg.ref, pkg.origin, pkg.installation)
commit_idx = commits.index(pkg.commit) commit_idx = commits.index(pkg.commit)
@@ -133,7 +133,7 @@ class FlatpakManager(SoftwareManager):
commit = commits[commit_idx + 1] commit = commits[commit_idx + 1]
watcher.change_substatus(self.i18n['flatpak.downgrade.reverting']) watcher.change_substatus(self.i18n['flatpak.downgrade.reverting'])
watcher.change_progress(50) watcher.change_progress(50)
success = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.downgrade(pkg.ref, commit, root_password), success = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.downgrade(pkg.ref, commit, pkg.installation, root_password),
success_phrases=['Changes complete.', 'Updates complete.'], success_phrases=['Changes complete.', 'Updates complete.'],
wrong_error_phrase='Warning')) wrong_error_phrase='Warning'))
watcher.change_progress(100) watcher.change_progress(100)
@@ -194,7 +194,7 @@ class FlatpakManager(SoftwareManager):
def get_history(self, pkg: FlatpakApplication) -> PackageHistory: def get_history(self, pkg: FlatpakApplication) -> PackageHistory:
pkg.commit = flatpak.get_commit(pkg.id, pkg.branch) pkg.commit = flatpak.get_commit(pkg.id, pkg.branch)
commits = flatpak.get_app_commits_data(pkg.ref, pkg.origin) commits = flatpak.get_app_commits_data(pkg.ref, pkg.origin, pkg.installation)
status_idx = 0 status_idx = 0
for idx, data in enumerate(commits): for idx, data in enumerate(commits):
@@ -229,7 +229,7 @@ class FlatpakManager(SoftwareManager):
return flatpak.is_installed() return flatpak.is_installed()
def requires_root(self, action: str, pkg: FlatpakApplication): def requires_root(self, action: str, pkg: FlatpakApplication):
return action == 'downgrade' return action == 'downgrade' and pkg.installation == 'system'
def prepare(self): def prepare(self):
pass pass

View File

@@ -96,6 +96,7 @@ def list_installed(version: str) -> List[dict]:
'description': None, 'description': None,
'origin': data[1], 'origin': data[1],
'runtime': runtime, 'runtime': runtime,
'installation': 'user' if 'user' in data[5] else 'system',
'version': ref_split[2] if runtime else None 'version': ref_split[2] if runtime else None
}) })
@@ -135,6 +136,7 @@ def list_installed(version: str) -> List[dict]:
'description': data[4], 'description': data[4],
'origin': data[5], 'origin': data[5],
'runtime': runtime, 'runtime': runtime,
'installation': 'user' if 'user' in data[6] else 'system',
'version': app_ver}) 'version': app_ver})
return apps return apps
@@ -158,10 +160,16 @@ def uninstall(app_ref: str):
def list_updates_as_str(version: str): def list_updates_as_str(version: str):
updates = read_updates(version, 'system')
updates += read_updates(version, 'user')
return updates
def read_updates(version: str, installation: str) -> str:
if version < '1.2': if version < '1.2':
return run_cmd('{} update --no-related'.format(BASE_CMD), ignore_return_code=True) return run_cmd('{} update --no-related --{}'.format(BASE_CMD, installation), ignore_return_code=True)
else: else:
updates = new_subprocess([BASE_CMD, 'update']).stdout updates = new_subprocess([BASE_CMD, 'update', '--{}'.format(installation)]).stdout
out = StringIO() out = StringIO()
@@ -175,12 +183,17 @@ def list_updates_as_str(version: str):
return out.read() return out.read()
def downgrade(app_ref: str, commit: str, root_password: str) -> subprocess.Popen: def downgrade(app_ref: str, commit: str, installation: str, root_password: str) -> subprocess.Popen:
return new_root_subprocess([BASE_CMD, 'update', '--no-related', '--commit={}'.format(commit), app_ref, '-y'], root_password) cmd = [BASE_CMD, 'update', '--no-related', '--commit={}'.format(commit), app_ref, '-y']
if installation == 'system':
return new_root_subprocess(cmd, root_password)
else:
return new_subprocess(cmd)
def get_app_commits(app_ref: str, origin: str) -> List[str]: def get_app_commits(app_ref: str, origin: str, installation: str) -> List[str]:
log = run_cmd('{} remote-info --log {} {}'.format(BASE_CMD, origin, app_ref)) log = run_cmd('{} remote-info --log {} {} --{}'.format(BASE_CMD, origin, app_ref, installation))
if log: if log:
return re.findall(r'Commit+:\s(.+)', log) return re.findall(r'Commit+:\s(.+)', log)
@@ -188,8 +201,8 @@ def get_app_commits(app_ref: str, origin: str) -> List[str]:
raise NoInternetException() raise NoInternetException()
def get_app_commits_data(app_ref: str, origin: str) -> List[dict]: def get_app_commits_data(app_ref: str, origin: str, installation: str) -> List[dict]:
log = run_cmd('{} remote-info --log {} {}'.format(BASE_CMD, origin, app_ref)) log = run_cmd('{} remote-info --log {} {} --{}'.format(BASE_CMD, origin, app_ref, installation))
if not log: if not log:
raise NoInternetException() raise NoInternetException()
@@ -294,7 +307,7 @@ def search(version: str, word: str, app_id: bool = False) -> List[dict]:
def install(app_id: str, origin: str): def install(app_id: str, origin: str):
return new_subprocess([BASE_CMD, 'install', origin, app_id, '-y']) return new_subprocess([BASE_CMD, 'install', origin, app_id, '-y', '--user'])
def set_default_remotes(): def set_default_remotes():

View File

@@ -7,7 +7,8 @@ from bauh.gems.flatpak import ROOT_DIR
class FlatpakApplication(SoftwarePackage): class FlatpakApplication(SoftwarePackage):
def __init__(self, id: str = None, name: str = None, version: str = None, latest_version: str = None, description: str = None, def __init__(self, id: str = None, name: str = None, version: str = None, latest_version: str = None, description: str = None,
branch: str = None, arch: str = None, origin: str = None, runtime: bool = False, ref: str = None, commit: str = None): branch: str = None, arch: str = None, origin: str = None, runtime: bool = False, ref: str = None, commit: str = None,
installation: str = None):
super(FlatpakApplication, self).__init__(id=id, name=name, version=version, super(FlatpakApplication, self).__init__(id=id, name=name, version=version,
latest_version=latest_version, description=description) latest_version=latest_version, description=description)
self.ref = ref self.ref = ref
@@ -16,6 +17,7 @@ class FlatpakApplication(SoftwarePackage):
self.origin = origin self.origin = origin
self.runtime = runtime self.runtime = runtime
self.commit = commit self.commit = commit
self.installation = installation
if runtime: if runtime:
self.categories = ['runtime'] self.categories = ['runtime']