def get_config(config='~/.nyttth/config.yml'):
global cfg
if not cfg:
cfgpath = os.path.expanduser(config)
log.debug('reading config from {}'.format(cfgpath))
cfg = dict()
if os.path.isfile(cfgpath):
with open(cfgpath, 'r') as stream:
cfg = yaml.load(stream)
else:
print 'config not found at {}. Create y/n?'.format(cfgpath)
if propmt_yn():
import errno
try:
os.makedirs(os.path.dirname(cfgpath))
except OSError as e:
if e.errno != errno.EEXIST:
raise
with open(cfgpath, 'w') as cfg_file:
cfg_file.write(SAMPLE_CONFIG)
print 'Sample configuration has been written to {}.\n You will need to edit '.format(cfgpath) + \
'this configuration with real values from your networking environment. Exiting.'
else:
print 'Exiting'
exit()
if 'log_level' in cfg:
# print('setting log level to {}'.format(cfg['log_level']))
log.setLevel(logging.getLevelName(cfg['log_level']))
cfg['basedir'] = os.path.dirname(cfgpath)
cfg['supervisor.conf'] = os.path.join(cfg['basedir'],'supervisord.conf')
return cfg
no_you_talk_to_the_hand.py 文件源码
python
阅读 22
收藏 0
点赞 0
评论 0
评论列表
文章目录