feat: enhance profile import functionality to support original name preservation and unique import modifications

This commit is contained in:
Sam Chau
2025-01-10 00:55:13 +10:30
parent 0fc36be017
commit 76f4f94290
2 changed files with 47 additions and 12 deletions

View File

@@ -136,6 +136,7 @@ def import_profiles():
'Either profileNames or all=true is required'
}), 400
# Get import_as_unique setting
import_settings = get_unique_arrs([arr_id])
arr_settings = import_settings.get(arr_id, {
'import_as_unique': False,
@@ -179,13 +180,22 @@ def import_profiles():
'error': 'Failed to read profiles directory'
}), 500
# Store original names for file lookups
original_names = profile_names.copy()
# Modify profile names if import_as_unique is true
if import_as_unique:
profile_names = [f"{name} [Dictionarry]" for name in profile_names]
logger.info(
f"Modified profile names for unique import: {profile_names}")
logger.debug(
f"Attempting to import profiles: {profile_names} for {arr_data['type']}: {arr_data['name']}"
)
# Get any custom formats referenced in these profiles
format_names = set()
for profile_name in profile_names:
for profile_name in original_names: # Use original names for file lookup
try:
profile_file = f"{get_category_directory('profile')}/{profile_name}.yml"
format_data = load_yaml_file(profile_file)
@@ -195,19 +205,33 @@ def import_profiles():
logger.error(f"Error loading profile {profile_name}: {str(e)}")
continue
# Import/Update formats first - regardless of reported success since 202s are good
# Import/Update formats first
if format_names:
import_formats_to_arr(format_names=list(format_names),
base_url=arr_data['arrServer'],
api_key=arr_data['apiKey'],
arr_type=arr_data['type'])
format_names_list = list(format_names)
if import_as_unique:
modified_format_names = [
f"{name} [Dictionarry]" for name in format_names_list
]
import_formats_to_arr(format_names=modified_format_names,
original_names=format_names_list,
base_url=arr_data['arrServer'],
api_key=arr_data['apiKey'],
arr_type=arr_data['type'])
else:
import_formats_to_arr(format_names=format_names_list,
original_names=format_names_list,
base_url=arr_data['arrServer'],
api_key=arr_data['apiKey'],
arr_type=arr_data['type'])
# Import profiles
result = import_profiles_to_arr(profile_names=profile_names,
original_names=original_names,
base_url=arr_data['arrServer'],
api_key=arr_data['apiKey'],
arr_type=arr_data['type'],
arr_id=arr_id)
arr_id=arr_id,
import_as_unique=import_as_unique)
return jsonify(result), 200 if result['success'] else 400

View File

@@ -15,8 +15,9 @@ from ..arr.manager import get_arr_config
logger = logging.getLogger('importarr')
def import_profiles_to_arr(profile_names: List[str], base_url: str,
api_key: str, arr_type: str, arr_id: str) -> Dict:
def import_profiles_to_arr(profile_names: List[str], original_names: List[str],
base_url: str, api_key: str, arr_type: str,
arr_id: str, import_as_unique: bool) -> Dict:
logger.info(
f"Received {len(profile_names)} profiles to import for {arr_type}")
results = {
@@ -52,14 +53,24 @@ def import_profiles_to_arr(profile_names: List[str], base_url: str,
target_app = TargetApp.RADARR if arr_type.lower(
) == 'radarr' else TargetApp.SONARR
for profile_name in profile_names:
for i, profile_name in enumerate(profile_names):
try:
profile_file = f"{get_category_directory('profile')}/{profile_name}.yml"
# Use original name for file lookup
original_name = original_names[i]
profile_file = f"{get_category_directory('profile')}/{original_name}.yml"
profile_data = load_yaml_file(profile_file)
# Set the potentially modified profile name
profile_data['name'] = profile_name
# Modify custom format names if import_as_unique is true
if import_as_unique and 'custom_formats' in profile_data:
for cf in profile_data['custom_formats']:
cf['name'] = f"{cf['name']} [Dictionarry]"
logger.info("Received profile:\n" +
yaml.dump(profile_data, sort_keys=False))
# Log the language setting (if any)
profile_language = profile_data.get('language', 'any')
if profile_language != 'any':
logger.info(