salt-formula-manager/salt-formula-manager.py

78 lines
2.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
import os
import sys
import yaml
from lib import Formula
from lib import FormulaRepo
# constants
CONFIG_FILE = 'sfm.yaml'
REPO_STATE = 'latest'
# reads configuration and returns the dictionary
def read_config():
f = open(CONFIG_FILE, 'r')
conf = yaml.load(f)
f.close()
return conf
# creates the formulas directory if it doesn't exist
def check_formula_dir(formulas_dir):
# check if the formulas directory is actually a directory
if not os.path.isdir(formulas_dir):
# check if it's a file
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(formulas_dir)
# loops through the array of repos and downloads them
def get_formulas(formulas, formulas_dir, formulas_url):
2016-09-26 16:48:51 -04:00
# loop through the defined formulas
for formula_def in formulas:
# create a formula object
formula = Formula.Formula(formula_def, formulas_dir, formulas_url)
# create a repo object for the formula
formula_repo = FormulaRepo.FormulaRepo(formula)
# retrieve our formula
formula_repo.retrieve()
# pull any new commits for the repo
formula_repo.pull_updates()
# get the repo tracking information from the formula definition
tracking_version = formula.get_tracking_state()
# make sure our formula's repo is up-to-date with the latest tracked version
formula_repo.check_tracking_info(tracking_version)
# purge un-managed formulas
def clean_formulas(conf):
if conf['purge_formulas']:
print('Cleaning out unmanaged formulas')
else:
print('Not cleaning out unmanaged formulas')
# main program
def main():
# read configuration settings
conf = read_config()
# make sure the formulas directory exists
check_formula_dir(conf['formulas_dir'])
# do the formula stuff
get_formulas(conf['formulas'], conf['formulas_dir'], conf['formulas_url'])
# clean unmanaged formulas
#clean_formulas(conf)
# run main
main()