Skip to content
Newer
Older
100644 23 lines (20 sloc) 892 Bytes
27fa807 @malcolmt Added support for machine-based local settings.
authored Aug 16, 2010
1 import socket
2
3 def load_external_settings(module_root, caller_globals):
4 """
5 Loads an external settings file, based on machine hostname, and pulls all
6 the all-caps names into the passed-in namespace.
7 """
8 # Convert machine hostname to valid Python module name.
9 hostname = socket.gethostname().replace(".", "_").replace("-", "_")
10 try:
11 module = __import__("%s.%s" % (module_root, hostname), caller_globals,
12 {}, [])
13 local_settings = getattr(module, hostname)
14 for setting in dir(local_settings):
15 if setting.upper() == setting:
16 caller_globals[setting] = getattr(local_settings, setting)
17 except ImportError:
18 # File may not exist, so we ignore all import errors. If you make a
19 # Python syntax error in the file, it will be swallowed silently. So
20 # don't do that.
21 pass
22
Something went wrong with that request. Please try again.