From 530a5019e252833c0cf10983a93576b4dac4f1eb Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Wed, 24 Nov 2021 14:14:04 -0300 Subject: [PATCH] [api] refactoring: adding AUTOSTART_DIR constant to 'paths' module --- CHANGELOG.md | 1 + bauh/api/paths.py | 1 + bauh/gems/web/controller.py | 5 ++--- bauh/gems/web/model.py | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30367e5c..97a9445f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - caching: `/var/cache/bauh` - configuration: `/etc/bauh` - temp dir: `/tmp/bauh@root` (`/tmp/bauh@$USER` for non root users) + - autostart: `/etc/xdg/autostart` (only used by the Web gem at the moment) - UI - settings panel: diff --git a/bauh/api/paths.py b/bauh/api/paths.py index 1ca0ea63..62e9522e 100644 --- a/bauh/api/paths.py +++ b/bauh/api/paths.py @@ -10,3 +10,4 @@ USER_THEMES_PATH = '{}/.local/share/bauh/themes'.format(str(Path.home())) DESKTOP_ENTRIES_DIR = '{}/.local/share/applications'.format(str(Path.home())) TEMP_DIR = f'/tmp/{__app_name__}@{getuser()}' LOGS_DIR = f'{TEMP_DIR}/logs' +AUTOSTART_DIR = f'/etc/xdg/autostart' if user.is_root() else f'{Path.home()}/.config/autostart' diff --git a/bauh/gems/web/controller.py b/bauh/gems/web/controller.py index 0eda0fd5..ad43233a 100644 --- a/bauh/gems/web/controller.py +++ b/bauh/gems/web/controller.py @@ -26,7 +26,7 @@ from bauh.api.abstract.model import SoftwarePackage, CustomSoftwareAction, Packa SuggestionPriority, PackageStatus from bauh.api.abstract.view import MessageType, MultipleSelectComponent, InputOption, SingleSelectComponent, \ SelectViewType, TextInputComponent, FormComponent, FileChooserComponent, ViewComponent, PanelComponent -from bauh.api.paths import DESKTOP_ENTRIES_DIR +from bauh.api.paths import DESKTOP_ENTRIES_DIR, AUTOSTART_DIR from bauh.commons import resource from bauh.commons.boot import CreateConfigFile from bauh.commons.html import bold @@ -763,8 +763,7 @@ class WebApplicationManager(SoftwareManager): pkg.desktop_entry = desktop_entry_path if '--tray=start-in-tray' in install_options: - autostart_dir = '{}/.config/autostart'.format(Path.home()) - Path(autostart_dir).mkdir(parents=True, exist_ok=True) + Path(AUTOSTART_DIR).mkdir(parents=True, exist_ok=True) with open(pkg.get_autostart_path(), 'w+') as f: f.write(entry_content) diff --git a/bauh/gems/web/model.py b/bauh/gems/web/model.py index a5bfae45..d04f2d47 100644 --- a/bauh/gems/web/model.py +++ b/bauh/gems/web/model.py @@ -6,6 +6,7 @@ from typing import List from bauh import __app_name__ from bauh.api import user from bauh.api.abstract.model import SoftwarePackage +from bauh.api.paths import AUTOSTART_DIR from bauh.commons import resource from bauh.gems.web import ROOT_DIR @@ -125,7 +126,7 @@ class WebApplication(SoftwarePackage): def get_autostart_path(self) -> str: if self.desktop_entry: - return f"{Path.home()}/.config/autostart/{self.desktop_entry.split('/')[-1]}" + return f"{AUTOSTART_DIR}/{self.desktop_entry.split('/')[-1]}" def set_custom_icon(self, custom_icon: str): self.custom_icon = custom_icon