Change read_recipe_commit to use the recipe name

Callers really shouldn't need to know the details of the filenames, so
change it to convert it internally.
This commit is contained in:
Brian C. Lane 2017-11-13 15:14:24 -08:00
parent ab6decec0b
commit 639d325a0c
3 changed files with 10 additions and 11 deletions

View File

@ -292,15 +292,15 @@ def read_commit(repo, branch, filename, commit=None):
""" """
return read_commit_spec(repo, "%s:%s" % (commit or branch, filename)) return read_commit_spec(repo, "%s:%s" % (commit or branch, filename))
def read_recipe_commit(repo, branch, filename, commit=None): def read_recipe_commit(repo, branch, recipe_name, commit=None):
"""Read a recipe commit from git and return a Recipe object """Read a recipe commit from git and return a Recipe object
:param repo: Open repository :param repo: Open repository
:type repo: Git.Repository :type repo: Git.Repository
:param branch: Branch name :param branch: Branch name
:type branch: str :type branch: str
:param filename: filename to read :param recipe_name: Recipe name to read
:type filename: str :type recipe_name: str
:param commit: Optional commit hash :param commit: Optional commit hash
:type commit: str :type commit: str
:returns: A Recipe object :returns: A Recipe object
@ -310,7 +310,7 @@ def read_recipe_commit(repo, branch, filename, commit=None):
If no commit is passed the master:filename is returned, otherwise it will be If no commit is passed the master:filename is returned, otherwise it will be
commit:filename commit:filename
""" """
recipe_toml = read_commit(repo, branch, filename, commit) recipe_toml = read_commit(repo, branch, recipe_filename(recipe_name), commit)
return recipe_from_toml(recipe_toml) return recipe_from_toml(recipe_toml)
def list_branch_files(repo, branch): def list_branch_files(repo, branch):
@ -441,7 +441,7 @@ def commit_recipe(repo, branch, recipe):
:raises: Can raise errors from Ggit :raises: Can raise errors from Ggit
""" """
try: try:
old_recipe = read_recipe_commit(repo, branch, recipe.filename) old_recipe = read_recipe_commit(repo, branch, recipe["name"])
old_version = old_recipe["version"] old_version = old_recipe["version"]
except Exception: except Exception:
old_version = None old_version = None

View File

@ -75,7 +75,6 @@ def v0_api(api):
errors = [] errors = []
for recipe_name in [n.strip() for n in recipe_names.split(",")]: for recipe_name in [n.strip() for n in recipe_names.split(",")]:
exceptions = [] exceptions = []
filename = recipe_filename(recipe_name)
# Get the workspace version (if it exists) # Get the workspace version (if it exists)
try: try:
with api.config["GITLOCK"].lock: with api.config["GITLOCK"].lock:
@ -87,7 +86,7 @@ def v0_api(api):
# Get the git version (if it exists) # Get the git version (if it exists)
try: try:
with api.config["GITLOCK"].lock: with api.config["GITLOCK"].lock:
git_recipe = read_recipe_commit(api.config["GITLOCK"].repo, "master", filename) git_recipe = read_recipe_commit(api.config["GITLOCK"].repo, "master", recipe_name)
except Exception as e: except Exception as e:
git_recipe = None git_recipe = None
exceptions.append(str(e)) exceptions.append(str(e))
@ -157,7 +156,7 @@ def v0_api(api):
commit_recipe(api.config["GITLOCK"].repo, "master", recipe) commit_recipe(api.config["GITLOCK"].repo, "master", recipe)
# Read the recipe with new version and write it to the workspace # Read the recipe with new version and write it to the workspace
recipe = read_recipe_commit(api.config["GITLOCK"].repo, "master", recipe.filename) recipe = read_recipe_commit(api.config["GITLOCK"].repo, "master", recipe["name"])
workspace_write(api.config["GITLOCK"].repo, "master", recipe) workspace_write(api.config["GITLOCK"].repo, "master", recipe)
except Exception as e: except Exception as e:
return jsonify(status=False, error={"msg":str(e)}), 400 return jsonify(status=False, error={"msg":str(e)}), 400

View File

@ -151,12 +151,12 @@ class GitRecipesTest(unittest.TestCase):
commits = recipes.list_commits(self.repo, "master", "http-server.toml") commits = recipes.list_commits(self.repo, "master", "http-server.toml")
self.assertEqual(len(commits), 1, "Wrong number of commits: %s" % commits) self.assertEqual(len(commits), 1, "Wrong number of commits: %s" % commits)
recipe = recipes.read_recipe_commit(self.repo, "master", "http-server.toml") recipe = recipes.read_recipe_commit(self.repo, "master", "http-server")
self.assertNotEqual(recipe, None) self.assertNotEqual(recipe, None)
self.assertEqual(recipe["name"], "http-server") self.assertEqual(recipe["name"], "http-server")
# Read by commit id # Read by commit id
recipe = recipes.read_recipe_commit(self.repo, "master", "http-server.toml", commits[0].commit) recipe = recipes.read_recipe_commit(self.repo, "master", "http-server", commits[0].commit)
self.assertNotEqual(recipe, None) self.assertNotEqual(recipe, None)
self.assertEqual(recipe["name"], "http-server") self.assertEqual(recipe["name"], "http-server")
@ -193,7 +193,7 @@ class GitRecipesTest(unittest.TestCase):
def test_10_tag_new_commit(self): def test_10_tag_new_commit(self):
"""Test tagging a newer commit of a recipe""" """Test tagging a newer commit of a recipe"""
recipe = recipes.read_recipe_commit(self.repo, "master", "http-server.toml") recipe = recipes.read_recipe_commit(self.repo, "master", "http-server")
recipe["description"] = "A modified description" recipe["description"] = "A modified description"
oid = recipes.commit_recipe(self.repo, "master", recipe) oid = recipes.commit_recipe(self.repo, "master", recipe)
self.assertNotEqual(oid, None) self.assertNotEqual(oid, None)