diff --git a/bauh/gems/appimage/controller.py b/bauh/gems/appimage/controller.py index fc63238b..9629bc6f 100644 --- a/bauh/gems/appimage/controller.py +++ b/bauh/gems/appimage/controller.py @@ -48,6 +48,9 @@ class AppImageManager(SoftwareManager): else: self.logger.warning("Could not get a database connection. File '{}' not found".format(db_path)) + def _gen_app_key(self, app: AppImage): + return '{}{}'.format(app.name.lower(), app.github.lower() if app.github else '') + def search(self, words: str, disk_loader: DiskCacheLoader, limit: int = -1) -> SearchResult: res = SearchResult([], [], 0) connection = self._get_db_connection(DB_APPS_PATH) @@ -62,7 +65,7 @@ class AppImageManager(SoftwareManager): for l in cursor.fetchall(): app = AppImage(*l) res.new.append(app) - found_map['{}_{}'.format(app.name.lower(), app.github.lower())] = {'app': app, 'idx': idx} + found_map[self._gen_app_key(app)] = {'app': app, 'idx': idx} idx += 1 if res.new: @@ -70,7 +73,7 @@ class AppImageManager(SoftwareManager): if installed: for iapp in installed: - key = '{}_{}'.format(iapp.name.lower(), iapp.github.lower()) + key = self._gen_app_key(iapp) new_found = found_map.get(key) @@ -93,7 +96,7 @@ class AppImageManager(SoftwareManager): installed = run_cmd('ls {}*/data.json'.format(INSTALLATION_PATH), print_error=False) if installed: - names, githubs = set(), set() + names = set() for path in installed.split('\n'): if path: with open(path) as f: @@ -102,7 +105,6 @@ class AppImageManager(SoftwareManager): res.installed.append(app) names.add("'{}'".format(app.name.lower())) - githubs.add("'{}'".format(app.github.lower())) if res.installed: con = self._get_db_connection(DB_APPS_PATH) @@ -110,11 +112,11 @@ class AppImageManager(SoftwareManager): if con: try: cursor = con.cursor() - cursor.execute(query.FIND_APPS_LATEST_VERSIONS.format(','.join(names), ','.join(githubs))) + cursor.execute(query.FIND_APPS_LATEST_VERSIONS.format(','.join(names))) for tup in cursor.fetchall(): for app in res.installed: - if app.name.lower() == tup[0].lower() and app.github.lower() == tup[1].lower(): + if app.name.lower() == tup[0].lower() and (not app.github or app.github.lower() == tup[1].lower()): app.update = tup[2] > app.version if app.update: @@ -150,6 +152,7 @@ class AppImageManager(SoftwareManager): if self.uninstall(pkg, root_password, watcher): old_release = versions.history[versions.pkg_status_idx + 1] pkg.version = old_release['0_version'] + pkg.latest_version = pkg.version pkg.url_download = old_release['2_url_download'] if self.install(pkg, root_password, watcher): self.cache_to_disk(pkg, None, False) @@ -217,7 +220,7 @@ class AppImageManager(SoftwareManager): if connection: cursor = connection.cursor() - cursor.execute(query.FIND_APP_ID_BY_NAME_AND_GITHUB.format(pkg.name.lower(), pkg.github.lower())) + cursor.execute(query.FIND_APP_ID_BY_NAME_AND_GITHUB.format(pkg.name.lower(), pkg.github.lower() if pkg.github else '')) app_tuple = cursor.fetchone() if not app_tuple: @@ -232,7 +235,7 @@ class AppImageManager(SoftwareManager): if releases: for idx, tup in enumerate(releases): - history.append({'0_version': tup[0], '1_published_at': datetime.strptime(tup[2], '%Y-%m-%dT%H:%M:%SZ'), '2_url_download': tup[1]}) + history.append({'0_version': tup[0], '1_published_at': datetime.strptime(tup[2], '%Y-%m-%dT%H:%M:%SZ') if tup[2] else '', '2_url_download': tup[1]}) if res.pkg_status_idx == -1 and pkg.version == tup[0]: res.pkg_status_idx = idx diff --git a/bauh/gems/appimage/query.py b/bauh/gems/appimage/query.py index abe720c5..40e624b7 100644 --- a/bauh/gems/appimage/query.py +++ b/bauh/gems/appimage/query.py @@ -4,5 +4,5 @@ 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_LATEST_VERSIONS = "SELECT name, github, version, url_download FROM apps WHERE lower(name) IN ({}) AND lower(github) in ({})" +FIND_APPS_LATEST_VERSIONS = "SELECT name, github, version, url_download FROM apps WHERE lower(name) IN ({})" FIND_RELEASES_BY_APP_ID = "SELECT {} FROM releases".format(','.join(RELEASE_ATTRS)) + " WHERE app_id = {} ORDER BY version desc" diff --git a/bauh/view/core/downloader.py b/bauh/view/core/downloader.py index 8ebcac02..1e9da8a7 100644 --- a/bauh/view/core/downloader.py +++ b/bauh/view/core/downloader.py @@ -84,7 +84,7 @@ class AdaptableFileDownloader(FileDownloader): downloader = 'wget' file_size = self.http_client.get_content_length(file_url) - msg = bold('[{}] ').format(downloader) + self.i18n['downloading'] + ' ' + bold(file_url.split('/')[-1]) + (' ' + file_size if file_size else '') + msg = bold('[{}] ').format(downloader) + self.i18n['downloading'] + ' ' + bold(file_url.split('/')[-1]) + (' ( {} )'.format(file_size) if file_size else '') watcher.change_substatus(msg) success = handler.handle(process) except: