improvement: only changing the installed package status ( not refreshing the whole table ) | fix: flatpak downgrading error handling

This commit is contained in:
Vinicius Moreira
2019-09-24 15:17:09 -03:00
parent d3e5835a8b
commit 2a84ff4c32
15 changed files with 104 additions and 54 deletions

View File

@@ -1,3 +1,4 @@
import json
import os
import re
import shutil
@@ -639,7 +640,17 @@ class ArchManager(SoftwareManager):
return False
def install(self, pkg: ArchPackage, root_password: str, watcher: ProcessWatcher, skip_optdeps: bool = False) -> bool:
return self._install_from_aur(pkg.name, pkg.maintainer, root_password, ProcessHandler(watcher), dependency=False, skip_optdeps=skip_optdeps)
res = self._install_from_aur(pkg.name, pkg.maintainer, root_password, ProcessHandler(watcher), dependency=False, skip_optdeps=skip_optdeps)
if res:
if os.path.exists(pkg.get_disk_data_path()):
with open(pkg.get_disk_data_path()) as f:
data = f.read()
if data:
data = json.loads(data)
pkg.fill_cached_data(data)
return res
def _is_wget_available(self):
try:
@@ -668,8 +679,7 @@ class ArchManager(SoftwareManager):
return False
def cache_to_disk(self, pkg: ArchPackage, icon_bytes: bytes, only_icon: bool):
if self.context.disk_cache and pkg.supports_disk_cache():
pass
pass
def requires_root(self, action: str, pkg: ArchPackage):
return action != 'search'

View File

@@ -1,3 +1,4 @@
import traceback
from datetime import datetime
from threading import Thread
from typing import List, Set, Type
@@ -117,7 +118,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_phrase='Updates complete.'))
success = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.downgrade(pkg.ref, commit, root_password), success_phrases=['Changes complete.', 'Updates complete.']))
watcher.change_progress(100)
return success
@@ -152,7 +153,19 @@ class FlatpakManager(SoftwareManager):
return PackageHistory(pkg=pkg, history=commits, pkg_status_idx=status_idx)
def install(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher) -> bool:
return ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.install(pkg.id, pkg.origin)))
res = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.install(pkg.id, pkg.origin)))
if res:
try:
fields = flatpak.get_fields(pkg.id, pkg.branch, ['Ref', 'Branch'])
if fields:
pkg.ref = fields[0]
pkg.branch = fields[1]
except:
traceback.print_exc()
return res
def is_enabled(self):
return self.enabled

View File

@@ -34,6 +34,22 @@ def get_app_info_fields(app_id: str, branch: str, fields: List[str] = [], check_
return data
def get_fields(app_id: str, branch: str, fields: List[str]) -> List[str]:
cmd = [BASE_CMD, 'info', app_id]
if branch:
cmd.append(branch)
info = new_subprocess(cmd).stdout
res = []
for o in new_subprocess(['grep', '-E', '({}):.+'.format('|'.join(fields)), '-o'], stdin=info).stdout:
if o:
res.append(o.decode().split(':')[-1].strip())
return res
def is_installed():
version = get_version()
return False if version is None else True
@@ -282,5 +298,3 @@ def has_remotes_set() -> bool:
def run(app_id: str):
subprocess.Popen([BASE_CMD, 'run', app_id])

View File

@@ -21,13 +21,13 @@ class FlatpakApplication(SoftwarePackage):
return self.description is None and self.icon_url
def has_history(self):
return self.installed
return self.installed and self.ref
def has_info(self):
return self.installed
def can_be_downgraded(self):
return self.installed
return self.installed and self.ref
def get_type(self):
return 'flatpak'