From d6f031b49584f9be5c9d2840fd6c768ef01ebff6 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Mon, 26 Sep 2016 16:48:51 -0400 Subject: [PATCH] Added repo cloning to this script --- salt-formula-manager.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/salt-formula-manager.py b/salt-formula-manager.py index 913717d..5ac00f3 100644 --- a/salt-formula-manager.py +++ b/salt-formula-manager.py @@ -30,11 +30,32 @@ def check_formula_dir(conf): # loops through the array of repos and downloads them def get_formulas(conf): + # loop through the defined formulas for formula in conf['formulas']: + git_url = '' + local_path = '' + + # check if the formula entry is a string or a dictionary if isinstance(formula, dict): - print('Downloading ' + str(formula['url']) + ' into ' + str(conf['formulas_dir']) + '/' + str(formula['name'])) + # entry is a dictionary + git_url = str(formula['url']) + local_path = str(conf['formulas_dir']) + '/' + str(formula['name']) elif isinstance(formula, str): - print('Downloading ' + str(conf['formulas_url']) + str(formula) + '-formula into ' + str(conf['formulas_dir']) + '/' + str(formula) + '-formula') + # entry is a string + git_url = str(conf['formulas_url']) + str(formula) + '-formula' + local_path = str(conf['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 + if os.path.exists(local_path): + print(local_path + ' already exists, so we\'re skipping this.') + else: + print('Downloading ' + git_url + ' into ' + local_path) + # clone git repo + Repo.clone_from(git_url, local_path) # main program def main():