diff --git a/salt-formula-manager.py b/salt-formula-manager.py index fc7ef05..b0caec1 100644 --- a/salt-formula-manager.py +++ b/salt-formula-manager.py @@ -32,22 +32,7 @@ def check_formula_dir(formulas_dir): def get_formulas(formulas, formulas_dir, formulas_url): # loop through the defined formulas for formula in formulas: - 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) + git_url, local_path = parse_formula_entry(formula, formulas_dir, formulas_url) # check if the destination directory exists if os.path.exists(local_path): @@ -57,6 +42,29 @@ def get_formulas(formulas, formulas_dir, formulas_url): # clone git repo 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 def clean_formulas(conf): if conf['purge_formulas']: