mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-06 22:54:16 +02:00
[appimage][feature] downloading db files from github
This commit is contained in:
@@ -7,7 +7,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
## [0.7.0]
|
||||
### Features
|
||||
- AppImage support ( see below )
|
||||
- "Screenshots" button
|
||||
- **Screenshots** button
|
||||
- **Categories** filter
|
||||
|
||||
### Improvements
|
||||
- Flatpak:
|
||||
|
||||
@@ -19,6 +19,7 @@ from bauh.commons.html import bold
|
||||
from bauh.commons.system import SystemProcess, new_subprocess, ProcessHandler, run_cmd
|
||||
from bauh.gems.appimage import query, INSTALLATION_PATH
|
||||
from bauh.gems.appimage.model import AppImage
|
||||
from bauh.gems.appimage.worker import DatabaseUpdater
|
||||
|
||||
DB_APPS_PATH = '{}/{}'.format(HOME_PATH, '.local/share/bauh/appimage/apps.db')
|
||||
DB_RELEASES_PATH = '{}/{}'.format(HOME_PATH, '.local/share/bauh/appimage/releases.db')
|
||||
@@ -41,6 +42,7 @@ class AppImageManager(SoftwareManager):
|
||||
self.http_client = context.http_client
|
||||
self.logger = context.logger
|
||||
self.file_downloader = context.file_downloader
|
||||
self.dbs_updater = DatabaseUpdater(http_client=context.http_client, logger=context.logger)
|
||||
|
||||
def _get_db_connection(self, db_path: str) -> sqlite3.Connection:
|
||||
if os.path.exists(db_path):
|
||||
@@ -335,8 +337,7 @@ class AppImageManager(SoftwareManager):
|
||||
return False
|
||||
|
||||
def prepare(self):
|
||||
# TODO
|
||||
pass
|
||||
self.dbs_updater.start()
|
||||
|
||||
def list_updates(self, internet_available: bool) -> List[PackageUpdate]:
|
||||
# TODO
|
||||
|
||||
52
bauh/gems/appimage/worker.py
Normal file
52
bauh/gems/appimage/worker.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
from multiprocessing import Process
|
||||
from threading import Thread
|
||||
|
||||
from bauh.api.http import HttpClient
|
||||
|
||||
|
||||
class DatabaseUpdater(Thread if bool(int(os.getenv('BAUH_DEBUG', 0))) else Process):
|
||||
|
||||
URL_APPS = 'https://github.com/vinifmor/bauh-files/blob/master/appimage/apps.db?raw=true'
|
||||
URL_RELEASES = 'https://github.com/vinifmor/bauh-files/blob/master/appimage/releases.db?raw=true'
|
||||
APPS_PATH = '{}/.local/share/bauh/appimage/apps.db'
|
||||
RELEASES_PATH = '{}/.local/share/bauh/appimage/releases.db'
|
||||
|
||||
def __init__(self, http_client: HttpClient, logger: logging.Logger):
|
||||
super(DatabaseUpdater, self).__init__(daemon=True)
|
||||
self.http_client = http_client
|
||||
self.logger = logger
|
||||
self.enabled = bool(int(os.getenv('BAUH_APPIMAGE_DB_UPDATER', 1)))
|
||||
self.sleep = 60 * 20
|
||||
|
||||
def _download_file(self, url: str, output: str):
|
||||
res = self.http_client.get(url, headers={'Authorization': 'token {}'.format(os.getenv('GITHUB_TOKEN'))})
|
||||
|
||||
if res:
|
||||
with open(output, 'wb+') as f:
|
||||
f.write(res.content)
|
||||
|
||||
self.logger.info("Database file saved at {}".format(output))
|
||||
else:
|
||||
self.logger.warning('Could not download a database file from {}'.format(url))
|
||||
|
||||
def run(self):
|
||||
if self.enabled:
|
||||
while True:
|
||||
self.logger.info('Retrieving AppImage databases')
|
||||
|
||||
threads = [Thread(target=self._download_file, args=(self.URL_APPS, self.APPS_PATH)),
|
||||
Thread(target=self._download_file, args=(self.URL_RELEASES, self.RELEASES_PATH))]
|
||||
|
||||
for t in threads:
|
||||
t.start()
|
||||
|
||||
for t in threads:
|
||||
t.join()
|
||||
|
||||
self.logger.info('Sleeping')
|
||||
time.sleep(self.sleep)
|
||||
else:
|
||||
self.logger.warning('Disabled')
|
||||
Reference in New Issue
Block a user