summaryrefslogtreecommitdiff
path: root/tic/parser/recipe_parser.py
diff options
context:
space:
mode:
Diffstat (limited to 'tic/parser/recipe_parser.py')
-rw-r--r--tic/parser/recipe_parser.py45
1 files changed, 23 insertions, 22 deletions
diff --git a/tic/parser/recipe_parser.py b/tic/parser/recipe_parser.py
index 82b9e4c..5165c64 100644
--- a/tic/parser/recipe_parser.py
+++ b/tic/parser/recipe_parser.py
@@ -90,9 +90,9 @@ class DefaultRecipe(object):
logger.info(err)
except yaml.YAMLError as err:
logger.info(err)
- def getDefaultRecipe(self):
+ def get_default_recipe(self):
return copy.deepcopy(self.DEFAULT_RECIPE)
- def getSystemConfig(self):
+ def get_system_config(self):
data = copy.deepcopy(self.DEFAULT_RECIPE)
for field in RECIPE_EXTEND_FIELD:
if field == 'Partitions':
@@ -102,7 +102,8 @@ class DefaultRecipe(object):
if data.get(field):
data[field] = []
return data
- def getDefaultParameter(self):
+ @classmethod
+ def get_default_parameter(cls):
return [dict(url=DEFAULT_RECIPE_NAME, type='recipe')]
default_recipe = DefaultRecipe()
@@ -115,7 +116,7 @@ class RecipeParser(object):
self._repositories = None
self._recipe = None
# add recipe input
- self.addRecipes(inputs)
+ self.add_recipes(inputs)
def parse(self):
logger = logging.getLogger(__name__)
@@ -131,7 +132,7 @@ class RecipeParser(object):
if data_type == 'recipe':
# default recipe
if data.get('url') == DEFAULT_RECIPE_NAME:
- self.recipes[data.get('url')] = default_recipe.getDefaultRecipe()
+ self.recipes[data.get('url')] = default_recipe.get_default_recipe()
else:
with contextlib.closing(urllib2.urlopen(data.get('url'))) as op:
self.recipes[data.get('url')] = yaml.load(op.read())
@@ -152,7 +153,7 @@ class RecipeParser(object):
logger.error(err)
raise TICError(configmgr.message['recipe_parse_error'] % data.get('url'))
- def addRecipes(self, inputs):
+ def add_recipes(self, inputs):
if inputs:
if isinstance(inputs, list):
for data in inputs:
@@ -160,12 +161,12 @@ class RecipeParser(object):
else:
self.inputs.append(inputs)
- def getRepositories(self):
+ def get_repositories(self):
if not self._repositories:
- self._repositories = self._getAllRepositories()
+ self._repositories = self._get_all_repositories()
return self._repositories
- def _getAllRepositories(self):
+ def _get_all_repositories(self):
repos = []
name_count = 1
for data in self.inputs:
@@ -201,7 +202,7 @@ class RecipeParser(object):
repos.append(data)
return repos
- def _renameRepository(self, repo_dict, repo_name):
+ def _rename_repository(self, repo_dict, repo_name):
number = repo_dict.get(repo_name)
new_name = ''.join([repo_name, '_', str(number)])
while(new_name in repo_dict):
@@ -210,9 +211,9 @@ class RecipeParser(object):
repo_dict[repo_name] = number + 1
return new_name
- def getMergedRepositories(self):
+ def get_merged_repositories(self):
result = []
- repositories = self.getRepositories()
+ repositories = self.get_repositories()
repo_name = {} # 'name': count
repo_url = {} # 'url': exist
for target in repositories:
@@ -224,7 +225,7 @@ class RecipeParser(object):
continue
# if repo's name is duplicated, rename it (postfix '_count')
if repo.get('name') in repo_name:
- repo['name'] = self._renameRepository(repo_name, repo['name'])
+ repo['name'] = self._rename_repository(repo_name, repo['name'])
else:
repo_name[repo['name']] = 1
repo_url[repo['url']] = 1
@@ -237,18 +238,18 @@ class RecipeParser(object):
if target.get('url') in repo_url:
continue
if target['name'] in repo_name:
- target['name'] = self._renameRepository(repo_name, target['name'])
+ target['name'] = self._rename_repository(repo_name, target['name'])
else:
repo_name[target['name']] = 1
repo_url[target['url']] = 1
result.append(target)
return result
- def getMergedRecipe(self):
+ def get_merged_recipe(self):
if self._recipe:
return self._recipe
- mergedInfo = default_recipe.getSystemConfig()
+ mergedInfo = default_recipe.get_system_config()
# merge recipe info
for i in xrange(len(self.inputs), 0, -1):
if self.inputs[i-1].get('type') == 'recipe':
@@ -278,15 +279,15 @@ class RecipeParser(object):
mergedInfo[extName].reverse()
# set repositories
- mergedInfo['Repositories'] = self.getMergedRepositories()
+ mergedInfo['Repositories'] = self.get_merged_repositories()
if mergedInfo.get('Repositories'):
for repo in mergedInfo['Repositories']:
mergedInfo['Recipe']['Repos'].append(repo['name'])
return mergedInfo
- def export2Recipe(self, packages, outdir, filename):
+ def export_recipe(self, packages, outdir, filename):
logger = logging.getLogger(__name__)
- recipe = self.getMergedRecipe()
+ recipe = self.get_merged_recipe()
make_dirs(outdir)
reciep_path = os.path.join(outdir, filename)
# set packages
@@ -315,9 +316,9 @@ class RecipeParser(object):
raise TICError(configmgr.message['recipe_convert_error'])
return reciep_path
- def export2Yaml(self, packages, filepath):
+ def export_yaml(self, packages, filepath):
logger = logging.getLogger(__name__)
- recipe = self.getMergedRecipe()
+ recipe = self.get_merged_recipe()
# config.yaml
config = dict(Default=None, Configurations=[])
config['Default'] = recipe.get('Recipe')
@@ -394,6 +395,6 @@ def YamlInfo(cachedir, configs, repos):
if __name__ == '__main__':
inputs = [{'url': DEFAULT_RECIPE_NAME, 'type': 'recipe'}, {'url': 'http://localhost/repo/recipe/recipe1.yaml', 'type': 'recipe'}]
parser = RecipeParser()
- parser.addRecipes(inputs)
+ parser.add_recipes(inputs)
parser.parse()
print(parser.repositories)