From 83cc7cc134ab23839a6a42f31c160234633a72c1 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Wed, 24 Nov 2021 10:46:39 -0300 Subject: [PATCH] [api] refactoring: temp dir now follow the patter /tmp/bauh@vinicius --- CHANGELOG.md | 1 + README.md | 2 +- bauh/api/paths.py | 3 ++- bauh/gems/arch/__init__.py | 2 +- bauh/gems/arch/controller.py | 2 +- bauh/gems/arch/cpu_manager.py | 3 ++- bauh/gems/web/__init__.py | 2 +- 7 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9389f3b..4365525a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - General - directory paths changed for a root user using bauh: - caching: `/var/cache/bauh` + - temp dir: `/tmp/bauh@root` (`/tmp/bauh@$USER` for non root users) - UI - settings panel: diff --git a/README.md b/README.md index 9d7544a1..4a034453 100644 --- a/README.md +++ b/README.md @@ -411,7 +411,7 @@ boot: #### Directory structure, caching and logs - `~/.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. -- `/tmp/bauh` (or `/tmp/bauh_root` for **root**): stores logging and temporary files (e.g: build dependencies) +- `/tmp/bauh@$USER` (e.g: `/tmp/bauh@root`): stores logging and temporary files (e.g: build dependencies) #### Custom themes diff --git a/bauh/api/paths.py b/bauh/api/paths.py index 8bab3d9c..07ef627e 100644 --- a/bauh/api/paths.py +++ b/bauh/api/paths.py @@ -1,3 +1,4 @@ +from getpass import getuser from pathlib import Path from bauh import __app_name__ @@ -7,4 +8,4 @@ CACHE_PATH = f'/var/cache/{__app_name__}' if user.is_root() else f'{Path.home()} CONFIG_PATH = '{}/.config/bauh'.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())) -TEMP_DIR = '/tmp/bauh{}'.format('_root' if user.is_root() else '') +TEMP_DIR = f'/tmp/{__app_name__}@{getuser()}' diff --git a/bauh/gems/arch/__init__.py b/bauh/gems/arch/__init__.py index 0c434ab2..6f83071a 100644 --- a/bauh/gems/arch/__init__.py +++ b/bauh/gems/arch/__init__.py @@ -5,7 +5,7 @@ from bauh.api.paths import CONFIG_PATH, TEMP_DIR, CACHE_PATH from bauh.commons import resource ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) -BUILD_DIR = '{}/arch'.format(TEMP_DIR) +BUILD_DIR = f'{TEMP_DIR}/arch' ARCH_CACHE_PATH = f'{CACHE_PATH}/arch' CATEGORIES_FILE_PATH = f'{ARCH_CACHE_PATH}/categories.txt' URL_CATEGORIES_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/arch/categories.txt' diff --git a/bauh/gems/arch/controller.py b/bauh/gems/arch/controller.py index 1f896bed..0d0d7ab4 100644 --- a/bauh/gems/arch/controller.py +++ b/bauh/gems/arch/controller.py @@ -1656,7 +1656,7 @@ class ArchManager(SoftwareManager): version_files[ver] = file_path versions.sort(reverse=True) - extract_path = '{}/arch/history'.format(TEMP_DIR) + extract_path = f'{TEMP_DIR}/arch/history' try: Path(extract_path).mkdir(parents=True, exist_ok=True) diff --git a/bauh/gems/arch/cpu_manager.py b/bauh/gems/arch/cpu_manager.py index 47731176..e10dd249 100644 --- a/bauh/gems/arch/cpu_manager.py +++ b/bauh/gems/arch/cpu_manager.py @@ -4,6 +4,7 @@ import traceback from logging import Logger from typing import Optional, Set, Tuple, Dict +from bauh.api.paths import TEMP_DIR from bauh.commons.system import new_root_subprocess @@ -24,7 +25,7 @@ def current_governors() -> Dict[str, Set[int]]: def set_governor(governor: str, root_password: str, cpu_idxs: Optional[Set[int]] = None): - new_gov_file = '/tmp/bauh_scaling_governor' + new_gov_file = f'{TEMP_DIR}/bauh_scaling_governor' with open(new_gov_file, 'w+') as f: f.write(governor) diff --git a/bauh/gems/web/__init__.py b/bauh/gems/web/__init__.py index 91bf7192..ddfde07d 100644 --- a/bauh/gems/web/__init__.py +++ b/bauh/gems/web/__init__.py @@ -27,7 +27,7 @@ DESKTOP_ENTRY_PATH_PATTERN = DESKTOP_ENTRIES_DIR + '/bauh.web.{name}.desktop' URL_FIX_PATTERN = "https://raw.githubusercontent.com/vinifmor/bauh-files/master/web/fix/{url}.js" 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' -TEMP_PATH = '{}/web'.format(TEMP_DIR) +TEMP_PATH = f'{TEMP_DIR}/web' SEARCH_INDEX_FILE = f'{WEB_CACHE_PATH}/index.yml' SUGGESTIONS_CACHE_FILE = f'{WEB_CACHE_PATH}/suggestions.yml' SUGGESTIONS_CACHE_TS_FILE = map_timestamp_file(SUGGESTIONS_CACHE_FILE)