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
# limitations under the License.
from __future__ import print_function
from __future__ import unicode_literals
import os
import subprocess
import sys
@ -44,7 +47,7 @@ if 'DISTRO_NAME' in os.environ:
# centos7 matches as rhel7 in devstack
RELEASE='rhel7'
if not RELEASE:
print "Can not determine RELEASE"
print("Can not determine RELEASE")
sys.exit(1)
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={}):
print "Running:", cmd
print("Running:", cmd)
newenv = os.environ
newenv.update(env)
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()
if status:
return (p.returncode, out.strip())
@ -106,8 +110,8 @@ def _find_images(basedir):
if os.path.exists(image_tool):
returncode, out = run_local(image_tool, status=True)
if returncode:
print "%s failed" % image_tool
print "Exit: %s, Output: %s" % (returncode, out)
print("%s failed" % image_tool)
print("Exit: %s, Output: %s" % (returncode, out))
# reset images so we'll fall back
images = []
else:
@ -126,7 +130,7 @@ def local_prep(distribution):
if ' -> ' in branch:
continue
branch_data = {'name': branch}
print 'Branch: ', branch
print('Branch: ', branch)
run_local(['sudo', 'git', 'checkout', branch], 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
# limitations under the License.
from __future__ import print_function
import os
import urllib2
from urllib2 import URLError
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/'
'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):
try:
projects = []
for f in yaml.load(urllib2.urlopen(url)):
for f in yaml.load(urlopen(url)):
# Skip repos that are inactive
project = f['project']
dirname = os.path.dirname(project)
@ -50,7 +53,7 @@ def get_project_list(url):
return projects
except URLError:
print "Could not open project list url: '%s'" % url
print("Could not open project list url: '%s'" % url)
raise
def main():