2016-09-14 16:29:58 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from git import Repo
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import yaml
|
|
|
|
|
2017-07-20 11:30:28 -04:00
|
|
|
from lib import Formula
|
|
|
|
from lib import FormulaRepo
|
|
|
|
|
2016-09-14 16:29:58 -04:00
|
|
|
# constants
|
|
|
|
CONFIG_FILE = 'sfm.yaml'
|
2017-07-20 11:30:28 -04:00
|
|
|
REPO_STATE = 'latest'
|
2016-09-14 16:29:58 -04:00
|
|
|
|
|
|
|
# reads configuration and returns the dictionary
|
|
|
|
def read_config():
|
|
|
|
f = open(CONFIG_FILE, 'r')
|
|
|
|
conf = yaml.load(f)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
return conf
|
|
|
|
|
2017-07-20 11:30:28 -04:00
|
|
|
# creates the formulas directory if it doesn't exist
|
2017-07-19 13:06:00 -04:00
|
|
|
def check_formula_dir(formulas_dir):
|
2016-09-14 16:29:58 -04:00
|
|
|
# check if the formulas directory is actually a directory
|
2017-07-19 13:06:00 -04:00
|
|
|
if not os.path.isdir(formulas_dir):
|
2016-09-14 16:29:58 -04:00
|
|
|
# check if it's a file
|
2017-07-19 13:06:00 -04:00
|
|
|
if os.path.exists(formulas_dir):
|
|
|
|
print(str(formulas_dir) + ' exists but is not a directory. Please fix this.')
|
2016-09-14 16:29:58 -04:00
|
|
|
sys.exit(1)
|
|
|
|
# create it if not
|
|
|
|
else:
|
2017-07-19 13:06:00 -04:00
|
|
|
os.makedirs(formulas_dir)
|
2016-09-14 16:29:58 -04:00
|
|
|
|
2016-09-14 16:58:33 -04:00
|
|
|
# loops through the array of repos and downloads them
|
2017-07-19 13:06:00 -04:00
|
|
|
def get_formulas(formulas, formulas_dir, formulas_url):
|
2016-09-26 16:48:51 -04:00
|
|
|
# loop through the defined formulas
|
2017-07-20 11:30:28 -04:00
|
|
|
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)
|
2016-09-14 16:58:33 -04:00
|
|
|
|
2017-07-20 11:30:28 -04:00
|
|
|
# retrieve our formula
|
|
|
|
formula_repo.retrieve()
|
2017-07-19 13:09:16 -04:00
|
|
|
|
2017-07-20 11:30:28 -04:00
|
|
|
# make sure our formula's repo is up-to-date with the latest tracked version
|
|
|
|
## TODO
|
2017-07-19 13:09:16 -04:00
|
|
|
|
2016-09-29 11:51:46 -04:00
|
|
|
# purge un-managed formulas
|
|
|
|
def clean_formulas(conf):
|
|
|
|
if conf['purge_formulas']:
|
|
|
|
print('Cleaning out unmanaged formulas')
|
|
|
|
|
|
|
|
else:
|
|
|
|
print('Not cleaning out unmanaged formulas')
|
|
|
|
|
2016-09-14 16:29:58 -04:00
|
|
|
# main program
|
|
|
|
def main():
|
|
|
|
# read configuration settings
|
|
|
|
conf = read_config()
|
|
|
|
|
|
|
|
# make sure the formulas directory exists
|
2017-07-19 13:06:00 -04:00
|
|
|
check_formula_dir(conf['formulas_dir'])
|
2016-09-14 16:29:58 -04:00
|
|
|
|
2016-09-14 16:58:33 -04:00
|
|
|
# do the formula stuff
|
2017-07-19 13:06:00 -04:00
|
|
|
get_formulas(conf['formulas'], conf['formulas_dir'], conf['formulas_url'])
|
2016-09-14 16:58:33 -04:00
|
|
|
|
2016-09-29 11:51:46 -04:00
|
|
|
# clean unmanaged formulas
|
2017-07-19 13:06:00 -04:00
|
|
|
#clean_formulas(conf)
|
2016-09-29 11:51:46 -04:00
|
|
|
|
2016-09-14 16:29:58 -04:00
|
|
|
# run main
|
|
|
|
main()
|