Commits

Anonymous committed fd6c3ab

Make the config file be read at run time, not import time. Allows override of config file.

  • Participants
  • Parent commits 5561446

Comments (0)

Files changed (1)

File config_reader.py

 import xml.etree.ElementTree as ET
 import os
 
-HOME = os.environ['HOME']
-CONFIG_FILE = os.environ.get('DATABASES_XML_FILE', HOME + '/.databases.xml')
-
-def read_config(config_file=CONFIG_FILE):
+def read_config(config_file=None):
     '''Read the config file and return a dictionary filled in with values
     
     >>> db = read_config("./testdatabases.xml")
     >>> print db
     {'default': {'ENGINE': 'django.db.backends.mysql', 'NAME': 'name1', 'HOST': 'db.example.org', 'USER': 'user1', 'PASSWORD': 'pass1', 'PORT': '3333'}, 'default-ro': {'ENGINE': 'django.db.backends.mysql', 'NAME': 'name1ro', 'HOST': 'db.example.org', 'USER': 'user1ro', 'PASSWORD': 'pass1ro', 'PORT': '3333'}}
     '''
+    if not config_file:
+        HOME = os.environ['HOME']
+        config_file = os.environ.get('DATABASES_XML_FILE', HOME + '/.databases.xml')
     with open(config_file, 'r') as f:
         etree = ET.parse(f)
     config_dict = {}