Merge "Allow using openstackdocstheme without git installed"

This commit is contained in:
Jenkins 2017-07-04 16:33:11 +00:00 committed by Gerrit Code Review
commit 0daee5c3c8
2 changed files with 14 additions and 5 deletions

View File

@ -71,8 +71,12 @@ release = '1.0'
# These variables are passed to the logabug code via html_context.
giturl = u'https://git.openstack.org/cgit/openstack/openstackdocstheme/tree/doc/source'
git_cmd = ["/usr/bin/git", "rev-parse", "HEAD"]
gitsha = subprocess.Popen(
git_cmd, stdout=subprocess.PIPE).communicate()[0].strip('\n')
# git might not be available during build (eg when building from an sdist)
try:
gitsha = subprocess.Popen(
git_cmd, stdout=subprocess.PIPE).communicate()[0].strip('\n')
except Exception:
gitsha = 'unknown'
bug_tag = "doc-builds"
html_context = {"gitsha": gitsha, "bug_tag": bug_tag, "giturl": giturl}

View File

@ -78,9 +78,14 @@ def _html_page_context(app, pagename, templatename, context, doctree):
global _html_context_data
if _html_context_data is None:
_html_context_data = {}
_html_context_data['gitsha'] = subprocess.check_output(
['git', 'rev-parse', 'HEAD'],
).decode('utf-8').strip()
try:
_html_context_data['gitsha'] = subprocess.check_output(
['git', 'rev-parse', 'HEAD'],
).decode('utf-8').strip()
except Exception:
app.warn('Cannot get gitsha from git repository.')
_html_context_data['gitsha'] = 'unknown'
repo_name = app.config.repository_name
if repo_name:
_html_context_data['giturl'] = _giturl.format(repo_name)