-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathini_to_yml.py
More file actions
executable file
·31 lines (24 loc) · 916 Bytes
/
ini_to_yml.py
File metadata and controls
executable file
·31 lines (24 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
import ConfigParser
import yaml
import argparse
def process_ini(inifile,ymlfile):
config = ConfigParser.ConfigParser()
config.read(inifile)
datamap = {}
for section in config.sections():
datamap[section] = {}
for name,value in config.items(section):
datamap[section].update({name:value})
with open(ymlfile,"w") as ymlfile:
yaml.dump(datamap,ymlfile,default_flow_style=False)
def main():
parser = argparse.ArgumentParser(description="Convert a basic ini file to yml")
parser.add_argument('--in',action="store",dest="ini",required=True,help="Input ini file")
parser.add_argument('--out',action="store",dest="yml",required=True,help="Output yml file")
args = vars(parser.parse_args())
inifile = args['ini']
ymlfile = args['yml']
process_ini(inifile,ymlfile)
if __name__ == '__main__':
main()