From 67747e3dabb7abdb349d671c9c4c95b409ac83b7 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Thu, 30 May 2024 08:39:22 -0600 Subject: [PATCH] update config --- utils/update_config.py | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/utils/update_config.py b/utils/update_config.py index 5444174..3e6ff92 100644 --- a/utils/update_config.py +++ b/utils/update_config.py @@ -20,23 +20,55 @@ def update_config(config_file_path): # Prepare the new content new_content = [] in_databases_section = False + backup_section_exists = False + in_backup_section = False for line in lines: + # Detect if we are in the [databases] section if line.strip().lower() == '[databases]': in_databases_section = True continue if line.startswith('[') and in_databases_section: in_databases_section = False - if not in_databases_section: - new_content.append(line) + if in_databases_section: + continue + + # Detect if we are in the [BACKUP] section + if line.strip().lower() == '[backup]': + backup_section_exists = True + in_backup_section = True + elif line.startswith('[') and in_backup_section: + in_backup_section = False + + # Add lines to the new content, and check for existing keys in the [BACKUP] section + if in_backup_section: + if 'export_enabled' not in config['BACKUP']: + new_content.append('export_enabled=true\n') + if 'full_backup_enabled' not in config['BACKUP']: + new_content.append('full_backup_enabled=true\n') + if 'backup_snapshot_streams' not in config['BACKUP']: + new_content.append('backup_snapshot_streams=false\n') + if 'max_stream_size' not in config['BACKUP']: + new_content.append('# Maximum size of a backup stream, the default is 10GB, be careful when setting this higher\n') + new_content.append('# Especially considering PV\'s for plex, sonarr, radarr, etc. can be quite large\n') + new_content.append('# Example: max_stream_size=10GB, max_stream_size=20KB, max_stream_size=1TB\n') + new_content.append('# max_stream_size=10GB\n') + + new_content.append(line) - # Ensure the [BACKUP] section is added if it does not exist - if 'BACKUP' not in config: + # If the [BACKUP] section does not exist, add it + if not backup_section_exists: new_content.append('\n[BACKUP]\n') new_content.append('export_enabled=true\n') new_content.append('full_backup_enabled=true\n') + new_content.append('backup_snapshot_streams=false\n') + new_content.append('\n## String options ##\n') new_content.append('# Uncomment the following line to specify a custom dataset location for backups\n') new_content.append('# custom_dataset_location=\n') + new_content.append('\n# Maximum size of a backup stream, the default is 10GB, be careful when setting this higher\n') + new_content.append('# Especially considering PV\'s for plex, sonarr, radarr, etc. can be quite large\n') + new_content.append('# Example: max_stream_size=10GB, max_stream_size=20KB, max_stream_size=1TB\n') + new_content.append('# max_stream_size=10GB\n') # Write the new content back to the config file with config_file_path.open('w') as file: