From cca98602e6674b3892bdfbfbc1c347160090700b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Mon, 18 May 2020 17:14:55 -0300 Subject: [PATCH] [feature][appimage] able to ignore appimage updates --- README.md | 1 + bauh/gems/appimage/__init__.py | 2 ++ bauh/gems/appimage/controller.py | 54 +++++++++++++++++++++++++++++++- bauh/gems/appimage/model.py | 9 +++++- 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bea6e8b8..174e0500 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,7 @@ installation_level: null # defines a default installation level: user or system. - Databases updater daemon running every 20 minutes ( it can be customized via the configuration file described below ) - Crashes may happen during an AppImage installation if **AppImageLauncher** is installed. It is advisable to uninstall it and reboot the system before trying to install an application. - All supported application names can be found at [apps.txt](https://github.com/vinifmor/bauh-files/blob/master/appimage/apps.txt) +- Applications with ignored updates are defined at **~/.config/bauh/appimage/updates_ignored.txt** - The configuration file is located at **~/.config/bauh/appimage.yml** and it allows the following customizations: ``` db_updater: diff --git a/bauh/gems/appimage/__init__.py b/bauh/gems/appimage/__init__.py index 74073e52..7875d807 100644 --- a/bauh/gems/appimage/__init__.py +++ b/bauh/gems/appimage/__init__.py @@ -9,6 +9,8 @@ LOCAL_PATH = '{}/.local/share/bauh/appimage'.format(str(Path.home())) INSTALLATION_PATH = LOCAL_PATH + '/installed/' SUGGESTIONS_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/appimage/suggestions.txt' CONFIG_FILE = '{}/appimage.yml'.format(CONFIG_PATH) +CONFIG_DIR = '{}/appimage'.format(CONFIG_PATH) +UPDATES_IGNORED_FILE = '{}/updates_ignored.txt'.format(CONFIG_DIR) def get_icon_path() -> str: diff --git a/bauh/gems/appimage/controller.py b/bauh/gems/appimage/controller.py index bee22356..c257236f 100644 --- a/bauh/gems/appimage/controller.py +++ b/bauh/gems/appimage/controller.py @@ -27,7 +27,8 @@ from bauh.commons import resource from bauh.commons.config import save_config from bauh.commons.html import bold from bauh.commons.system import SystemProcess, new_subprocess, ProcessHandler, run_cmd, SimpleProcess -from bauh.gems.appimage import query, INSTALLATION_PATH, LOCAL_PATH, SUGGESTIONS_FILE, CONFIG_FILE, ROOT_DIR +from bauh.gems.appimage import query, INSTALLATION_PATH, LOCAL_PATH, SUGGESTIONS_FILE, CONFIG_FILE, ROOT_DIR, \ + CONFIG_DIR, UPDATES_IGNORED_FILE from bauh.gems.appimage.config import read_config from bauh.gems.appimage.model import AppImage from bauh.gems.appimage.worker import DatabaseUpdater @@ -235,6 +236,13 @@ class AppImageManager(SoftwareManager): if not connection: self._close_connection(DB_APPS_PATH, con) + ignored_updates = self._read_ignored_updates() + + if ignored_updates: + for app in res.installed: + if app.supports_ignored_updates() and app.name in ignored_updates: + app.updates_ignored = True + res.total = len(res.installed) return res @@ -684,3 +692,47 @@ class AppImageManager(SoftwareManager): to_update.append(requirement) return UpgradeRequirements([], [], to_update, []) + + def _read_ignored_updates(self) -> Set[str]: + ignored = set() + if os.path.exists(UPDATES_IGNORED_FILE): + with open(UPDATES_IGNORED_FILE) as f: + ignored_txt = f.read() + + for l in ignored_txt.split('\n'): + if l: + line_clean = l.strip() + + if line_clean: + ignored.add(line_clean) + + return ignored + + def ignore_update(self, pkg: AppImage): + Path(CONFIG_DIR).mkdir(parents=True, exist_ok=True) + + current_ignored = self._read_ignored_updates() + + if pkg.name not in current_ignored: + current_ignored.add(pkg.name) + self._write_ignored_updates(current_ignored) + + pkg.updates_ignored = True + + def _write_ignored_updates(self, names: Set[str]): + ignored_list = [*names] + ignored_list.sort() + + with open(UPDATES_IGNORED_FILE, 'w+') as f: + for ignored in ignored_list: + f.write('{}\n'.format(ignored)) + + def revert_ignored_update(self, pkg: AppImage): + current_ignored = self._read_ignored_updates() + + if current_ignored and pkg.name in current_ignored: + current_ignored.remove(pkg.name) + + self._write_ignored_updates(current_ignored) + + pkg.updates_ignored = False diff --git a/bauh/gems/appimage/model.py b/bauh/gems/appimage/model.py index 5663bb64..948dcfaf 100644 --- a/bauh/gems/appimage/model.py +++ b/bauh/gems/appimage/model.py @@ -15,7 +15,7 @@ class AppImage(SoftwarePackage): url_download: str = None, url_icon: str = None, url_screenshot: str = None, license: str = None, author: str = None, categories=None, icon_path: str = None, installed: bool = False, url_download_latest_version: str = None, local_file_path: str = None, imported: bool = False, - i18n: I18n = None, install_dir: str = None, custom_actions: List[CustomSoftwareAction] = None, **kwargs): + i18n: I18n = None, install_dir: str = None, custom_actions: List[CustomSoftwareAction] = None, updates_ignored: bool = False, **kwargs): super(AppImage, self).__init__(id=name, name=name, version=version, latest_version=version, icon_url=url_icon, license=license, description=description, installed=installed) @@ -32,6 +32,7 @@ class AppImage(SoftwarePackage): self.i18n = i18n self.install_dir = install_dir self.custom_actions = custom_actions + self.updates_ignored = updates_ignored def __repr__(self): return "{} (name={}, github={})".format(self.__class__.__name__, self.name, self.github) @@ -107,3 +108,9 @@ class AppImage(SoftwarePackage): def supports_backup(self) -> bool: return False + + def supports_ignored_updates(self) -> bool: + return self.installed and not self.imported + + def is_update_ignored(self) -> bool: + return self.updates_ignored