Replace deprecated library function os.popen() with subprocess

os.popen() is deprecated since version 2.6. Resolved with use of
subprocess module.

Change-Id: Iea9c0501f46c57d809217912fb0f40eb2bc4f111
Closes-Bug: #1529836
This commit is contained in:
Harshada Mangesh Kakad 2015-12-30 08:59:21 -08:00
parent 816d90f999
commit c40464514d
2 changed files with 14 additions and 6 deletions

View File

@ -19,7 +19,7 @@
# serve to show the default.
# import sys
import os
import subprocess
import openstackdocstheme
@ -81,10 +81,15 @@ release = '2.1.0'
# bug_project: Launchpad project to file bugs against.
# These variables are passed to the logabug code via html_context.
giturl = u'http://git.openstack.org/cgit/openstack/nova/tree/api-guide/source'
git_cmd = "/usr/bin/git log | head -n1 | cut -f2 -d' '"
gitsha = os.popen(git_cmd).read().strip('\n')
git_cmd = ["/usr/bin/git", "rev-parse", "HEAD"]
gitsha = subprocess.Popen(
git_cmd, stdout=subprocess.PIPE).communicate()[0]
# source tree
pwd = os.popen("pwd").read().strip('\n')
pwd = subprocess.Popen(
"pwd", stdout=subprocess.PIPE).communicate()[0].strip('\n')
# html_context allows us to pass arbitrary values into the html template
html_context = {"pwd": pwd,
"gitsha": gitsha,

View File

@ -12,6 +12,7 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
import subprocess
import sys
import os
@ -194,8 +195,10 @@ html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
git_cmd = "git log --pretty=format:'%ad, commit %h' --date=local -n1"
html_last_updated_fmt = os.popen(git_cmd).read()
git_cmd = ["git", "log", "--pretty=format:'%ad, commit %h'", "--date=local",
"-n1"]
html_last_updated_fmt = subprocess.Popen(
git_cmd, stdout=subprocess.PIPE).communicate()[0]
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.