salt-formula-manager/lib/Formula.py

62 lines
2.2 KiB
Python
Raw Permalink Normal View History

import sys
class Formula():
# class variables
git_url = ''
version = ''
local_path = ''
# class constructor
def __init__(self, formula_def, formulas_dir, formulas_url):
self.formulas_dir = formulas_dir
self.formulas_url = formulas_url
self.formula_def = formula_def
self.__parse_entry()
# sets the formula's git_url and local_path variables
def __parse_entry(self):
# define our function variables here
git_url = ''
version = ''
local_path = ''
# check if the formula entry is a string or a dictionary
if isinstance(self.formula_def, dict):
# entry is a dictionary
# check if the formula's name was defined
if not 'name' in self.formula_def:
# set the formula's name if need be
name_partial = [k for k, v in self.formula_def.items() if v == None][0]
self.formula_def['name'] = name_partial + '-formula'
# check if the dictionary has a git URL defined
if 'url' in self.formula_def:
git_url = str(self.formula_def['url'])
else:
git_url = str(self.formulas_url) + str(self.formula_def['name'])
# 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)
# put together the local
local_path = str(self.formulas_dir) + '/' + str(self.formula_def['name'])
else:
# entry type is not supported
print('One of your formula entries is not a dict (' + str(self.formula_def) + ') - please fix this.')
sys.exit(1)
# set the class values here
self.git_url = git_url
self.version = version
self.local_path = local_path
# checks to see if a tag to track has been defined
def get_tracking_state(self):
return self.version