2017-07-20 11:30:28 -04:00
|
|
|
import sys
|
|
|
|
|
|
|
|
class Formula():
|
|
|
|
|
|
|
|
# class variables
|
|
|
|
git_url = ''
|
2021-04-04 01:46:14 -04:00
|
|
|
version = ''
|
2017-07-20 11:30:28 -04:00
|
|
|
local_path = ''
|
|
|
|
|
|
|
|
# class constructor
|
|
|
|
def __init__(self, formula_def, formulas_dir, formulas_url):
|
|
|
|
self.formulas_dir = formulas_dir
|
|
|
|
self.formulas_url = formulas_url
|
2017-07-25 10:07:21 -04:00
|
|
|
self.formula_def = formula_def
|
2017-08-01 10:09:21 -04:00
|
|
|
self.__parse_entry()
|
2017-07-20 11:30:28 -04:00
|
|
|
|
|
|
|
# sets the formula's git_url and local_path variables
|
2017-08-01 10:09:21 -04:00
|
|
|
def __parse_entry(self):
|
2017-07-20 11:30:28 -04:00
|
|
|
# define our function variables here
|
|
|
|
git_url = ''
|
2021-04-04 01:46:14 -04:00
|
|
|
version = ''
|
2017-07-20 11:30:28 -04:00
|
|
|
local_path = ''
|
|
|
|
|
|
|
|
# check if the formula entry is a string or a dictionary
|
2017-07-25 10:07:21 -04:00
|
|
|
if isinstance(self.formula_def, dict):
|
2017-07-20 11:30:28 -04:00
|
|
|
# entry is a dictionary
|
|
|
|
# check if the formula's name was defined
|
2017-07-25 10:07:21 -04:00
|
|
|
if not 'name' in self.formula_def:
|
2017-07-20 11:30:28 -04:00
|
|
|
# set the formula's name if need be
|
2017-08-02 10:59:16 -04:00
|
|
|
name_partial = [k for k, v in self.formula_def.items() if v == None][0]
|
2017-07-25 10:07:21 -04:00
|
|
|
self.formula_def['name'] = name_partial + '-formula'
|
2017-08-02 10:59:16 -04:00
|
|
|
|
2017-07-20 11:30:28 -04:00
|
|
|
# check if the dictionary has a git URL defined
|
2017-07-25 10:07:21 -04:00
|
|
|
if 'url' in self.formula_def:
|
|
|
|
git_url = str(self.formula_def['url'])
|
2017-07-20 11:30:28 -04:00
|
|
|
else:
|
2017-07-25 16:38:15 -04:00
|
|
|
git_url = str(self.formulas_url) + str(self.formula_def['name'])
|
2021-04-04 01:46:14 -04:00
|
|
|
|
|
|
|
# check if the git tag was defined
|
|
|
|
if 'version' in self.formula_def:
|
|
|
|
version = str(self.formula_def['version'])
|
|
|
|
else:
|
|
|
|
# this is incorrect!
|
|
|
|
print('You must define a version tag for every formula (issue is: ' + str(self.formula_def) + ')')
|
|
|
|
sys.exit(1)
|
2017-08-02 10:59:16 -04:00
|
|
|
|
2017-07-20 11:30:28 -04:00
|
|
|
# put together the local
|
2017-07-25 10:07:21 -04:00
|
|
|
local_path = str(self.formulas_dir) + '/' + str(self.formula_def['name'])
|
2017-07-20 11:30:28 -04:00
|
|
|
else:
|
|
|
|
# entry type is not supported
|
2021-04-04 01:46:14 -04:00
|
|
|
print('One of your formula entries is not a dict (' + str(self.formula_def) + ') - please fix this.')
|
2017-07-20 11:30:28 -04:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# set the class values here
|
|
|
|
self.git_url = git_url
|
2021-04-04 01:46:14 -04:00
|
|
|
self.version = version
|
2017-07-20 11:30:28 -04:00
|
|
|
self.local_path = local_path
|
2017-07-25 10:43:44 -04:00
|
|
|
|
2021-04-04 01:46:14 -04:00
|
|
|
# checks to see if a tag to track has been defined
|
2017-07-25 10:43:44 -04:00
|
|
|
def get_tracking_state(self):
|
2021-04-04 01:46:14 -04:00
|
|
|
return self.version
|