def add_recipes(self, recipes, name, override=False):
"""
Parameters
----------
"""
# ====== validate arguments ====== #
if not is_string(name):
raise ValueError("`name` must be string, but given: %s" % str(type(name)))
if name in self._saved_recipes and not override:
raise ValueError("Cannot override pre-defined RECIPE with name: '%s'"
% name)
# ====== validate recipes list ====== #
if isinstance(recipes, RecipeList):
recipes = tuple(recipes._recipes)
else:
tmp = []
for rcp in as_tuple(recipes, t=FeederRecipe):
if isinstance(rcp, RecipeList):
tmp += list(rcp._recipes)
else:
tmp.append(rcp)
recipes = tuple(tmp)
# ====== store the recipes to disk ====== #
path = os.path.join(self.recipe_path, name)
with open(path, 'wb') as f:
cPickle.dump(recipes, f, protocol=cPickle.HIGHEST_PROTOCOL)
# ====== update local recipes list ====== #
self._saved_recipes[name] = recipes
return self
评论列表
文章目录