mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 01:14:15 +02:00
appimages -> support apps with no github set
This commit is contained in:
@@ -48,6 +48,9 @@ class AppImageManager(SoftwareManager):
|
|||||||
else:
|
else:
|
||||||
self.logger.warning("Could not get a database connection. File '{}' not found".format(db_path))
|
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:
|
def search(self, words: str, disk_loader: DiskCacheLoader, limit: int = -1) -> SearchResult:
|
||||||
res = SearchResult([], [], 0)
|
res = SearchResult([], [], 0)
|
||||||
connection = self._get_db_connection(DB_APPS_PATH)
|
connection = self._get_db_connection(DB_APPS_PATH)
|
||||||
@@ -62,7 +65,7 @@ class AppImageManager(SoftwareManager):
|
|||||||
for l in cursor.fetchall():
|
for l in cursor.fetchall():
|
||||||
app = AppImage(*l)
|
app = AppImage(*l)
|
||||||
res.new.append(app)
|
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
|
idx += 1
|
||||||
|
|
||||||
if res.new:
|
if res.new:
|
||||||
@@ -70,7 +73,7 @@ class AppImageManager(SoftwareManager):
|
|||||||
|
|
||||||
if installed:
|
if installed:
|
||||||
for iapp in 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)
|
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)
|
installed = run_cmd('ls {}*/data.json'.format(INSTALLATION_PATH), print_error=False)
|
||||||
|
|
||||||
if installed:
|
if installed:
|
||||||
names, githubs = set(), set()
|
names = set()
|
||||||
for path in installed.split('\n'):
|
for path in installed.split('\n'):
|
||||||
if path:
|
if path:
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
@@ -102,7 +105,6 @@ class AppImageManager(SoftwareManager):
|
|||||||
|
|
||||||
res.installed.append(app)
|
res.installed.append(app)
|
||||||
names.add("'{}'".format(app.name.lower()))
|
names.add("'{}'".format(app.name.lower()))
|
||||||
githubs.add("'{}'".format(app.github.lower()))
|
|
||||||
|
|
||||||
if res.installed:
|
if res.installed:
|
||||||
con = self._get_db_connection(DB_APPS_PATH)
|
con = self._get_db_connection(DB_APPS_PATH)
|
||||||
@@ -110,11 +112,11 @@ class AppImageManager(SoftwareManager):
|
|||||||
if con:
|
if con:
|
||||||
try:
|
try:
|
||||||
cursor = con.cursor()
|
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 tup in cursor.fetchall():
|
||||||
for app in res.installed:
|
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
|
app.update = tup[2] > app.version
|
||||||
|
|
||||||
if app.update:
|
if app.update:
|
||||||
@@ -150,6 +152,7 @@ class AppImageManager(SoftwareManager):
|
|||||||
if self.uninstall(pkg, root_password, watcher):
|
if self.uninstall(pkg, root_password, watcher):
|
||||||
old_release = versions.history[versions.pkg_status_idx + 1]
|
old_release = versions.history[versions.pkg_status_idx + 1]
|
||||||
pkg.version = old_release['0_version']
|
pkg.version = old_release['0_version']
|
||||||
|
pkg.latest_version = pkg.version
|
||||||
pkg.url_download = old_release['2_url_download']
|
pkg.url_download = old_release['2_url_download']
|
||||||
if self.install(pkg, root_password, watcher):
|
if self.install(pkg, root_password, watcher):
|
||||||
self.cache_to_disk(pkg, None, False)
|
self.cache_to_disk(pkg, None, False)
|
||||||
@@ -217,7 +220,7 @@ class AppImageManager(SoftwareManager):
|
|||||||
if connection:
|
if connection:
|
||||||
cursor = connection.cursor()
|
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()
|
app_tuple = cursor.fetchone()
|
||||||
|
|
||||||
if not app_tuple:
|
if not app_tuple:
|
||||||
@@ -232,7 +235,7 @@ class AppImageManager(SoftwareManager):
|
|||||||
|
|
||||||
if releases:
|
if releases:
|
||||||
for idx, tup in enumerate(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]:
|
if res.pkg_status_idx == -1 and pkg.version == tup[0]:
|
||||||
res.pkg_status_idx = idx
|
res.pkg_status_idx = idx
|
||||||
|
|||||||
@@ -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 '%{}%'"
|
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_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"
|
FIND_RELEASES_BY_APP_ID = "SELECT {} FROM releases".format(','.join(RELEASE_ATTRS)) + " WHERE app_id = {} ORDER BY version desc"
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class AdaptableFileDownloader(FileDownloader):
|
|||||||
downloader = 'wget'
|
downloader = 'wget'
|
||||||
|
|
||||||
file_size = self.http_client.get_content_length(file_url)
|
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)
|
watcher.change_substatus(msg)
|
||||||
success = handler.handle(process)
|
success = handler.handle(process)
|
||||||
except:
|
except:
|
||||||
|
|||||||
Reference in New Issue
Block a user