| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | import os, sys |
| |
|
| | if len(sys.argv) < 2: |
| | print('Usage: %s file ...' % (sys.argv[0])) |
| | sys.exit(1) |
| |
|
| | def prepare_conf_files(files): |
| | conf_files = [] |
| | for f in files: |
| | if os.path.isfile(f): |
| | if not os.path.isabs(f): |
| | f = os.path.join(os.getcwd(), f) |
| | conf_files.append(f) |
| | else: |
| | print('%s is not a readable file' % f) |
| | sys.exit(1) |
| | return conf_files |
| |
|
| | conf_files = prepare_conf_files(sys.argv[1:]) |
| | print('conf files: ') |
| | print(conf_files) |
| |
|
| | bk_env_prefix = 'BK_' |
| | zk_env_prefix = 'ZK_' |
| |
|
| | for conf_filename in conf_files: |
| | lines = [] |
| | keys = {} |
| |
|
| | |
| | for line in open(conf_filename): |
| | lines.append(line) |
| | line = line.strip() |
| | |
| | if not line or '=' not in line: |
| | continue |
| |
|
| | if line.startswith('#'): |
| | line = line.replace('#', '') |
| |
|
| | |
| | line = line.replace(' ', '') |
| | k,v = line.split('=', 1) |
| |
|
| | |
| | if k not in keys: |
| | keys[k] = len(lines) - 1 |
| | else: |
| | lines.pop() |
| |
|
| | |
| | for k in sorted(os.environ.keys()): |
| | v = os.environ[k] |
| | if k.startswith(bk_env_prefix): |
| | search_key = k[len(bk_env_prefix):] |
| | if search_key in keys: |
| | print('[%s] Applying config %s = %s' % (conf_filename, search_key, v)) |
| | idx = keys[search_key] |
| | lines[idx] = '%s=%s\n' % (search_key, v) |
| | if k.startswith(zk_env_prefix): |
| | search_key = k[len(zk_env_prefix):] |
| | if search_key in keys: |
| | print('[%s] Applying config %s = %s' % (conf_filename, search_key, v)) |
| | idx = keys[search_key] |
| | lines[idx] = '%s=%s\n' % (search_key, v) |
| |
|
| | |
| | f = open(conf_filename, 'w') |
| | for line in lines: |
| | f.write(line) |
| | f.close() |
| |
|