Enable H23* rules in pep/flake (py3-compat)

Basic python 3 compatibility fixies

Change-Id: I97726d42706c538d40cb1662112e56c13432e87f
Related-Bug: #1333290
This commit is contained in:
Valeriy Ponomaryov
2014-06-23 11:51:29 -04:00
parent 493ec0a538
commit dc1926e9ad
10 changed files with 48 additions and 35 deletions

View File

@@ -109,7 +109,7 @@ class Manager(utils.HookableMixin):
cache_dir = os.path.expanduser(os.path.join(base_dir, uniqifier))
try:
os.makedirs(cache_dir, 0755)
os.makedirs(cache_dir, 0o755)
except OSError:
# NOTE(kiall): This is typically either permission denied while
# attempting to create the directory, or the directory

View File

@@ -7,6 +7,8 @@
OpenStack Client interface. Handles the REST calls and responses.
"""
from __future__ import print_function
import logging
import os
import urlparse
@@ -227,13 +229,13 @@ class HTTPClient(object):
self.management_url = management_url.rstrip('/')
return None
except exceptions.AmbiguousEndpoints:
print "Found more than one valid endpoint. Use a more " \
"restrictive filter"
print("Found more than one valid endpoint. Use a more "
"restrictive filter")
raise
except KeyError:
raise exceptions.AuthorizationFailure()
except exceptions.EndpointNotFound:
print "Could not find any suitable endpoint. Correct region?"
print("Could not find any suitable endpoint. Correct region?")
raise
elif resp.status_code == 305:

View File

@@ -18,6 +18,8 @@
Command-line interface to the OpenStack Manila API.
"""
from __future__ import print_function
import argparse
import glob
import imp
@@ -427,7 +429,7 @@ class OpenStackManilaShell(object):
commands.remove('bash-completion')
commands.remove('bash_completion')
print ' '.join(commands | options)
print(' '.join(commands | options))
@utils.arg('command', metavar='<subcommand>', nargs='?',
help='Display help for <subcommand>')
@@ -455,14 +457,14 @@ def main():
try:
OpenStackManilaShell().main(map(strutils.safe_decode, sys.argv[1:]))
except KeyboardInterrupt:
print >> sys.stderr, "... terminating manila client"
print("... terminating manila client", file=sys.stderr)
sys.exit(130)
except Exception, e:
except Exception as e:
logger.debug(e, exc_info=1)
message = e.message
if not isinstance(message, basestring):
message = str(message)
print >> sys.stderr, "ERROR: %s" % strutils.safe_encode(message)
print("ERROR: %s" % strutils.safe_encode(message), file=sys.stderr)
sys.exit(1)

View File

@@ -1,3 +1,5 @@
from __future__ import print_function
import os
import sys
import uuid
@@ -142,14 +144,14 @@ def print_list(objs, fields, formatters={}):
row.append(data)
pt.add_row(row)
print strutils.safe_encode(pt.get_string(sortby=fields[0]))
print(strutils.safe_encode(pt.get_string(sortby=fields[0])))
def print_dict(d, property="Property"):
pt = prettytable.PrettyTable([property, 'Value'], caching=False)
pt.aligns = ['l', 'l']
[pt.add_row(list(r)) for r in d.iteritems()]
print strutils.safe_encode(pt.get_string(sortby=property))
print(strutils.safe_encode(pt.get_string(sortby=property)))
def find_resource(manager, name_or_id):

View File

