Merge branch 'fpakus' into fpakpart

# Conflicts:
#	bauh/gems/flatpak/flatpak.py
#	bauh/gems/flatpak/model.py
This commit is contained in:
Vinícius Moreira
2020-01-10 17:42:27 -03:00
3 changed files with 28 additions and 17 deletions

View File

@@ -135,7 +135,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)
@@ -147,7 +147,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)
@@ -208,7 +208,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):
@@ -243,7 +243,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

@@ -97,6 +97,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
}) })
@@ -136,6 +137,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
@@ -159,11 +161,21 @@ def uninstall(app_ref: str):
def list_updates_as_str(version: str) -> Dict[str, set]: def list_updates_as_str(version: str) -> Dict[str, set]:
updates = read_updates(version, 'system')
user_updates = read_updates(version, 'user')
for attr in ('full', 'partial'):
updates[attr].update(user_updates[attr])
return updates
def read_updates(version: str, installation: str) -> Dict[str, set]:
if version < '1.2': if version < '1.2':
# TODO # TODO
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
reg = r'[0-9]+\.\s+.+' if version >= '1.5.0' else r'[0-9]+\.\s+(\w+|\.)+\s+\w+\s+(\w|\.)+' reg = r'[0-9]+\.\s+.+' if version >= '1.5.0' else r'[0-9]+\.\s+(\w+|\.)+\s+\w+\s+(\w|\.)+'
@@ -189,12 +201,13 @@ def list_updates_as_str(version: str) -> Dict[str, set]:
return res return res
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']
return new_root_subprocess(cmd, root_password)
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)
@@ -202,8 +215,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()

View File

@@ -8,7 +8,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
@@ -23,7 +24,7 @@ class FlatpakApplication(SoftwarePackage):
if runtime: if runtime:
self.categories = ['runtime'] self.categories = ['runtime']
def is_incomplete(self) -> bool: def is_incomplete(self):
return self.description is None and self.icon_url return self.description is None and self.icon_url
def has_history(self) -> bool: def has_history(self) -> bool:
@@ -71,9 +72,6 @@ class FlatpakApplication(SoftwarePackage):
def get_publisher(self): def get_publisher(self):
return self.origin return self.origin
def can_be_uninstalled(self) -> bool:
return self.installed and not self.partial
def gen_partial(self, partial_id: str) -> "FlatpakApplication": def gen_partial(self, partial_id: str) -> "FlatpakApplication":
partial = copy.deepcopy(self) partial = copy.deepcopy(self)
partial.id = partial_id partial.id = partial_id