mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 01:14:15 +02:00
[improvements][appimage] AppImage updater daemon replaced by a default Python thread to reduce memory usage
This commit is contained in:
@@ -4,10 +4,12 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
## [0.7.3]
|
## [0.7.3] 2019-
|
||||||
### Improvements
|
### Improvements
|
||||||
- Not breaking the application when a i18n (translation) key was not found
|
- Not breaking the application when a i18n (translation) key was not found
|
||||||
- Adding all english (**en**) i18n keys to help people with the application translation
|
- Adding all english (**en**) i18n keys to help people with the application translation
|
||||||
|
- AppImage:
|
||||||
|
- AppImage updater daemon replaced by a default Python thread to reduce memory usage
|
||||||
|
|
||||||
## [0.7.2] 2019-11-01
|
## [0.7.2] 2019-11-01
|
||||||
### Improvements
|
### Improvements
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ will be pre-downloaded faster ( it does **NOT** modify your **pacman** settings
|
|||||||
- Installed applications are store at **~/.local/share/bauh/appimage/installed**
|
- Installed applications are store at **~/.local/share/bauh/appimage/installed**
|
||||||
- Desktop entries ( menu shortcuts ) of the installed applications are stored at **~/.local/share/applications**
|
- Desktop entries ( menu shortcuts ) of the installed applications are stored at **~/.local/share/applications**
|
||||||
- Downloaded database files are stored at **~/.local/share/bauh/appimage** as **apps.db** and **releases.db**
|
- Downloaded database files are stored at **~/.local/share/bauh/appimage** as **apps.db** and **releases.db**
|
||||||
- Databases updater daemon running every 20 minutes. It can be disabled via the environment variable **BAUH_APPIMAGE_DB_UPDATER=0**.
|
- Databases updater daemon running every 20 minutes ( the interval in SECONDS can be changed with the environment variable **BAUH_APPIMAGE_DB_UPDATER_TIME** ). It can be disabled via the environment variable **BAUH_APPIMAGE_DB_UPDATER=0**.
|
||||||
- All supported application names can be found at: https://github.com/vinifmor/bauh-files/blob/master/appimage/apps.txt
|
- All supported application names can be found at: https://github.com/vinifmor/bauh-files/blob/master/appimage/apps.txt
|
||||||
|
|
||||||
Obs: There are some crashes when **AppImageLauncher** is installed. It is advisable to uninstall it and reboot the system before trying to install an AppImage application.
|
Obs: There are some crashes when **AppImageLauncher** is installed. It is advisable to uninstall it and reboot the system before trying to install an AppImage application.
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import subprocess
|
|||||||
import traceback
|
import traceback
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from threading import Lock
|
||||||
from typing import Set, Type, List
|
from typing import Set, Type, List
|
||||||
|
|
||||||
from bauh.api.abstract.context import ApplicationContext
|
from bauh.api.abstract.context import ApplicationContext
|
||||||
@@ -18,7 +19,7 @@ from bauh.api.abstract.view import MessageType
|
|||||||
from bauh.api.constants import HOME_PATH
|
from bauh.api.constants import HOME_PATH
|
||||||
from bauh.commons.html import bold
|
from bauh.commons.html import bold
|
||||||
from bauh.commons.system import SystemProcess, new_subprocess, ProcessHandler, run_cmd, SimpleProcess
|
from bauh.commons.system import SystemProcess, new_subprocess, ProcessHandler, run_cmd, SimpleProcess
|
||||||
from bauh.gems.appimage import query, INSTALLATION_PATH, suggestions, db
|
from bauh.gems.appimage import query, INSTALLATION_PATH, suggestions
|
||||||
from bauh.gems.appimage.model import AppImage
|
from bauh.gems.appimage.model import AppImage
|
||||||
from bauh.gems.appimage.worker import DatabaseUpdater
|
from bauh.gems.appimage.worker import DatabaseUpdater
|
||||||
|
|
||||||
@@ -43,18 +44,19 @@ class AppImageManager(SoftwareManager):
|
|||||||
self.http_client = context.http_client
|
self.http_client = context.http_client
|
||||||
self.logger = context.logger
|
self.logger = context.logger
|
||||||
self.file_downloader = context.file_downloader
|
self.file_downloader = context.file_downloader
|
||||||
self.dbs_updater = DatabaseUpdater(http_client=context.http_client, logger=context.logger)
|
self.db_locks = {DB_APPS_PATH: Lock(), DB_RELEASES_PATH: Lock()}
|
||||||
|
self.dbs_updater = DatabaseUpdater(http_client=context.http_client, logger=context.logger, db_locks=self.db_locks)
|
||||||
|
|
||||||
def _get_db_connection(self, db_path: str) -> sqlite3.Connection:
|
def _get_db_connection(self, db_path: str) -> sqlite3.Connection:
|
||||||
if os.path.exists(db_path):
|
if os.path.exists(db_path):
|
||||||
db.acquire_lock(db_path)
|
self.db_locks[db_path].acquire()
|
||||||
return sqlite3.connect(db_path)
|
return sqlite3.connect(db_path)
|
||||||
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 _close_connection(self, db_path: str, con: sqlite3.Connection):
|
def _close_connection(self, db_path: str, con: sqlite3.Connection):
|
||||||
con.close()
|
con.close()
|
||||||
db.release_lock(db_path)
|
self.db_locks[db_path].release()
|
||||||
|
|
||||||
def _gen_app_key(self, app: AppImage):
|
def _gen_app_key(self, app: AppImage):
|
||||||
return '{}{}'.format(app.name.lower(), app.github.lower() if app.github else '')
|
return '{}{}'.format(app.name.lower(), app.github.lower() if app.github else '')
|
||||||
@@ -380,9 +382,6 @@ class AppImageManager(SoftwareManager):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
for path in (DB_APPS_PATH, DB_RELEASES_PATH):
|
|
||||||
db.release_lock(path)
|
|
||||||
|
|
||||||
self.dbs_updater.start()
|
self.dbs_updater.start()
|
||||||
|
|
||||||
def list_updates(self, internet_available: bool) -> List[PackageUpdate]:
|
def list_updates(self, internet_available: bool) -> List[PackageUpdate]:
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
import os
|
|
||||||
import time
|
|
||||||
|
|
||||||
|
|
||||||
def acquire_lock(db_path: str):
|
|
||||||
lock_path = db_path + '.lock'
|
|
||||||
while True:
|
|
||||||
if not os.path.exists(lock_path):
|
|
||||||
open(lock_path, 'a').close()
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
time.sleep(0.0001)
|
|
||||||
|
|
||||||
|
|
||||||
def release_lock(db_path: str):
|
|
||||||
lock_path = db_path + '.lock'
|
|
||||||
if os.path.exists(lock_path):
|
|
||||||
os.remove(lock_path)
|
|
||||||
@@ -4,27 +4,27 @@ import os
|
|||||||
import tarfile
|
import tarfile
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from multiprocessing import Process
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from bauh.api.http import HttpClient
|
from bauh.api.http import HttpClient
|
||||||
from bauh.gems.appimage import LOCAL_PATH, db
|
from bauh.gems.appimage import LOCAL_PATH
|
||||||
|
|
||||||
|
|
||||||
class DatabaseUpdater(Thread if bool(int(os.getenv('BAUH_DEBUG', 0))) else Process):
|
class DatabaseUpdater(Thread):
|
||||||
|
|
||||||
URL_DB = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/appimage/dbs.tar.gz'
|
URL_DB = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/appimage/dbs.tar.gz'
|
||||||
COMPRESS_FILE_PATH = LOCAL_PATH + '/db.tar.gz'
|
COMPRESS_FILE_PATH = LOCAL_PATH + '/db.tar.gz'
|
||||||
|
|
||||||
def __init__(self, http_client: HttpClient, logger: logging.Logger):
|
def __init__(self, http_client: HttpClient, logger: logging.Logger, db_locks: dict):
|
||||||
super(DatabaseUpdater, self).__init__(daemon=True)
|
super(DatabaseUpdater, self).__init__(daemon=True)
|
||||||
self.http_client = http_client
|
self.http_client = http_client
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
self.enabled = bool(int(os.getenv('BAUH_APPIMAGE_DB_UPDATER', 1)))
|
self.enabled = bool(int(os.getenv('BAUH_APPIMAGE_DB_UPDATER', 1)))
|
||||||
self.sleep = 60 * 20
|
self.db_locks = db_locks
|
||||||
|
self.sleep = int(os.getenv('BAUH_APPIMAGE_DB_UPDATER_TIME', 60 * 20))
|
||||||
|
|
||||||
def _download_databases(self):
|
def _download_databases(self):
|
||||||
self.logger.info('Retrieving AppImage databases')
|
self.logger.info('Retrieving AppImage databases')
|
||||||
@@ -44,9 +44,11 @@ class DatabaseUpdater(Thread if bool(int(os.getenv('BAUH_DEBUG', 0))) else Proce
|
|||||||
if old_db_files:
|
if old_db_files:
|
||||||
self.logger.info('Deleting old database files')
|
self.logger.info('Deleting old database files')
|
||||||
for f in old_db_files:
|
for f in old_db_files:
|
||||||
db.acquire_lock(f)
|
self.db_locks[f].acquire()
|
||||||
os.remove(f)
|
try:
|
||||||
db.release_lock(f)
|
os.remove(f)
|
||||||
|
finally:
|
||||||
|
self.db_locks[f].release()
|
||||||
|
|
||||||
self.logger.info('Old database files deleted')
|
self.logger.info('Old database files deleted')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user