[fix] ignore updates file handling for Arch, AppImage and Flatpak

This commit is contained in:
Vinícius Moreira
2020-05-19 18:50:05 -03:00
parent 5cd26d1d82
commit ce7e309799
3 changed files with 47 additions and 22 deletions

View File

@@ -316,6 +316,8 @@ class AppImageManager(SoftwareManager):
if os.path.exists(de_path): if os.path.exists(de_path):
os.remove(de_path) os.remove(de_path)
self.revert_ignored_update(pkg)
return True return True
def get_managed_types(self) -> Set[Type[SoftwarePackage]]: def get_managed_types(self) -> Set[Type[SoftwarePackage]]:
@@ -723,8 +725,11 @@ class AppImageManager(SoftwareManager):
ignored_list.sort() ignored_list.sort()
with open(UPDATES_IGNORED_FILE, 'w+') as f: with open(UPDATES_IGNORED_FILE, 'w+') as f:
for ignored in ignored_list: if ignored_list:
f.write('{}\n'.format(ignored)) for ignored in ignored_list:
f.write('{}\n'.format(ignored))
else:
f.write('')
def revert_ignored_update(self, pkg: AppImage): def revert_ignored_update(self, pkg: AppImage):
current_ignored = self._read_ignored_updates() current_ignored = self._read_ignored_updates()

View File

@@ -2259,34 +2259,49 @@ class ArchManager(SoftwareManager):
return True return True
def _list_ignored_updates(self) -> Set[str]: def _list_ignored_updates(self) -> Set[str]:
ignored = set()
if os.path.exists(UPDATES_IGNORED_FILE): if os.path.exists(UPDATES_IGNORED_FILE):
with open(UPDATES_IGNORED_FILE) as f: with open(UPDATES_IGNORED_FILE) as f:
return {line.strip() for line in f.read().split('\n') if line} ignored_lines = f.readlines()
for line in ignored_lines:
if line:
line_clean = line.strip()
if line_clean:
ignored.add(line_clean)
return ignored
def _write_ignored(self, names: Set[str]):
Path(CONFIG_DIR).mkdir(parents=True, exist_ok=True)
ignored_list = [*names]
ignored_list.sort()
with open(UPDATES_IGNORED_FILE, 'w+') as f:
if ignored_list:
for pkg in ignored_list:
f.write('{}\n'.format(pkg))
else:
f.write('')
def ignore_update(self, pkg: ArchPackage): def ignore_update(self, pkg: ArchPackage):
ignored = self._list_ignored_updates() ignored = self._list_ignored_updates()
if not ignored or pkg.name not in ignored: if pkg.name not in ignored:
Path(CONFIG_DIR).mkdir(parents=True, exist_ok=True) ignored.add(pkg.name)
self._write_ignored(ignored)
with open(UPDATES_IGNORED_FILE, 'a+') as f: pkg.update_ignored = True
f.write('{}\n'.format(pkg.name))
pkg.update_ignored = True
def _revert_ignored_updates(self, pkgs: Iterable[str]): def _revert_ignored_updates(self, pkgs: Iterable[str]):
if os.path.exists(UPDATES_IGNORED_FILE): ignored = self._list_ignored_updates()
ignored = []
with open(UPDATES_IGNORED_FILE) as f:
for line in f.read().split('\n'):
if line:
clean_line = line.strip()
if clean_line and clean_line not in pkgs: for p in pkgs:
ignored.append(clean_line) if p in ignored:
ignored.remove(p)
with open(UPDATES_IGNORED_FILE, 'w+') as f: self._write_ignored(ignored)
f.writelines(ignored)
def revert_ignored_update(self, pkg: ArchPackage): def revert_ignored_update(self, pkg: ArchPackage):
self._revert_ignored_updates({pkg.name}) self._revert_ignored_updates({pkg.name})

View File

@@ -232,6 +232,8 @@ class FlatpakManager(SoftwareManager):
if self.suggestions_cache: if self.suggestions_cache:
self.suggestions_cache.delete(pkg.id) self.suggestions_cache.delete(pkg.id)
self.revert_ignored_update(pkg)
return uninstalled return uninstalled
def get_info(self, app: FlatpakApplication) -> dict: def get_info(self, app: FlatpakApplication) -> dict:
@@ -568,8 +570,11 @@ class FlatpakManager(SoftwareManager):
ignored_list.sort() ignored_list.sort()
with open(UPDATES_IGNORED_FILE, 'w+') as f: with open(UPDATES_IGNORED_FILE, 'w+') as f:
for ignored in ignored_list: if ignored_list:
f.write('{}\n'.format(ignored)) for ignored in ignored_list:
f.write('{}\n'.format(ignored))
else:
f.write('')
def ignore_update(self, pkg: FlatpakApplication): def ignore_update(self, pkg: FlatpakApplication):
ignored_keys = self._read_ignored_updates() ignored_keys = self._read_ignored_updates()