def setup(cls): for name, value in uppercase_attributes(cls).items(): if isinstance(value, Value): try: setup_value(cls, name, value) except ValueError, e: print 'WARNING: ', e
def FileSettings(path): path = os.path.expanduser(path) mod = imp.new_module('localshop.local') mod.__file__ = path class Holder(object): pass try: with open(path, 'r') as fh: exec(fh.read(), mod.__dict__) except IOError as e: print("Notice: Unable to load configuration file %s (%s), " "using default settings\n\n" % (path, e.strerror)) return Holder for name, value in uppercase_attributes(mod).items(): setattr(Holder, name, value) return Holder
def apply_settings(cls): """A decorator to set class attributes from imported settings.""" for key, value in uppercase_attributes(settings).items(): setattr(cls, key, value) return cls
def FileSettings(path): path = os.path.expanduser(path) mod = imp.new_module('localshop.local') mod.__file__ = path class Holder(object): pass try: execfile(path, mod.__dict__) except IOError, e: print("Notice: Unable to load configuration file %s (%s), " "using default settings\n\n" % (path, e.strerror)) return Holder for name, value in uppercase_attributes(mod).items(): setattr(Holder, name, value) return Holder class Base(Settings): # Django settings for localshop project. PROJECT_ROOT = os.path.join(os.path.dirname(__file__), os.pardir) DEBUG = False TEMPLATE_DEBUG = DEBUG ADMINS = ( # ('Your Name', '*****@*****.**'), )