Allow using openstackdocstheme without git installed

When building rpm packages, git might not be available in the
build env because it is not needed when building from a sdist tarball.
So make git optional.

Change-Id: I159768799fcf15ed0aea6b8350dd395f632e812d
This commit is contained in:
Thomas Bechtold 2017-07-04 12:26:39 +02:00
parent cb33fecb2d
commit af22063ebf
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)