@@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import print_function
import os
import sys
import time
@@ -35,17 +37,17 @@ def _poll_for_status(poll_fn, obj_id, action, final_ok_states,
sys.stdout.write(msg)
sys.stdout.flush()
print
print()
while True:
obj = poll_fn(obj_id)
status = obj.status.lower()
progress = getattr(obj, 'progress', None) or 0
if status in final_ok_states:
print_progress(100)
print "\nFinished"
print("\nFinished")
break
elif status == "error":
print "\nError %(action)s instance" % locals()
print("\nError %(action)s instance" % locals())
break
else:
print_progress(progress)

View File

@@ -6,6 +6,8 @@ wrong the tests might raise AssertionError. I've indicated in comments the
places where actual behavior differs from the spec.
"""
from __future__ import print_function
def assert_has_keys(dict, required=[], optional=[]):
keys = dict.keys()
@@ -54,9 +56,9 @@ class FakeClient(object):
try:
assert entry[2] == body
except AssertionError:
print entry[2]
print "!="
print body
print(entry[2])
print("!=")
print(body)
raise
self.client.callstack = []

View File

@@ -105,9 +105,9 @@ class ServiceCatalogTest(utils.TestCase):
self.assertRaises(exceptions.AmbiguousEndpoints, sc.url_for,
service_type='compute')
self.assertEquals(sc.url_for('tenantId', '1', service_type='compute'),
self.assertEqual(sc.url_for('tenantId', '1', service_type='compute'),
"https://compute1.host/v1/1234")
self.assertEquals(sc.url_for('tenantId', '2', service_type='compute'),
self.assertEqual(sc.url_for('tenantId', '2', service_type='compute'),
"https://compute1.host/v1/3456")
self.assertRaises(exceptions.EndpointNotFound, sc.url_for,
@@ -118,10 +118,10 @@ class ServiceCatalogTest(utils.TestCase):
self.assertRaises(exceptions.AmbiguousEndpoints, sc.url_for,
service_type='share')
self.assertEquals(sc.url_for('tenantId', '1', service_type='share'),
"https://share1.host/v1/1234")
self.assertEquals(sc.url_for('tenantId', '2', service_type='share'),
"https://share1.host/v1/3456")
self.assertEqual(sc.url_for('tenantId', '1', service_type='share'),
"https://share1.host/v1/1234")
self.assertEqual(sc.url_for('tenantId', '2', service_type='share'),
"https://share1.host/v1/3456")
self.assertRaises(exceptions.EndpointNotFound, sc.url_for,
"region", "North", service_type='share')

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
from manilaclient.v1 import client
from tests.v1 import fake_clients as fakes
@@ -56,8 +58,7 @@ class FakeHTTPClient(fakes.FakeHTTPClient):
return (resp, {}, _body)
def get_snapshots_detail(self, **kw):
print kw
# print kw['share_id']
print(kw)
snapshots = {'snapshots': [{
'id': 1234,
'created_at': '2012-08-27T00:00:00.000000',

View File

@@ -22,6 +22,8 @@
Installation script for Nova's development virtualenv
"""
from __future__ import print_function
import optparse
import os
import subprocess
@@ -36,7 +38,7 @@ PY_VERSION = "python%s.%s" % (sys.version_info[0], sys.version_info[1])
def die(message, *args):
print >> sys.stderr, message % args
print(message % args, file=sys.stderr)
sys.exit(1)
@@ -77,12 +79,12 @@ class Distro(object):
return
if self.check_cmd('easy_install'):
print 'Installing virtualenv via easy_install...',
print('Installing virtualenv via easy_install...', end=' ')
if run_command(['easy_install', 'virtualenv']):
print 'Succeeded'
print('Succeeded')
return
else:
print 'Failed'
print('Failed')
die('ERROR: virtualenv not found.\n\nDevelopment'
' requires virtualenv, please install it using your'
@@ -164,17 +166,17 @@ def create_virtualenv(venv=VENV, no_site_packages=True):
"""Creates the virtual environment and installs PIP only into the
virtual environment
"""
print 'Creating venv...',
print('Creating venv...', end=' ')
if no_site_packages:
run_command(['virtualenv', '-q', '--no-site-packages', VENV])
else:
run_command(['virtualenv', '-q', VENV])
print 'done.'
print 'Installing pip in virtualenv...',
print('done.')
print('Installing pip in virtualenv...', end=' ')
if not run_command(['tools/with_venv.sh', 'easy_install',
'pip>1.0']).strip():
die("Failed to install pip.")
print 'done.'
print('done.')
def pip_install(*args):
@@ -184,7 +186,7 @@ def pip_install(*args):
def install_dependencies(venv=VENV):
print 'Installing dependencies with pip (this can take a while)...'
print('Installing dependencies with pip (this can take a while)...')
# First things first, make sure our venv has the latest pip and distribute.
pip_install('pip')
@@ -222,7 +224,7 @@ def print_help():
Also, make test will automatically use the virtualenv.
"""
print help
print(help)
def parse_args():

View File

@@ -28,6 +28,6 @@ commands = python setup.py testr --coverage --testr-args='{posargs}'
downloadcache = ~/cache/pip
[flake8]
ignore = E12,H102,H23,H501,F811,F821
ignore = E12,H102,H501,F811,F821
builtins = _
exclude = .venv,.tox,dist,doc,openstack,*egg