]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
heat : workaround engine error with version code
authorSteven Hardy <shardy@redhat.com>
Wed, 10 Oct 2012 10:57:33 +0000 (11:57 +0100)
committerSteven Hardy <shardy@redhat.com>
Wed, 10 Oct 2012 13:26:52 +0000 (14:26 +0100)
Work around lack of git sha in vcsversion so we don't get an
engine error if the version dict doesn't contain the sha key

Fixes #259

Change-Id: I25d2cfb008a5a9e0e1a60e7360e58608d2d8e9c0
Signed-off-by: Steven Hardy <shardy@redhat.com>
heat/version.py

index 2c75971aef05a0d1e93e6ef6939056cdfe05f8cb..9eafd553c275403a99123c751581e19a5a17d499 100644 (file)
@@ -13,6 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import os
 
 try:
     import git
@@ -22,7 +23,7 @@ except ImportError:
 try:
     from heat.vcsversion import version_info
 except ImportError:
-    version_info = {'sha': ''}
+    version_info = {}
 
 HEAT_VERSION = '7'
 FINAL = False   # This becomes true at Release Candidate time
@@ -30,29 +31,33 @@ FINAL = False   # This becomes true at Release Candidate time
 
 def get_git_sha():
     if not git:
-        return version_info['sha']
+        return version_info.get('sha', '')
 
     try:
         repo = git.Repo('.')
-    except InvalidGitRepositoryError:
-        return version_info['sha']
+    except git.InvalidGitRepositoryError:
+        return version_info.get('sha', '')
     return repo.head.commit.hexsha
 
 
 def write_git_sha():
-    if not git:
-        return
 
     sha = get_git_sha()
+    vcsversion_path = 'heat/vcsversion.py'
 
     if sha:
-        with open('heat/vcsversion.py', 'w') as version_file:
+        with open(vcsversion_path, 'w') as version_file:
             version_file.write("""
 # This file is automatically generated by heat's setup.py, so don't edit it. :)
 version_info = {
     'sha': '%s'
 }
 """ % (sha))
+    else:
+        try:
+            os.remove(vcsversion_path)
+        except OSError:
+            pass
 
 
 def version_string(type='short'):