[api] refactoring: caching directory for root user is now /var/cache/bauh

This commit is contained in:
Vinicius Moreira
2021-11-24 10:34:04 -03:00
parent f78498c1ec
commit aa889dcd51
18 changed files with 49 additions and 42 deletions

View File

@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [0.9.22] ## [0.9.22]
### Improvements ### Improvements
- General
- directory paths changed for a root user using bauh:
- caching: `/var/cache/bauh`
- UI - UI
- settings panel: - settings panel:
- always displaying all supported packaging technologies - always displaying all supported packaging technologies
@@ -13,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
<p align="center"> <p align="center">
<img src="https://raw.githubusercontent.com/vinifmor/bauh-files/master/pictures/releases/0.9.22/missing_type_dep.png"> <img src="https://raw.githubusercontent.com/vinifmor/bauh-files/master/pictures/releases/0.9.22/missing_type_dep.png">
</p> </p>
### Fixes ### Fixes
- Arch - Arch

View File

@@ -29,7 +29,7 @@ Key features
- [Snap](#type_snap) - [Snap](#type_snap)
- [Native Web applications](#type_web) - [Native Web applications](#type_web)
7. [General settings](#settings) 7. [General settings](#settings)
8. [Cache and logs](#cache_logs) 8. [Directory structure, caching and logs](#dirs)
9. [Custom themes](#custom_themes) 9. [Custom themes](#custom_themes)
10. [Tray icons](#tray_icons) 10. [Tray icons](#tray_icons)
11. [CLI (Command Line Interface)](#cli) 11. [CLI (Command Line Interface)](#cli)
@@ -409,9 +409,9 @@ boot:
load_apps: true # if the installed applications or suggestions should be loaded on the management panel after the initialization process. Default: true. load_apps: true # if the installed applications or suggestions should be loaded on the management panel after the initialization process. Default: true.
``` ```
#### <a name="cache_logs">Cache and Logs</a> #### <a name="dirs">Directory structure, caching and logs</a>
- Installation logs and temporary files are saved at `/tmp/bauh` (or `/tmp/bauh_root` if you launch it as root) - `~/.cache/bauh` (or `/var/cache/bauh` for **root**): stores data about your installed applications, databases, indexes, etc. Files are stored here to provide a faster initialization and data recovery.
- Some data about your installed applications are stored in `~/.cache/bauh` to load them faster - `/tmp/bauh` (or `/tmp/bauh_root` for **root**): stores logging and temporary files (e.g: build dependencies)
#### <a name="custom_themes">Custom themes</a> #### <a name="custom_themes">Custom themes</a>

View File

@@ -146,7 +146,7 @@ class SoftwarePackage(ABC):
""" """
:return: base cache path for the specific app type :return: base cache path for the specific app type
""" """
return CACHE_PATH + '/' + self.get_type() return f'{CACHE_PATH}/{self.get_type()}'
def can_be_updated(self) -> bool: def can_be_updated(self) -> bool:
""" """

View File

@@ -1,8 +1,9 @@
from pathlib import Path from pathlib import Path
from bauh import __app_name__
from bauh.api import user from bauh.api import user
CACHE_PATH = '{}/.cache/bauh'.format(str(Path.home())) CACHE_PATH = f'/var/cache/{__app_name__}' if user.is_root() else f'{Path.home()}/.cache/{__app_name__}'
CONFIG_PATH = '{}/.config/bauh'.format(str(Path.home())) CONFIG_PATH = '{}/.config/bauh'.format(str(Path.home()))
USER_THEMES_PATH = '{}/.local/share/bauh/themes'.format(str(Path.home())) USER_THEMES_PATH = '{}/.local/share/bauh/themes'.format(str(Path.home()))
DESKTOP_ENTRIES_DIR = '{}/.local/share/applications'.format(str(Path.home())) DESKTOP_ENTRIES_DIR = '{}/.local/share/applications'.format(str(Path.home()))

View File

@@ -1,5 +1,6 @@
import os import os
from typing import Optional
def is_root(): def is_root(user_id: Optional[int] = None):
return os.getuid() == 0 return user_id == 0 if user_id is not None else os.getuid() == 0

View File

@@ -2,7 +2,7 @@ import os
from pathlib import Path from pathlib import Path
from typing import Optional from typing import Optional
from bauh.api.paths import CONFIG_PATH, CACHE_PATH, TEMP_DIR from bauh.api.paths import CONFIG_PATH, TEMP_DIR, CACHE_PATH
from bauh.commons import resource from bauh.commons import resource
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -14,13 +14,13 @@ CONFIG_DIR = '{}/appimage'.format(CONFIG_PATH)
UPDATES_IGNORED_FILE = '{}/updates_ignored.txt'.format(CONFIG_DIR) UPDATES_IGNORED_FILE = '{}/updates_ignored.txt'.format(CONFIG_DIR)
SYMLINKS_DIR = '{}/.local/bin'.format(str(Path.home())) SYMLINKS_DIR = '{}/.local/bin'.format(str(Path.home()))
URL_COMPRESSED_DATABASES = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/appimage/dbs.tar.gz' URL_COMPRESSED_DATABASES = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/appimage/dbs.tar.gz'
APPIMAGE_CACHE_PATH = '{}/appimage'.format(CACHE_PATH) APPIMAGE_CACHE_PATH = f'{CACHE_PATH}/appimage'
DATABASE_APPS_FILE = '{}/apps.db'.format(APPIMAGE_CACHE_PATH) DATABASE_APPS_FILE = f'{APPIMAGE_CACHE_PATH}/apps.db'
DATABASE_RELEASES_FILE = '{}/releases.db'.format(APPIMAGE_CACHE_PATH) DATABASE_RELEASES_FILE = f'{APPIMAGE_CACHE_PATH}/releases.db'
DATABASES_TS_FILE = '{}/dbs.ts'.format(APPIMAGE_CACHE_PATH) DATABASES_TS_FILE = f'{APPIMAGE_CACHE_PATH}/dbs.ts'
DESKTOP_ENTRIES_PATH = '{}/.local/share/applications'.format(str(Path.home())) DESKTOP_ENTRIES_PATH = '{}/.local/share/applications'.format(str(Path.home()))
SUGGESTIONS_CACHED_FILE = '{}/suggestions.txt'.format(APPIMAGE_CACHE_PATH) SUGGESTIONS_CACHED_FILE = f'{APPIMAGE_CACHE_PATH}/suggestions.txt'
SUGGESTIONS_CACHED_TS_FILE = '{}/suggestions.ts'.format(APPIMAGE_CACHE_PATH) SUGGESTIONS_CACHED_TS_FILE = f'{APPIMAGE_CACHE_PATH}/suggestions.ts'
DOWNLOAD_DIR = f'{TEMP_DIR}/appimage/download' DOWNLOAD_DIR = f'{TEMP_DIR}/appimage/download'

View File

@@ -722,7 +722,7 @@ class AppImageManager(SoftwareManager):
return updates return updates
def list_warnings(self, internet_available: bool) -> List[str]: def list_warnings(self, internet_available: bool) -> List[str]:
dbfiles = glob.glob('{}/*.db'.format(APPIMAGE_CACHE_PATH)) dbfiles = glob.glob(f'{APPIMAGE_CACHE_PATH}/*.db')
if not dbfiles or len({f for f in (DATABASE_APPS_FILE, DATABASE_RELEASES_FILE) if f in dbfiles}) != 2: if not dbfiles or len({f for f in (DATABASE_APPS_FILE, DATABASE_RELEASES_FILE) if f in dbfiles}) != 2:
return [self.i18n['appimage.warning.missing_db_files'].format(appimage=bold('AppImage'))] return [self.i18n['appimage.warning.missing_db_files'].format(appimage=bold('AppImage'))]

View File

@@ -24,7 +24,7 @@ from bauh.view.util.translation import I18n
class DatabaseUpdater(Thread): class DatabaseUpdater(Thread):
COMPRESS_FILE_PATH = '{}/db.tar.gz'.format(APPIMAGE_CACHE_PATH) COMPRESS_FILE_PATH = f'{APPIMAGE_CACHE_PATH}/db.tar.gz'
def __init__(self, i18n: I18n, http_client: HttpClient, logger: logging.Logger, taskman: TaskManager, def __init__(self, i18n: I18n, http_client: HttpClient, logger: logging.Logger, taskman: TaskManager,
watcher: Optional[ProcessWatcher] = None, appimage_config: Optional[dict] = None, create_config: Optional[CreateConfigFile] = None): watcher: Optional[ProcessWatcher] = None, appimage_config: Optional[dict] = None, create_config: Optional[CreateConfigFile] = None):
@@ -52,10 +52,10 @@ class DatabaseUpdater(Thread):
self.logger.info("No expiration time configured for the AppImage database") self.logger.info("No expiration time configured for the AppImage database")
return True return True
files = {*glob.glob('{}/*'.format(APPIMAGE_CACHE_PATH))} files = {*glob.glob(f'{APPIMAGE_CACHE_PATH}/*')}
if not files: if not files:
self.logger.warning('No database files on {}'.format(APPIMAGE_CACHE_PATH)) self.logger.warning(f'No database files on {APPIMAGE_CACHE_PATH}')
return True return True
if DATABASES_TS_FILE not in files: if DATABASES_TS_FILE not in files:
@@ -113,7 +113,7 @@ class DatabaseUpdater(Thread):
self.logger.info("Database file saved at {}".format(self.COMPRESS_FILE_PATH)) self.logger.info("Database file saved at {}".format(self.COMPRESS_FILE_PATH))
self._update_task_progress(50, self.i18n['appimage.update_database.deleting_old']) self._update_task_progress(50, self.i18n['appimage.update_database.deleting_old'])
old_db_files = glob.glob(APPIMAGE_CACHE_PATH + '/*.db') old_db_files = glob.glob(f'{APPIMAGE_CACHE_PATH}/*.db')
if old_db_files: if old_db_files:
self.logger.info('Deleting old database files') self.logger.info('Deleting old database files')

View File

@@ -1,19 +1,19 @@
import os import os
from pathlib import Path from pathlib import Path
from bauh.api.paths import CACHE_PATH, CONFIG_PATH, TEMP_DIR from bauh.api.paths import CONFIG_PATH, TEMP_DIR, CACHE_PATH
from bauh.commons import resource from bauh.commons import resource
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
BUILD_DIR = '{}/arch'.format(TEMP_DIR) BUILD_DIR = '{}/arch'.format(TEMP_DIR)
ARCH_CACHE_PATH = CACHE_PATH + '/arch' ARCH_CACHE_PATH = f'{CACHE_PATH}/arch'
CATEGORIES_FILE_PATH = ARCH_CACHE_PATH + '/categories.txt' CATEGORIES_FILE_PATH = f'{ARCH_CACHE_PATH}/categories.txt'
URL_CATEGORIES_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/arch/categories.txt' URL_CATEGORIES_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/arch/categories.txt'
URL_GPG_SERVERS = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/arch/gpgservers.txt' URL_GPG_SERVERS = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/arch/gpgservers.txt'
CONFIG_DIR = '{}/.config/bauh/arch'.format(str(Path.home())) CONFIG_DIR = '{}/.config/bauh/arch'.format(str(Path.home()))
CUSTOM_MAKEPKG_FILE = '{}/makepkg.conf'.format(CONFIG_DIR) CUSTOM_MAKEPKG_FILE = '{}/makepkg.conf'.format(CONFIG_DIR)
AUR_INDEX_FILE = '{}/aur/index.txt'.format(ARCH_CACHE_PATH) AUR_INDEX_FILE = f'{ARCH_CACHE_PATH}/aur/index.txt'
AUR_INDEX_TS_FILE = '{}/aur/index.ts'.format(ARCH_CACHE_PATH) AUR_INDEX_TS_FILE = f'{ARCH_CACHE_PATH}/aur/index.ts'
CONFIG_FILE = '{}/arch.yml'.format(CONFIG_PATH) CONFIG_FILE = '{}/arch.yml'.format(CONFIG_PATH)
SUGGESTIONS_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/arch/aur_suggestions.txt' SUGGESTIONS_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/arch/aur_suggestions.txt'
UPDATES_IGNORED_FILE = '{}/updates_ignored.txt'.format(CONFIG_DIR) UPDATES_IGNORED_FILE = '{}/updates_ignored.txt'.format(CONFIG_DIR)

View File

@@ -10,7 +10,7 @@ from typing import Optional
from bauh.api.paths import CACHE_PATH from bauh.api.paths import CACHE_PATH
from bauh.commons.system import ProcessHandler from bauh.commons.system import ProcessHandler
SYNC_FILE = '{}/arch/db_sync'.format(CACHE_PATH) SYNC_FILE = f'{CACHE_PATH}/arch/db_sync'
def should_sync(arch_config: dict, aur_supported: bool, handler: Optional[ProcessHandler], logger: logging.Logger): def should_sync(arch_config: dict, aur_supported: bool, handler: Optional[ProcessHandler], logger: logging.Logger):

View File

@@ -8,7 +8,7 @@ from pathlib import Path
from bauh.api.paths import CACHE_PATH from bauh.api.paths import CACHE_PATH
SYNC_FILE = '{}/arch/mirrors_sync'.format(CACHE_PATH) SYNC_FILE = f'{CACHE_PATH}/arch/mirrors_sync'
def should_sync(logger: logging.Logger): def should_sync(logger: logging.Logger):

View File

@@ -85,7 +85,7 @@ class ArchPackage(SoftwarePackage):
@staticmethod @staticmethod
def disk_cache_path(pkgname: str): def disk_cache_path(pkgname: str):
return ARCH_CACHE_PATH + '/installed/' + pkgname return f'{ARCH_CACHE_PATH}/installed/{pkgname}'
def get_pkg_build_url(self): def get_pkg_build_url(self):
if self.package_base: if self.package_base:

View File

@@ -156,8 +156,8 @@ class ArchDiskCacheUpdater(Thread):
self.progress = 0 # progress is defined by the number of packages prepared and indexed self.progress = 0 # progress is defined by the number of packages prepared and indexed
self.controller = controller self.controller = controller
self.internet_available = internet_available self.internet_available = internet_available
self.installed_hash_path = '{}/installed.sha1'.format(ARCH_CACHE_PATH) self.installed_hash_path = f'{ARCH_CACHE_PATH}/installed.sha1'
self.installed_cache_dir = '{}/installed'.format(ARCH_CACHE_PATH) self.installed_cache_dir = f'{ARCH_CACHE_PATH}/installed'
self.aur_indexer = aur_indexer self.aur_indexer = aur_indexer
self.create_config = create_config self.create_config = create_config
self.taskman.register_task(self.task_id, self.i18n['arch.task.disk_cache'], get_icon_path()) self.taskman.register_task(self.task_id, self.i18n['arch.task.disk_cache'], get_icon_path())

View File

@@ -1,12 +1,12 @@
import os import os
from bauh.api.paths import CACHE_PATH, CONFIG_PATH from bauh.api.paths import CONFIG_PATH, CACHE_PATH
from bauh.commons import resource from bauh.commons import resource
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
SNAP_CACHE_PATH = CACHE_PATH + '/snap' SNAP_CACHE_PATH = f'{CACHE_PATH}/snap'
CONFIG_FILE = '{}/snap.yml'.format(CONFIG_PATH) CONFIG_FILE = '{}/snap.yml'.format(CONFIG_PATH)
CATEGORIES_FILE_PATH = SNAP_CACHE_PATH + '/categories.txt' CATEGORIES_FILE_PATH = f'{SNAP_CACHE_PATH}/categories.txt'
URL_CATEGORIES_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/snap/categories.txt' URL_CATEGORIES_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/snap/categories.txt'
SUGGESTIONS_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/snap/suggestions.txt' SUGGESTIONS_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/snap/suggestions.txt'

View File

@@ -7,7 +7,7 @@ from bauh.commons.util import map_timestamp_file
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
WEB_PATH = '{}/.local/share/bauh/web'.format(Path.home()) WEB_PATH = '{}/.local/share/bauh/web'.format(Path.home())
WEB_CACHE_PATH = '{}/web'.format(CACHE_PATH) WEB_CACHE_PATH = f'{CACHE_PATH}/web'
INSTALLED_PATH = '{}/installed'.format(WEB_PATH) INSTALLED_PATH = '{}/installed'.format(WEB_PATH)
ENV_PATH = '{}/env'.format(WEB_PATH) ENV_PATH = '{}/env'.format(WEB_PATH)
FIXES_PATH = '{}/fixes'.format(WEB_PATH) FIXES_PATH = '{}/fixes'.format(WEB_PATH)
@@ -28,12 +28,12 @@ URL_FIX_PATTERN = "https://raw.githubusercontent.com/vinifmor/bauh-files/master/
URL_SUGGESTIONS = "https://raw.githubusercontent.com/vinifmor/bauh-files/master/web/env/v1/suggestions.yml" URL_SUGGESTIONS = "https://raw.githubusercontent.com/vinifmor/bauh-files/master/web/env/v1/suggestions.yml"
UA_CHROME = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36' UA_CHROME = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'
TEMP_PATH = '{}/web'.format(TEMP_DIR) TEMP_PATH = '{}/web'.format(TEMP_DIR)
SEARCH_INDEX_FILE = '{}/index.yml'.format(WEB_CACHE_PATH) SEARCH_INDEX_FILE = f'{WEB_CACHE_PATH}/index.yml'
SUGGESTIONS_CACHE_FILE = '{}/suggestions.yml'.format(WEB_CACHE_PATH) SUGGESTIONS_CACHE_FILE = f'{WEB_CACHE_PATH}/suggestions.yml'
SUGGESTIONS_CACHE_TS_FILE = map_timestamp_file(SUGGESTIONS_CACHE_FILE) SUGGESTIONS_CACHE_TS_FILE = map_timestamp_file(SUGGESTIONS_CACHE_FILE)
CONFIG_FILE = '{}/web.yml'.format(CONFIG_PATH) CONFIG_FILE = '{}/web.yml'.format(CONFIG_PATH)
ENVIRONMENT_SETTINGS_CACHED_FILE = '{}/environment.yml'.format(WEB_CACHE_PATH) ENVIRONMENT_SETTINGS_CACHED_FILE = f'{WEB_CACHE_PATH}/environment.yml'
ENVIRONMENT_SETTINGS_TS_FILE = '{}/environment.ts'.format(WEB_CACHE_PATH) ENVIRONMENT_SETTINGS_TS_FILE = f'{WEB_CACHE_PATH}/environment.ts'
NATIVEFIER_BASE_URL = 'https://github.com/nativefier/nativefier/archive/v{version}.tar.gz' NATIVEFIER_BASE_URL = 'https://github.com/nativefier/nativefier/archive/v{version}.tar.gz'

View File

@@ -2,7 +2,7 @@ from pathlib import Path
from bauh.api.paths import CACHE_PATH from bauh.api.paths import CACHE_PATH
TRAY_CHECK_FILE = '{}/notify_tray'.format(CACHE_PATH) # it is a file that signals to the tray icon it should recheck for updates TRAY_CHECK_FILE = f'{CACHE_PATH}/notify_tray' # it is a file that signals to the tray icon it should recheck for updates
def notify_tray(): def notify_tray():

View File

@@ -5,8 +5,8 @@ from pathlib import Path
from packaging.version import parse as parse_version from packaging.version import parse as parse_version
from bauh import __app_name__, __version__ from bauh import __app_name__, __version__
from bauh.api.paths import CACHE_PATH
from bauh.api.http import HttpClient from bauh.api.http import HttpClient
from bauh.api.paths import CACHE_PATH
from bauh.commons.html import bold, link from bauh.commons.html import bold, link
from bauh.view.util.translation import I18n from bauh.view.util.translation import I18n
@@ -33,7 +33,7 @@ def check_for_update(logger: logging.Logger, http_client: HttpClient, i18n: I18n
break break
if latest and latest.get('tag_name'): if latest and latest.get('tag_name'):
notifications_dir = '{}/updates'.format(CACHE_PATH) notifications_dir = f'{CACHE_PATH}/updates'
release_file = '{}/{}{}'.format(notifications_dir, '' if not tray else 'tray_', latest['tag_name']) release_file = '{}/{}{}'.format(notifications_dir, '' if not tray else 'tray_', latest['tag_name'])
if os.path.exists(release_file): if os.path.exists(release_file):
logger.info("Release {} already notified".format(latest['tag_name'])) logger.info("Release {} already notified".format(latest['tag_name']))

View File

@@ -11,7 +11,7 @@ from colorama import Fore
from bauh import __app_name__ from bauh import __app_name__
from bauh.api.abstract.controller import SoftwareManager from bauh.api.abstract.controller import SoftwareManager
from bauh.api.paths import CACHE_PATH, CONFIG_PATH from bauh.api.paths import CONFIG_PATH, CACHE_PATH
from bauh.commons.system import run_cmd from bauh.commons.system import run_cmd
from bauh.view.util import resource from bauh.view.util import resource