ewa.config

Package ewa :: Module config |
[hide private]
[frames] | no frames]

# Source Code for Module ewa.config

     1  """
     2  A barebones config object loaded from a Python config file.
     3  """
     4
     5  import os
     6
     7  try:
     8      os.fork
     9  except NameError:
    10      have_fork=False
    11  else:
    12      have_fork=True
    13
    14 -class _config(object):
    15 -    def __init__(self):
    16          pass
    17
    18 -    def load(self, filename):
    19          filename=os.path.abspath(filename)
    20          s=open(filename).read()
    21          codeobj=compile(s, filename, 'exec')
    22          env={}
    23          exec codeobj in {}, env
    24          # load env selectively into self.__dict__
    25          for key in (k for k in env if not k.startswith('_')):
    26              self.__dict__[key]=env[key]
    27
    28 -    def merge_defaults(self, **kw):
    29          for k in kw:
    30              self.__dict__.setdefault(k, kw[k])
    31
    32 -    def keys(self):
    33          return self.__dict__.keys()
    34
    35 -    def __iter__(self):
    36          return self.__dict__.__iter__()
    37
    38 -    def iteritems(self):
    39          return self.__dict__.iteritems()
    40
    41 -    def clear(self):
    42          self.__dict__
    43
    44  Config=_config()
    45
    46  DEFAULTS=dict(loglevel='critical',
    47                logfile=None,
    48                logrotate=None,
    49                daemonize=True,
    50                use_xsendfile=True,
    51                sendfile_header='X-Sendfile',
    52                refresh_rate=0,
    53                protocol='fcgi',
    54                interface='127.0.0.1',
    55                port=5000,
    56                unixsocket=None,
    57                umask=None,
    58                stream=False,
    59                basedir=None,
    60                rulefile=None,
    61                targetdir=None,
    62                pidfile=None,
    63                use_threads=not have_fork,
    64                engine='default',
    65                user=None,
    66                group=None,
    67                content_disposition='attachment',
    68                lame_path='/usr/bin/lame',
    69                min_spare=None,
    70                max_spare=None,
    71                max_threads=None,
    72                max_children=None,
    73                max_requests=None
    74                )
    75
    76 -def initConfig(configfile):
    77      Config.load(configfile)
    78      Config.merge_defaults(**DEFAULTS)
    79
    80  __all__=['Config', 'initConfig']
    81