-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
38 lines (31 loc) · 1.46 KB
/
common.py
File metadata and controls
38 lines (31 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import sys
from pathlib import Path
def resource_path(relative_path):
""" Get the absolute path to a resource, works for dev and for PyInstaller """
if hasattr(sys, '_MEIPASS'):
# Running as bundled executable
return os.path.join(sys._MEIPASS, relative_path)
else:
# Running in development environment
# Get the directory of the current file
current_dir = os.path.dirname(os.path.abspath(__file__))
# Navigate up to the project root (assuming this file is in a subdirectory)
project_root = os.path.dirname(current_dir)
# Join the project root with the relative path
return os.path.join(project_root, relative_path)
# nicola: Dans Linusque, tu peux utiliser f'{Path.home()}/.config/{folder_name}'.
def get_strava_path(folder_name="Strava"):
"""
Retourne le chemin d'un dossier pour sauvegarder les jeux en cours en fonction du système d'exploitation.
:param folder_name: Nom du sous-dossier pour les sauvegardes (optionnel).
:return: Chemin absolu du dossier de sauvegarde.
"""
# Récupère le dossier utilisateur en fonction du système d'exploitation
if os.name == 'nt': # Système Windows
save_path = f'{Path.home()}/Documents/{folder_name}'
elif os.name == 'posix': # Systèmes Unix-like (Linux, macOS)
save_path = f'{Path.home()}/{folder_name}'
else:
raise OSError("Système d'exploitation non supporté")
return save_path