mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 00:04:15 +02:00
Switch runtime app identity to bearhub with legacy path migration
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
__version__ = '0.10.7'
|
__version__ = '0.10.7'
|
||||||
__app_name__ = 'bauh'
|
__app_name__ = 'bearhub'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import os
|
||||||
|
import shutil
|
||||||
from getpass import getuser
|
from getpass import getuser
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -18,3 +20,51 @@ LOGS_DIR = f'{TEMP_DIR}/logs'
|
|||||||
AUTOSTART_DIR = f'/etc/xdg/autostart' if user.is_root() else f'{Path.home()}/.config/autostart'
|
AUTOSTART_DIR = f'/etc/xdg/autostart' if user.is_root() else f'{Path.home()}/.config/autostart'
|
||||||
BINARIES_DIR = f'/usr/local/bin' if user.is_root() else f'{Path.home()}/.local/bin'
|
BINARIES_DIR = f'/usr/local/bin' if user.is_root() else f'{Path.home()}/.local/bin'
|
||||||
SHARED_FILES_DIR = f'/usr/local/share/{__app_name__}' if user.is_root() else f'{Path.home()}/.local/share/{__app_name__}'
|
SHARED_FILES_DIR = f'/usr/local/share/{__app_name__}' if user.is_root() else f'{Path.home()}/.local/share/{__app_name__}'
|
||||||
|
|
||||||
|
|
||||||
|
def _migrate_dir_if_possible(old_path: str, new_path: str):
|
||||||
|
if old_path == new_path:
|
||||||
|
return
|
||||||
|
|
||||||
|
if not os.path.exists(old_path):
|
||||||
|
return
|
||||||
|
|
||||||
|
if os.path.exists(new_path):
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
parent = os.path.dirname(new_path)
|
||||||
|
if parent:
|
||||||
|
Path(parent).mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
shutil.move(old_path, new_path)
|
||||||
|
except Exception:
|
||||||
|
# The migration is best-effort. If it fails, the app can still start with empty defaults.
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_legacy_paths():
|
||||||
|
old_app_name = 'bauh'
|
||||||
|
|
||||||
|
if old_app_name == __app_name__:
|
||||||
|
return
|
||||||
|
|
||||||
|
if user.is_root():
|
||||||
|
old_cache = f'/var/cache/{old_app_name}'
|
||||||
|
old_config = f'/etc/{old_app_name}'
|
||||||
|
old_shared = f'/usr/local/share/{old_app_name}'
|
||||||
|
old_temp = f'/tmp/{old_app_name}@{getuser()}'
|
||||||
|
else:
|
||||||
|
home = Path.home()
|
||||||
|
old_cache = f'{home}/.cache/{old_app_name}'
|
||||||
|
old_config = f'{home}/.config/{old_app_name}'
|
||||||
|
old_shared = f'{home}/.local/share/{old_app_name}'
|
||||||
|
old_temp = f'/tmp/{old_app_name}@{getuser()}'
|
||||||
|
|
||||||
|
_migrate_dir_if_possible(old_cache, CACHE_DIR)
|
||||||
|
_migrate_dir_if_possible(old_config, CONFIG_DIR)
|
||||||
|
_migrate_dir_if_possible(old_shared, SHARED_FILES_DIR)
|
||||||
|
_migrate_dir_if_possible(old_temp, TEMP_DIR)
|
||||||
|
|
||||||
|
|
||||||
|
migrate_legacy_paths()
|
||||||
|
|||||||
Reference in New Issue
Block a user