Made the parse_entry function for the Formula class a little less confusing
This commit is contained in:
parent
adcd08c544
commit
4aa1141538
@ -10,33 +10,34 @@ class Formula():
|
|||||||
def __init__(self, formula_def, formulas_dir, formulas_url):
|
def __init__(self, formula_def, formulas_dir, formulas_url):
|
||||||
self.formulas_dir = formulas_dir
|
self.formulas_dir = formulas_dir
|
||||||
self.formulas_url = formulas_url
|
self.formulas_url = formulas_url
|
||||||
self.parse_entry(formula_def)
|
self.formula_def = formula_def
|
||||||
|
self.parse_entry()
|
||||||
|
|
||||||
# sets the formula's git_url and local_path variables
|
# sets the formula's git_url and local_path variables
|
||||||
def parse_entry(self, formula_def):
|
def parse_entry(self):
|
||||||
# define our function variables here
|
# define our function variables here
|
||||||
git_url = ''
|
git_url = ''
|
||||||
local_path = ''
|
local_path = ''
|
||||||
|
|
||||||
# check if the formula entry is a string or a dictionary
|
# check if the formula entry is a string or a dictionary
|
||||||
if isinstance(formula_def, dict):
|
if isinstance(self.formula_def, dict):
|
||||||
# entry is a dictionary
|
# entry is a dictionary
|
||||||
# check if the formula's name was defined
|
# check if the formula's name was defined
|
||||||
if not 'name' in formula_def:
|
if not 'name' in self.formula_def:
|
||||||
# set the formula's name if need be
|
# set the formula's name if need be
|
||||||
name_partial = [k for i, k in enumerate(formula_def.keys()) if i == 0][0]
|
name_partial = [k for i, k in enumerate(self.formula_def.keys()) if i == 0][0]
|
||||||
formula_def['name'] = name_partial + '-formula'
|
self.formula_def['name'] = name_partial + '-formula'
|
||||||
# check if the dictionary has a git URL defined
|
# check if the dictionary has a git URL defined
|
||||||
if 'url' in formula_def:
|
if 'url' in self.formula_def:
|
||||||
git_url = str(formula_def['url'])
|
git_url = str(self.formula_def['url'])
|
||||||
else:
|
else:
|
||||||
git_url = str(self.formulas_url) + str(formula_def) + '-formula'
|
git_url = str(self.formulas_url) + str(self.formula_def['name']) + '-formula'
|
||||||
# put together the local
|
# put together the local
|
||||||
local_path = str(self.formulas_dir) + '/' + str(formula_def['name'])
|
local_path = str(self.formulas_dir) + '/' + str(self.formula_def['name'])
|
||||||
elif isinstance(formula_def, str):
|
elif isinstance(self.formula_def, str):
|
||||||
# entry is a string
|
# entry is a string
|
||||||
git_url = str(self.formulas_url) + str(formula_def) + '-formula'
|
git_url = str(self.formulas_url) + str(self.formula_def) + '-formula'
|
||||||
local_path = str(self.formulas_dir) + '/' + str(formula_def) + '-formula'
|
local_path = str(self.formulas_dir) + '/' + str(self.formula_def) + '-formula'
|
||||||
else:
|
else:
|
||||||
# entry type is not supported
|
# entry type is not supported
|
||||||
print('One of your formula entries is not a dict or a string (' + str(formula_def) + ') - please fix this.')
|
print('One of your formula entries is not a dict or a string (' + str(formula_def) + ') - please fix this.')
|
||||||
|
Loading…
Reference in New Issue
Block a user