Python3 support for cache-devstack/openstack-repos

Add python3 support for these functions.  Tested with a python3 based
dib in a Xenial environment.  Add __future__ imports so we don't
regress on these bits.

Change-Id: Iddca88cb6c9fbff6383c3597eb81133948b3b420
This commit is contained in:
Ian Wienand 2017-05-16 14:46:51 +10:00
parent 64bb1f6bcb
commit 5941b67292
2 changed files with 17 additions and 10 deletions

View File

@ -16,6 +16,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import print_function
from __future__ import unicode_literals
import os import os
import subprocess import subprocess
import sys import sys
@ -44,7 +47,7 @@ if 'DISTRO_NAME' in os.environ:
# centos7 matches as rhel7 in devstack # centos7 matches as rhel7 in devstack
RELEASE='rhel7' RELEASE='rhel7'
if not RELEASE: if not RELEASE:
print "Can not determine RELEASE" print("Can not determine RELEASE")
sys.exit(1) sys.exit(1)
DEVSTACK = os.path.join(TMP_MOUNT_PATH, 'opt/git/openstack-dev/devstack') DEVSTACK = os.path.join(TMP_MOUNT_PATH, 'opt/git/openstack-dev/devstack')
@ -53,11 +56,12 @@ IMAGES=os.path.join(TMP_HOOKS_PATH, 'source-repository-images')
def run_local(cmd, status=False, cwd='.', env={}): def run_local(cmd, status=False, cwd='.', env={}):
print "Running:", cmd print("Running:", cmd)
newenv = os.environ newenv = os.environ
newenv.update(env) newenv.update(env)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, cwd=cwd, p = subprocess.Popen(cmd, stdout=subprocess.PIPE, cwd=cwd,
stderr=subprocess.STDOUT, env=newenv) stderr=subprocess.STDOUT, env=newenv,
universal_newlines=True)
(out, nothing) = p.communicate() (out, nothing) = p.communicate()
if status: if status:
return (p.returncode, out.strip()) return (p.returncode, out.strip())
@ -106,8 +110,8 @@ def _find_images(basedir):
if os.path.exists(image_tool): if os.path.exists(image_tool):
returncode, out = run_local(image_tool, status=True) returncode, out = run_local(image_tool, status=True)
if returncode: if returncode:
print "%s failed" % image_tool print("%s failed" % image_tool)
print "Exit: %s, Output: %s" % (returncode, out) print("Exit: %s, Output: %s" % (returncode, out))
# reset images so we'll fall back # reset images so we'll fall back
images = [] images = []
else: else:
@ -126,7 +130,7 @@ def local_prep(distribution):
if ' -> ' in branch: if ' -> ' in branch:
continue continue
branch_data = {'name': branch} branch_data = {'name': branch}
print 'Branch: ', branch print('Branch: ', branch)
run_local(['sudo', 'git', 'checkout', branch], cwd=DEVSTACK) run_local(['sudo', 'git', 'checkout', branch], cwd=DEVSTACK)
run_local(['sudo', 'git', 'pull', '--ff-only', 'origin'], cwd=DEVSTACK) run_local(['sudo', 'git', 'pull', '--ff-only', 'origin'], cwd=DEVSTACK)

View File

@ -16,11 +16,14 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import print_function
import os import os
import urllib2
from urllib2 import URLError
import yaml import yaml
from six.moves.urllib.request import urlopen
from six.moves.urllib.error import URLError
URL = ('https://git.openstack.org/cgit/openstack-infra/project-config/' URL = ('https://git.openstack.org/cgit/openstack-infra/project-config/'
'plain/gerrit/projects.yaml') 'plain/gerrit/projects.yaml')
@ -33,7 +36,7 @@ CUSTOM_PROJECTS_LIST_URL=os.environ.get('DIB_CUSTOM_PROJECTS_LIST_URL')
def get_project_list(url): def get_project_list(url):
try: try:
projects = [] projects = []
for f in yaml.load(urllib2.urlopen(url)): for f in yaml.load(urlopen(url)):
# Skip repos that are inactive # Skip repos that are inactive
project = f['project'] project = f['project']
dirname = os.path.dirname(project) dirname = os.path.dirname(project)
@ -50,7 +53,7 @@ def get_project_list(url):
return projects return projects
except URLError: except URLError:
print "Could not open project list url: '%s'" % url print("Could not open project list url: '%s'" % url)
raise raise
def main(): def main():