mirror of
https://github.com/prise6/smart-iss-posts
synced 2024-05-19 13:56:33 +02:00
fonction pour generer le template yaml
This commit is contained in:
parent
1aa1d8051a
commit
f62ee67730
|
@ -3,16 +3,12 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import yaml
|
import yaml
|
||||||
from dotenv import find_dotenv, load_dotenv
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
load_dotenv(find_dotenv())
|
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
|
||||||
def __init__(self, project_dir = os.getenv("PROJECT_DIR"), mode = os.getenv("MODE")):
|
def __init__(self, project_dir, mode):
|
||||||
|
|
||||||
self.project_dir = project_dir
|
self.project_dir = project_dir
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.path_matcher = re.compile(r'\$\{([^}^{]+)\}')
|
self.path_matcher = re.compile(r'\$\{([^}^{]+)\}')
|
||||||
|
|
27
iss/tools/config_template.py
Normal file
27
iss/tools/config_template.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
import os
|
||||||
|
from dotenv import find_dotenv, load_dotenv
|
||||||
|
from iss.tools.config import Config
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
cfg = Config(project_dir = os.getenv('PROJECT_DIR'), mode = os.getenv('MODE'))
|
||||||
|
replace_items_recursive(cfg.config)
|
||||||
|
print(cfg.project_dir + '/config/config.template.yaml')
|
||||||
|
with open(cfg.project_dir + '/config/config.template.yaml', 'w') as f:
|
||||||
|
yaml.dump(cfg.config, f, default_flow_style = False)
|
||||||
|
|
||||||
|
def replace_items_recursive(d, v = 'XXX'):
|
||||||
|
for k in d.keys():
|
||||||
|
if type(d.get(k)) is not dict:
|
||||||
|
d.update({k: v})
|
||||||
|
else:
|
||||||
|
replace_items_recursive(d.get(k))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
load_dotenv(find_dotenv())
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue