[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_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)
@@ -133,7 +133,7 @@ class FlatpakManager(SoftwareManager):
commit = commits[commit_idx + 1]
watcher.change_substatus(self.i18n['flatpak.downgrade.reverting'])
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.'],
wrong_error_phrase='Warning'))
watcher.change_progress(100)
@@ -194,7 +194,7 @@ class FlatpakManager(SoftwareManager):
def get_history(self, pkg: FlatpakApplication) -> PackageHistory:
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
for idx, data in enumerate(commits):
@@ -229,7 +229,7 @@ class FlatpakManager(SoftwareManager):
return flatpak.is_installed()
def requires_root(self, action: str, pkg: FlatpakApplication):
return action == 'downgrade'
return action == 'downgrade' and pkg.installation == 'system'
def prepare(self):
pass

View File

@@ -96,6 +96,7 @@ def list_installed(version: str) -> List[dict]:
'description': None,
'origin': data[1],
'runtime': runtime,
'installation': 'user' if 'user' in data[5] else 'system',
'version': ref_split[2] if runtime else None
})
@@ -135,6 +136,7 @@ def list_installed(version: str) -> List[dict]:
'description': data[4],
'origin': data[5],
'runtime': runtime,
'installation': 'user' if 'user' in data[6] else 'system',
'version': app_ver})
return apps
@@ -158,10 +160,16 @@ def uninstall(app_ref: 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':
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:
updates = new_subprocess([BASE_CMD, 'update']).stdout
updates = new_subprocess([BASE_CMD, 'update', '--{}'.format(installation)]).stdout
out = StringIO()
@@ -175,12 +183,17 @@ def list_updates_as_str(version: str):
return out.read()
def downgrade(app_ref: str, commit: str, root_password: str) -> subprocess.Popen:
return new_root_subprocess([BASE_CMD, 'update', '--no-related', '--commit={}'.format(commit), app_ref, '-y'], root_password)
def downgrade(app_ref: str, commit: str, installation: str, root_password: str) -> subprocess.Popen:
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]:
log = run_cmd('{} remote-info --log {} {}'.format(BASE_CMD, origin, app_ref))
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, installation))
if 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()
def get_app_commits_data(app_ref: str, origin: str) -> List[dict]:
log = run_cmd('{} remote-info --log {} {}'.format(BASE_CMD, origin, app_ref))
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, installation))
if not log:
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):
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():

View File

@@ -7,7 +7,8 @@ from bauh.gems.flatpak import ROOT_DIR
class FlatpakApplication(SoftwarePackage):
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,
latest_version=latest_version, description=description)
self.ref = ref
@@ -16,6 +17,7 @@ class FlatpakApplication(SoftwarePackage):
self.origin = origin
self.runtime = runtime
self.commit = commit
self.installation = installation
if runtime:
self.categories = ['runtime']