From ce7e309799dfd08332d650be92fa18928736fad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Tue, 19 May 2020 18:50:05 -0300 Subject: [PATCH] [fix] ignore updates file handling for Arch, AppImage and Flatpak --- bauh/gems/appimage/controller.py | 9 ++++-- bauh/gems/arch/controller.py | 51 +++++++++++++++++++++----------- bauh/gems/flatpak/controller.py | 9 ++++-- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/bauh/gems/appimage/controller.py b/bauh/gems/appimage/controller.py index bec0029f..aefdf3c0 100644 --- a/bauh/gems/appimage/controller.py +++ b/bauh/gems/appimage/controller.py @@ -316,6 +316,8 @@ class AppImageManager(SoftwareManager): if os.path.exists(de_path): os.remove(de_path) + self.revert_ignored_update(pkg) + return True def get_managed_types(self) -> Set[Type[SoftwarePackage]]: @@ -723,8 +725,11 @@ class AppImageManager(SoftwareManager): ignored_list.sort() with open(UPDATES_IGNORED_FILE, 'w+') as f: - for ignored in ignored_list: - f.write('{}\n'.format(ignored)) + if ignored_list: + for ignored in ignored_list: + f.write('{}\n'.format(ignored)) + else: + f.write('') def revert_ignored_update(self, pkg: AppImage): current_ignored = self._read_ignored_updates() diff --git a/bauh/gems/arch/controller.py b/bauh/gems/arch/controller.py index c4f23d38..cdd26799 100644 --- a/bauh/gems/arch/controller.py +++ b/bauh/gems/arch/controller.py @@ -2259,35 +2259,50 @@ class ArchManager(SoftwareManager): return True def _list_ignored_updates(self) -> Set[str]: + ignored = set() if os.path.exists(UPDATES_IGNORED_FILE): 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): ignored = self._list_ignored_updates() - if not ignored or pkg.name not in ignored: - Path(CONFIG_DIR).mkdir(parents=True, exist_ok=True) + if pkg.name not in ignored: + ignored.add(pkg.name) + self._write_ignored(ignored) - with open(UPDATES_IGNORED_FILE, 'a+') as f: - f.write('{}\n'.format(pkg.name)) - - pkg.update_ignored = True + pkg.update_ignored = True def _revert_ignored_updates(self, pkgs: Iterable[str]): - if os.path.exists(UPDATES_IGNORED_FILE): - ignored = [] - with open(UPDATES_IGNORED_FILE) as f: - for line in f.read().split('\n'): - if line: - clean_line = line.strip() + ignored = self._list_ignored_updates() - if clean_line and clean_line not in pkgs: - ignored.append(clean_line) + for p in pkgs: + if p in ignored: + ignored.remove(p) - with open(UPDATES_IGNORED_FILE, 'w+') as f: - f.writelines(ignored) + self._write_ignored(ignored) def revert_ignored_update(self, pkg: ArchPackage): self._revert_ignored_updates({pkg.name}) - pkg.update_ignored = False \ No newline at end of file + pkg.update_ignored = False diff --git a/bauh/gems/flatpak/controller.py b/bauh/gems/flatpak/controller.py index 95c3b77f..37f54b63 100644 --- a/bauh/gems/flatpak/controller.py +++ b/bauh/gems/flatpak/controller.py @@ -232,6 +232,8 @@ class FlatpakManager(SoftwareManager): if self.suggestions_cache: self.suggestions_cache.delete(pkg.id) + self.revert_ignored_update(pkg) + return uninstalled def get_info(self, app: FlatpakApplication) -> dict: @@ -568,8 +570,11 @@ class FlatpakManager(SoftwareManager): ignored_list.sort() with open(UPDATES_IGNORED_FILE, 'w+') as f: - for ignored in ignored_list: - f.write('{}\n'.format(ignored)) + if ignored_list: + for ignored in ignored_list: + f.write('{}\n'.format(ignored)) + else: + f.write('') def ignore_update(self, pkg: FlatpakApplication): ignored_keys = self._read_ignored_updates()