mirror of
https://github.com/Ladebeze66/odoo_toolkit.git
synced 2025-12-13 12:36:52 +01:00
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import os
|
|
import json
|
|
from config import EXPORT_DIR
|
|
|
|
def ensure_export_directory(subdir=None):
|
|
"""Assure que le répertoire d'export existe"""
|
|
if subdir:
|
|
directory = os.path.join(EXPORT_DIR, subdir)
|
|
else:
|
|
directory = EXPORT_DIR
|
|
os.makedirs(directory, exist_ok=True)
|
|
return directory
|
|
|
|
def save_json(filename, data):
|
|
"""Sauvegarde des données au format JSON"""
|
|
try:
|
|
with open(filename, 'w', encoding='utf-8') as f:
|
|
json.dump(data, f, ensure_ascii=False, indent=4)
|
|
return True
|
|
except Exception as e:
|
|
print(f"Erreur lors de la sauvegarde du fichier {filename}: {e}")
|
|
return False
|
|
|
|
def get_user_choice(prompt, options):
|
|
"""Obtient un choix utilisateur parmi une liste d'options"""
|
|
while True:
|
|
print(prompt)
|
|
for i, option in enumerate(options, 1):
|
|
print(f"{i}. {option}")
|
|
|
|
try:
|
|
choice = int(input("Votre choix: "))
|
|
if 1 <= choice <= len(options):
|
|
return choice
|
|
else:
|
|
print("Choix invalide. Veuillez réessayer.")
|
|
except ValueError:
|
|
print("Veuillez entrer un nombre valide.")
|
|
|
|
def print_error(message):
|
|
print(f" Erreur: {message}") |