import os
import json
def split_config(config_file, output_dir="config_splits"):
"""
Splits a configuration file into development-only minimal configurations.
Args:
config_file (str): Path to the configuration file.
output_dir (str): Directory to store the split configurations.
"""
if not os.path.exists(output_dir):
os.makedirs(output_dir)
try:
with open(config_file, 'r') as f:
config = json.load(f)
except FileNotFoundError:
print(f"Error: Configuration file not found: {config_file}")
return
except json.JSONDecodeError:
print(f"Error: Invalid JSON in configuration file: {config_file}")
return
development_config = {}
minimal_config = {}
for key, value in config.items():
if key.startswith("development_only_"):
development_config[key] = value
elif key.startswith("minimal_"):
minimal_config[key] = value
else:
#Consider all other keys as essential
pass
development_file = os.path.join(output_dir, "development.json")
minimal_file = os.path.join(output_dir, "minimal.json")
try:
with open(development_file, 'w') as f:
json.dump(development_config, f, indent=4)
with open(minimal_file, 'w') as f:
json.dump(minimal_config, f, indent=4)
print(f"Split configurations saved to: {output_dir}")
except Exception as e:
print(f"Error writing to file: {e}")
if __name__ == '__main__':
# Example Usage:
# Assuming you have a config file named 'config.json'
split_config("config.json")
Add your comment