From f34924cd76697f7d25376db8de353d10555108e7 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Tue, 5 Dec 2023 15:30:31 -0300 Subject: [PATCH] [gems.appimage] refactoring: using the 'repository' field on queries instead of the deprecated 'github' --- CHANGELOG.md | 1 + bauh/gems/appimage/controller.py | 8 ++++---- bauh/gems/appimage/model.py | 11 ++++++----- bauh/gems/appimage/query.py | 10 ++++++---- bauh/gems/appimage/resources/locale/ca | 1 + bauh/gems/appimage/resources/locale/de | 1 + bauh/gems/appimage/resources/locale/en | 1 + bauh/gems/appimage/resources/locale/es | 1 + bauh/gems/appimage/resources/locale/fr | 1 + bauh/gems/appimage/resources/locale/it | 1 + bauh/gems/appimage/resources/locale/pt | 1 + bauh/gems/appimage/resources/locale/ru | 1 + bauh/gems/appimage/resources/locale/tr | 1 + 13 files changed, 26 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 665c0b51..7df64bf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Improvements - AppImage - info window: displaying "unknown" when there is no mapped license + - supporting AppImages from GitLab repositories - Arch - adding the AUR's URL on the package information dialog [#339](https://github.com/vinifmor/bauh/issues/339) - General diff --git a/bauh/gems/appimage/controller.py b/bauh/gems/appimage/controller.py index e4458fcf..87428af9 100644 --- a/bauh/gems/appimage/controller.py +++ b/bauh/gems/appimage/controller.py @@ -184,7 +184,7 @@ class AppImageManager(SoftwareManager, SettingsController): self.logger.warning(f"Could not get a connection for database '{db_path}'") def _gen_app_key(self, app: AppImage): - return f"{app.name.lower()}{app.github.lower() if app.github else ''}" + return f"{app.name.lower()}{app.repository.lower() if app.repository else ''}" def search(self, words: str, disk_loader: DiskCacheLoader, limit: int = -1, is_url: bool = False) -> SearchResult: if is_url: @@ -276,7 +276,7 @@ class AppImageManager(SoftwareManager, SettingsController): for tup in cursor.fetchall(): for app in installed_apps: - if app.name.lower() == tup[0].lower() and (not app.github or app.github.lower() == tup[1].lower()): + if app.name.lower() == tup[0].lower() and (not app.repository or app.repository.lower() == tup[1].lower()): continuous_version = app.version == 'continuous' continuous_update = tup[2] == 'continuous' @@ -441,7 +441,7 @@ class AppImageManager(SoftwareManager, SettingsController): return TransactionResult(success=True, installed=None, removed=[pkg]) def _add_self_latest_version(self, app: AppImage): - if app.name == self.context.app_name and app.github == self.app_github and not app.url_download_latest_version: + if app.name == self.context.app_name and app.repository == self.app_github and not app.url_download_latest_version: history = self.get_history(app) if not history or not history.history: @@ -500,7 +500,7 @@ class AppImageManager(SoftwareManager, SettingsController): try: cursor = app_con.cursor() - cursor.execute(query.FIND_APP_ID_BY_NAME_AND_GITHUB.format(pkg.name.lower(), pkg.github.lower() if pkg.github else '')) + cursor.execute(query.FIND_APP_ID_BY_REPO_AND_NAME.format(pkg.repository.lower() if pkg.repository else '', pkg.name.lower())) app_tuple = cursor.fetchone() if not app_tuple: diff --git a/bauh/gems/appimage/model.py b/bauh/gems/appimage/model.py index 69574ff6..927300c2 100644 --- a/bauh/gems/appimage/model.py +++ b/bauh/gems/appimage/model.py @@ -32,7 +32,8 @@ class AppImage(SoftwarePackage): def cached_attrs(cls) -> Tuple[str, ...]: if cls.__cached_attrs is None: cls.__cached_attrs = ('name', 'description', 'version', 'url_download', 'author', 'license', 'source', - 'icon_path', 'github', 'categories', 'imported', 'install_dir', 'symlink') + 'icon_path', 'repository', 'categories', 'imported', 'install_dir', + 'symlink') return cls.__cached_attrs @@ -43,17 +44,17 @@ class AppImage(SoftwarePackage): return cls.__re_many_spaces - def __init__(self, name: str = None, description: str = None, github: str = None, source: str = None, version: str = None, + def __init__(self, name: str = None, description: str = None, repository: str = None, source: str = None, version: str = None, 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, updates_ignored: bool = False, - symlink: str = None, manual_update: bool = False, **kwargs): + symlink: str = None, manual_update: bool = False, github: str = None, **kwargs): super(AppImage, self).__init__(id=name, name=name, version=version, latest_version=version, icon_url=url_icon, license=license, description=description, installed=installed) self.source = source - self.github = github + self.repository = repository if repository else (github if github else repository) self.categories = (categories.split(',') if isinstance(categories, str) else categories) if categories else None self.url_download = url_download self.icon_path = icon_path @@ -69,7 +70,7 @@ class AppImage(SoftwarePackage): self.manual_update = manual_update # True when the user is manually installing/upgrading an AppImage file def __repr__(self): - return "{} (name={}, github={})".format(self.__class__.__name__, self.name, self.github) + return f"{self.__class__.__name__} (name={self.name}, repository={self.repository})" def can_be_installed(self): return not self.installed and self.url_download diff --git a/bauh/gems/appimage/query.py b/bauh/gems/appimage/query.py index 6c39c557..b641b338 100644 --- a/bauh/gems/appimage/query.py +++ b/bauh/gems/appimage/query.py @@ -1,10 +1,12 @@ -APP_ATTRS = ('name', 'description', 'github', 'source', 'version', 'url_download', 'url_icon', 'url_screenshot', 'license', 'author', 'categories') +APP_ATTRS = ('name', 'description', 'repository', 'source', 'version', 'url_download', 'url_icon', + 'url_screenshot', 'license', 'author', 'categories') RELEASE_ATTRS = ('version', 'url_download', 'published_at') -SEARCH_APPS_BY_NAME_OR_DESCRIPTION = "SELECT {} FROM apps".format(','.join(APP_ATTRS)) + " WHERE lower(name) LIKE '%{}%' or lower(description) LIKE '%{}%'" -FIND_APP_ID_BY_NAME_AND_GITHUB = "SELECT id FROM apps WHERE lower(name) = '{}' and lower(github) = '{}'" -FIND_APPS_BY_NAME = "SELECT name, github, version, url_download FROM apps WHERE lower(name) IN ({})" +SEARCH_APPS_BY_NAME_OR_DESCRIPTION = f"SELECT {','.join(APP_ATTRS)} FROM apps" + \ + " WHERE lower(name) LIKE '%{}%' or lower(description) LIKE '%{}%'" +FIND_APP_ID_BY_REPO_AND_NAME = "SELECT id FROM apps WHERE lower(repository) = '{}' and lower(name) = '{}'" +FIND_APPS_BY_NAME = "SELECT name, repository, version, url_download FROM apps WHERE lower(name) IN ({})" FIND_APPS_BY_NAME_ONLY_NAME = "SELECT name FROM apps WHERE lower(name) IN ({})" FIND_APPS_BY_NAME_FULL = "SELECT {} FROM apps".format(','.join(APP_ATTRS)) + " WHERE lower(name) IN ({})" FIND_RELEASES_BY_APP_ID = "SELECT {} FROM releases".format(','.join(RELEASE_ATTRS)) + " WHERE app_id = {}" diff --git a/bauh/gems/appimage/resources/locale/ca b/bauh/gems/appimage/resources/locale/ca index 49bc7487..985f8761 100644 --- a/bauh/gems/appimage/resources/locale/ca +++ b/bauh/gems/appimage/resources/locale/ca @@ -33,6 +33,7 @@ appimage.info.icon_path=icona appimage.info.imported.false=No appimage.info.imported.true=Yes appimage.info.install_dir=Installation directory +appimage.info.repository=Repositori appimage.info.symlink=Symlink appimage.info.url_download=URL del fitxer appimage.install.appimagelauncher.error={appimgl} no permet la instal·lació de {app}. Desinstal·leu {appimgl}, reinicieu el sistema i torneu a provar d’instal·lar {app}. diff --git a/bauh/gems/appimage/resources/locale/de b/bauh/gems/appimage/resources/locale/de index 631ab3e9..06bd926d 100644 --- a/bauh/gems/appimage/resources/locale/de +++ b/bauh/gems/appimage/resources/locale/de @@ -33,6 +33,7 @@ appimage.info.icon_path=Symbol appimage.info.imported.false=Nein appimage.info.imported.true=Ja appimage.info.install_dir=Installationsverzeichnis +appimage.info.repository=Repository appimage.info.symlink=Symlink appimage.info.url_download=Datei-URL appimage.install.appimagelauncher.error={appimgl} lässt nicht zu, dass {app} installiert wird. Deinstallieren Sie {appimgl}, starten Sie Ihr System neu und versuchen Sie erneut, {app} zu installieren. diff --git a/bauh/gems/appimage/resources/locale/en b/bauh/gems/appimage/resources/locale/en index 487426a9..70d8659e 100644 --- a/bauh/gems/appimage/resources/locale/en +++ b/bauh/gems/appimage/resources/locale/en @@ -33,6 +33,7 @@ appimage.info.icon_path=icon appimage.info.imported.false=No appimage.info.imported.true=Yes appimage.info.install_dir=Installation directory +appimage.info.repository=Repository appimage.info.symlink=Symlink appimage.info.url_download=File URL appimage.install.appimagelauncher.error={appimgl} is not allowing {app} to be installed. Uninstall {appimgl}, reboot your system and try to install {app} again. diff --git a/bauh/gems/appimage/resources/locale/es b/bauh/gems/appimage/resources/locale/es index e98a0ccb..af174b9d 100644 --- a/bauh/gems/appimage/resources/locale/es +++ b/bauh/gems/appimage/resources/locale/es @@ -33,6 +33,7 @@ appimage.info.icon_path=icono appimage.info.imported.false=No appimage.info.imported.true=Sí appimage.info.install_dir=Directorio de instalación +appimage.info.repository=Repositorio appimage.info.symlink=Link simbólico appimage.info.url_download=URL del archivo appimage.install.appimagelauncher.error={appimgl} no permite la instalación de {app}. Desinstale {appimgl}, reinicie su sistema e intente instalar {app} nuevamente. diff --git a/bauh/gems/appimage/resources/locale/fr b/bauh/gems/appimage/resources/locale/fr index 996bf8f9..4aa27544 100644 --- a/bauh/gems/appimage/resources/locale/fr +++ b/bauh/gems/appimage/resources/locale/fr @@ -33,6 +33,7 @@ appimage.info.icon_path=icône appimage.info.imported.false=Non appimage.info.imported.true=Oui appimage.info.install_dir=Répertoire d'installation +appimage.info.repository=Dépôt appimage.info.symlink=Symlink appimage.info.url_download=URL du fichier appimage.install.appimagelauncher.error={appimgl} n'autorise pas {app} à être installé. Désinstallez {appimgl}, redemarrez, puis essayez d'installer {app} de nouveau. diff --git a/bauh/gems/appimage/resources/locale/it b/bauh/gems/appimage/resources/locale/it index 9ce0ce39..60aad6d4 100644 --- a/bauh/gems/appimage/resources/locale/it +++ b/bauh/gems/appimage/resources/locale/it @@ -33,6 +33,7 @@ appimage.info.icon_path=icona appimage.info.imported.false=No appimage.info.imported.true=Yes appimage.info.install_dir=Installation directory +appimage.info.repository=Deposito appimage.info.symlink=Symlink appimage.info.url_download=File URL appimage.install.appimagelauncher.error={appimgl} non consente l'installazione di {app}. Disinstallare {appimgl}, riavviare il sistema e provare a installare nuovamente {app}. diff --git a/bauh/gems/appimage/resources/locale/pt b/bauh/gems/appimage/resources/locale/pt index 572d8d05..130214b4 100644 --- a/bauh/gems/appimage/resources/locale/pt +++ b/bauh/gems/appimage/resources/locale/pt @@ -33,6 +33,7 @@ appimage.info.icon_path=ícone appimage.info.imported.false=Não appimage.info.imported.true=Sim appimage.info.install_dir=Diretório de instalação +appimage.info.repository=Repositório appimage.info.symlink=Link simbólico appimage.info.url_download=URL do arquivo appimage.install.appimagelauncher.error={appimgl} não está permitindo que o {app} seja instalado. Desinstale o {appimgl}, reinicie o sistema e tente instalar o {app} novamente. diff --git a/bauh/gems/appimage/resources/locale/ru b/bauh/gems/appimage/resources/locale/ru index c48754fb..44e76aed 100644 --- a/bauh/gems/appimage/resources/locale/ru +++ b/bauh/gems/appimage/resources/locale/ru @@ -33,6 +33,7 @@ appimage.info.icon_path=Значок appimage.info.imported.false=Нет appimage.info.imported.true=Да appimage.info.install_dir=Директория установки +appimage.info.repository=Pепозиторий appimage.info.symlink=Символическая ссылка appimage.info.url_download=URL Файла appimage.install.appimagelauncher.error={appimgl} не позволяет установить {app} . Удалите {appimgl}, перезагрузите ваш компьютер и попробуйте снова установить {app}. diff --git a/bauh/gems/appimage/resources/locale/tr b/bauh/gems/appimage/resources/locale/tr index a2b83e0f..f174a19c 100644 --- a/bauh/gems/appimage/resources/locale/tr +++ b/bauh/gems/appimage/resources/locale/tr @@ -33,6 +33,7 @@ appimage.info.icon_path=simge appimage.info.imported.false=Hayır appimage.info.imported.true=Evet appimage.info.install_dir=Kurulum dizini +appimage.info.repository=Depo appimage.info.symlink=Symlink appimage.info.url_download=Dosya Bağlantısı appimage.install.appimagelauncher.error={appimgl}, {app} uygulamasının yüklenmesine izin vermiyor. {appimgl} yazılımını kaldırın, sisteminizi yeniden başlatın ve {app} yazılımını tekrar yüklemeyi deneyin.