mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 12:04:16 +02:00
improving the gems panel selector
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import glob
|
||||
import logging
|
||||
import os
|
||||
import tarfile
|
||||
@@ -8,13 +9,13 @@ from pathlib import Path
|
||||
from threading import Thread
|
||||
|
||||
from bauh.api.http import HttpClient
|
||||
from bauh.gems.appimage import BASE_PATH
|
||||
from bauh.gems.appimage import LOCAL_PATH
|
||||
|
||||
|
||||
class DatabaseUpdater(Thread if bool(int(os.getenv('BAUH_DEBUG', 0))) else Process):
|
||||
|
||||
URL_DB = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/appimage/dbs.tar.gz'
|
||||
COMPRESS_FILE_PATH = BASE_PATH + '/db.tar.gz'
|
||||
COMPRESS_FILE_PATH = LOCAL_PATH + '/db.tar.gz'
|
||||
|
||||
def __init__(self, http_client: HttpClient, logger: logging.Logger):
|
||||
super(DatabaseUpdater, self).__init__(daemon=True)
|
||||
@@ -29,26 +30,26 @@ class DatabaseUpdater(Thread if bool(int(os.getenv('BAUH_DEBUG', 0))) else Proce
|
||||
res = self.http_client.get(self.URL_DB, headers={'Authorization': 'token {}'.format(os.getenv('GITHUB_TOKEN'))})
|
||||
|
||||
if res:
|
||||
Path(BASE_PATH).mkdir(parents=True, exist_ok=True)
|
||||
Path(LOCAL_PATH).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with open(self.COMPRESS_FILE_PATH, 'wb+') as f:
|
||||
f.write(res.content)
|
||||
|
||||
self.logger.info("Database file saved at {}".format(self.COMPRESS_FILE_PATH))
|
||||
|
||||
old_db_files = {file for r, d, f in os.walk(BASE_PATH) for file in f if file.endswith('.db')}
|
||||
old_db_files = glob.glob(LOCAL_PATH + '/*.db')
|
||||
|
||||
if old_db_files:
|
||||
self.logger.info('Deleting old database files')
|
||||
for f in old_db_files:
|
||||
os.remove('{}/{}'.format(BASE_PATH, f))
|
||||
os.remove(f)
|
||||
self.logger.info('Old database files deleted')
|
||||
|
||||
self.logger.info('Uncompressing {}'.format(self.COMPRESS_FILE_PATH))
|
||||
|
||||
try:
|
||||
tf = tarfile.open(self.COMPRESS_FILE_PATH)
|
||||
tf.extractall(BASE_PATH)
|
||||
tf.extractall(LOCAL_PATH)
|
||||
self.logger.info('Successfully uncompressed file {}'.format(self.COMPRESS_FILE_PATH))
|
||||
except:
|
||||
self.logger.error('Could not extract file {}'.format(self.COMPRESS_FILE_PATH))
|
||||
|
||||
Reference in New Issue
Block a user