Fix import error "No module named six.moves" for plugin sanity job
This commit fixes the import error "No module named six.moves" without
using the module for the plugin sanity job. Because the job call the
script directly.
Change-Id: Id0fa1b15fe443d65a1b6ca008e490d0fa54d6b32
diff --git a/tools/generate-tempest-plugins-list.py b/tools/generate-tempest-plugins-list.py
index 5e63c0d..99df0d1 100644
--- a/tools/generate-tempest-plugins-list.py
+++ b/tools/generate-tempest-plugins-list.py
@@ -26,7 +26,14 @@
import json
import re
-from six.moves import urllib
+try:
+ # For Python 3.0 and later
+ from urllib.error import HTTPError as HTTPError
+ import urllib.request as urllib
+except ImportError:
+ # Fall back to Python 2's urllib2
+ import urllib2 as urllib
+ from urllib2 import HTTPError as HTTPError
url = 'https://review.openstack.org/projects/'
@@ -51,9 +58,9 @@
def has_tempest_plugin(proj):
try:
- r = urllib.request.urlopen(
+ r = urllib.urlopen(
"https://git.openstack.org/cgit/%s/plain/setup.cfg" % proj)
- except urllib.error.HTTPError as err:
+ except HTTPError as err:
if err.code == 404:
return False
p = re.compile('^tempest\.test_plugins', re.M)
@@ -62,7 +69,7 @@
else:
False
-r = urllib.request.urlopen(url)
+r = urllib.urlopen(url)
# Gerrit prepends 4 garbage octets to the JSON, in order to counter
# cross-site scripting attacks. Therefore we must discard it so the
# json library won't choke.