Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
update config
Browse files Browse the repository at this point in the history
  • Loading branch information
Heavybullets8 committed May 30, 2024
1 parent 965b6e3 commit 67747e3
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions utils/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 67747e3

Please sign in to comment.