eth-monitor

Monitor and cache ethereum transactions with match filters
git clone git://git.defalsify.org/eth-monitor.git
Info | Log | Files | Refs | README | LICENSE

config.py (1327B)


      1 # standard imports
      2 import re
      3 import logging
      4 
      5 
      6 logg = logging.getLogger(__name__)
      7 
      8 
      9 re_env='^ETHMONITOR_({}_(.+))$'
     10 
     11 
     12 def __override_env(config, config_stem, env):
     13     re_env_instance = re_env.format(config_stem)
     14     for k in env:
     15         r = re.search(re_env_instance, k)
     16         if r != None:
     17             logg.debug('match renderer environment variable: {} '.format(r.group(1)))
     18             config.add(env[k], r.group(1), True)
     19 
     20 
     21 def __override_arg(config, config_stem, args):
     22     if args == None:
     23         return
     24 
     25     args_array = getattr(args, config_stem.lower())
     26     if args_array == None:
     27         return
     28 
     29     i = 0
     30     for a in args_array:
     31         s = config_stem + '_ARG_' + str(i)
     32         config.add(a, s, True)
     33         i += 1
     34 
     35 
     36 def override(config, keyword, env={}, args=None):
     37     config_stem = keyword.upper()
     38     __override_arg(config, config_stem, args)
     39     __override_env(config, config_stem, env)
     40 
     41 
     42 
     43 def list_from_prefix(config, keyword):
     44     re_config = keyword.upper() + '_'
     45     k_default = re_config + 'DEFAULT'
     46     r = []
     47     for k in config.all():
     48         if re.match(re_config, k):
     49             v = config.get(k)
     50             if k == k_default:
     51                 try:
     52                     v = v.split(',')
     53                 except AttributeError:
     54                     continue
     55             r.append(v)
     56     return r