def create_airflow_cfg(path, tpl, filename='airflow.cfg', encoding='utf8'):
"""
create airflow.cfg
:param path: root path
:param tpl: template file
:param filename: output filename
:param encoding: Encoding(default:utf8)
"""
env = Environment(loader=FileSystemLoader(path, encoding=encoding))
cfg_tpl = env.get_template(tpl)
cfg = cfg_tpl.render({env: os.environ.get(env) for env in ENVIRONMENTS})
file_path = '/'.join([path, filename])
if os.path.exists(file_path):
os.remove(file_path)
with open(file_path, 'w', encoding=encoding) as f:
f.write(cfg)
f.close()
评论列表
文章目录