Changed the functions so that they only take what parameters they need to work

This commit is contained in:
Gregory Ballantine 2017-07-19 13:06:00 -04:00
parent 672be1929d
commit 805758c295

View File

@ -17,21 +17,21 @@ def read_config():
return conf
# makes the formulas directory if it doesn't exist
def check_formula_dir(conf):
def check_formula_dir(formulas_dir):
# check if the formulas directory is actually a directory
if not os.path.isdir(conf['formulas_dir']):
if not os.path.isdir(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.')
if os.path.exists(formulas_dir):
print(str(formulas_dir) + ' exists but is not a directory. Please fix this.')
sys.exit(1)
# create it if not
else:
os.makedirs(conf['formulas_dir'])
os.makedirs(formulas_dir)
# loops through the array of repos and downloads them
def get_formulas(conf):
def get_formulas(formulas, formulas_dir, formulas_url):
# loop through the defined formulas
for formula in conf['formulas']:
for formula in formulas:
git_url = ''
local_path = ''
@ -39,11 +39,11 @@ def get_formulas(conf):
if isinstance(formula, dict):
# entry is a dictionary
git_url = str(formula['url'])
local_path = str(conf['formulas_dir']) + '/' + str(formula['name'])
local_path = str(formulas_dir) + '/' + str(formula['name'])
elif isinstance(formula, str):
# entry is a string
git_url = str(conf['formulas_url']) + str(formula) + '-formula'
local_path = str(conf['formulas_dir']) + '/' + str(formula) + '-formula'
git_url = str(formulas_url) + str(formula) + '-formula'
local_path = str(formulas_dir) + '/' + str(formula) + '-formula'
else:
# entry type is not supported
print('One of your entries is not a dict or a string (' + str(formula) + ') - please fix this.')
@ -71,13 +71,13 @@ def main():
conf = read_config()
# make sure the formulas directory exists
check_formula_dir(conf)
check_formula_dir(conf['formulas_dir'])
# do the formula stuff
get_formulas(conf)
get_formulas(conf['formulas'], conf['formulas_dir'], conf['formulas_url'])
# clean unmanaged formulas
clean_formulas(conf)
#clean_formulas(conf)
# run main
main()