Added basic configuration loading and creating the formulas directory if it doesn't exist
This commit is contained in:
parent
7549efaa78
commit
60ed108749
40
salt-formula-manager.py
Normal file
40
salt-formula-manager.py
Normal file
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from git import Repo
|
||||
import os
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
# constants
|
||||
CONFIG_FILE = 'sfm.yaml'
|
||||
|
||||
# reads configuration and returns the dictionary
|
||||
def read_config():
|
||||
f = open(CONFIG_FILE, 'r')
|
||||
conf = yaml.load(f)
|
||||
f.close()
|
||||
|
||||
return conf
|
||||
|
||||
# makes the formulas directory if it doesn't exist
|
||||
def check_formula_dir(conf):
|
||||
# check if the formulas directory is actually a directory
|
||||
if not os.path.isdir(conf['formulas_dir']):
|
||||
# check if it's a file
|
||||
if os.path.exists(conf['formulas_dir']):
|
||||
print(str(conf['formulas_dir']) + ' exists but is not a directory. Please fix this.')
|
||||
sys.exit(1)
|
||||
# create it if not
|
||||
else:
|
||||
os.makedirs(conf['formulas_dir'])
|
||||
|
||||
# main program
|
||||
def main():
|
||||
# read configuration settings
|
||||
conf = read_config()
|
||||
|
||||
# make sure the formulas directory exists
|
||||
check_formula_dir(conf)
|
||||
|
||||
# run main
|
||||
main()
|
Loading…
Reference in New Issue
Block a user