Broke the parsing of the formula entry into a separate functions
This commit is contained in:
parent
805758c295
commit
9b0c48a8e1
@ -32,22 +32,7 @@ def check_formula_dir(formulas_dir):
|
|||||||
def get_formulas(formulas, formulas_dir, formulas_url):
|
def get_formulas(formulas, formulas_dir, formulas_url):
|
||||||
# loop through the defined formulas
|
# loop through the defined formulas
|
||||||
for formula in formulas:
|
for formula in formulas:
|
||||||
git_url = ''
|
git_url, local_path = parse_formula_entry(formula, formulas_dir, formulas_url)
|
||||||
local_path = ''
|
|
||||||
|
|
||||||
# check if the formula entry is a string or a dictionary
|
|
||||||
if isinstance(formula, dict):
|
|
||||||
# entry is a dictionary
|
|
||||||
git_url = str(formula['url'])
|
|
||||||
local_path = str(formulas_dir) + '/' + str(formula['name'])
|
|
||||||
elif isinstance(formula, str):
|
|
||||||
# entry is a string
|
|
||||||
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.')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# check if the destination directory exists
|
# check if the destination directory exists
|
||||||
if os.path.exists(local_path):
|
if os.path.exists(local_path):
|
||||||
@ -57,6 +42,29 @@ def get_formulas(formulas, formulas_dir, formulas_url):
|
|||||||
# clone git repo
|
# clone git repo
|
||||||
Repo.clone_from(git_url, local_path)
|
Repo.clone_from(git_url, local_path)
|
||||||
|
|
||||||
|
# parses a formula entry, and then returns the target git URL and the destination for the clone
|
||||||
|
def parse_formula_entry(formula, formulas_dir, formulas_url):
|
||||||
|
# define our variables to be returned
|
||||||
|
git_url = ''
|
||||||
|
local_path = ''
|
||||||
|
|
||||||
|
# check if the formula entry is a string or a dictionary
|
||||||
|
if isinstance(formula, dict):
|
||||||
|
# entry is a dictionary
|
||||||
|
git_url = str(formula['url'])
|
||||||
|
local_path = str(formulas_dir) + '/' + str(formula['name'])
|
||||||
|
elif isinstance(formula, str):
|
||||||
|
# entry is a string
|
||||||
|
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.')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# return the values here
|
||||||
|
return git_url, local_path
|
||||||
|
|
||||||
# purge un-managed formulas
|
# purge un-managed formulas
|
||||||
def clean_formulas(conf):
|
def clean_formulas(conf):
|
||||||
if conf['purge_formulas']:
|
if conf['purge_formulas']:
|
||||||
|
Loading…
Reference in New Issue
Block a user