Use Python 3.x compatible syntax constructs

Avoid print operator, deprected except and
other things covered by statical checks.

Change-Id: I89f9608b977b2d4567300ec82558284dac347c9a
This commit is contained in:
Dirk Mueller committed 2013-06-23 20:51:36 +02:00
1 parent 70a82b823c
commit 1db5db2dc5
9 files changed
+28 -28

No files matched your search

+1 -1
View File
@@ -109,7 +109,7 @@ class ClientTestBase(tempest.test.BaseTestCase):
else:
with open('/dev/null', 'w') as devnull:
result = self.check_output(cmd, stderr=devnull)
except subprocess.CalledProcessError, e:
except subprocess.CalledProcessError as e:
LOG.error("command output:\n%s" % e.output)
raise
return result
+4 -4
View File
@@ -304,14 +304,14 @@ class VerifiedHTTPSConnection(httplib.HTTPSConnection):
if self.cert_file:
try:
self.context.use_certificate_file(self.cert_file)
except Exception, e:
except Exception as e:
msg = 'Unable to load cert from "%s" %s' % (self.cert_file, e)
raise exc.SSLConfigurationError(msg)
if self.key_file is None:
# We support having key and cert in same file
try:
self.context.use_privatekey_file(self.cert_file)
except Exception, e:
except Exception as e:
msg = ('No key file specified and unable to load key '
'from "%s" %s' % (self.cert_file, e))
raise exc.SSLConfigurationError(msg)
@@ -319,14 +319,14 @@ class VerifiedHTTPSConnection(httplib.HTTPSConnection):
if self.key_file:
try:
self.context.use_privatekey_file(self.key_file)
except Exception, e:
except Exception as e:
msg = 'Unable to load key from "%s" %s' % (self.key_file, e)
raise exc.SSLConfigurationError(msg)
if self.cacert:
try:
self.context.load_verify_locations(self.cacert)
except Exception, e:
except Exception as e:
msg = 'Unable to load CA from "%s"' % (self.cacert, e)
raise exc.SSLConfigurationError(msg)
else:
+1 -1
View File
@@ -55,7 +55,7 @@ def _load_log_config():
log_config = os.path.join(conf_dir, conf_file)
try:
logging.config.fileConfig(log_config)
except ConfigParser.Error, exc:
except ConfigParser.Error as exc:
raise cfg.ConfigFileParseError(log_config, str(exc))
return True
+2 -2
View File
@@ -144,8 +144,8 @@ class RestClient(object):
try:
auth_data = json.loads(resp_body)['access']
token = auth_data['token']['id']
except Exception, e:
print "Failed to obtain token for user: %s" % e
except Exception as e:
print("Failed to obtain token for user: %s" % e)
raise
mgmt_url = None
@@ -88,7 +88,7 @@ class ImageClientJSON(RestClient):
obj_size = obj.tell()
obj.seek(0)
return obj_size
except IOError, e:
except IOError as e:
if e.errno == errno.ESPIPE:
# Illegal seek. This means the user is trying
# to pipe image data to the client, e.g.
+1 -1
View File
@@ -128,7 +128,7 @@ class ComputeWhiteboxTest(test.ComputeFuzzClientTest, WhiteboxTest):
meta = MetaData()
meta.reflect(bind=engine)
except Exception, e:
except Exception as e:
raise exceptions.SQLException(message=e)
return connection, meta
+6 -6
View File
@@ -110,7 +110,7 @@ def collect_logs(url):
def usage():
print """
print("""
Usage: find_stack_traces.py <logurl>
Hunts for stack traces in a devstack run. Must provide it a base log url
@@ -118,20 +118,20 @@ from a tempest devstack run. Should start with http and end with /logs/.
Returns a report listing stack traces out of the various files where
they are found.
"""
""")
sys.exit(0)
def print_stats(items, fname, verbose=False):
errors = len(filter(lambda x: x.level == "ERROR", items))
traces = len(filter(lambda x: x.level == "TRACE", items))
print "%d ERRORS found in %s" % (errors, fname)
print "%d TRACES found in %s" % (traces, fname)
print("%d ERRORS found in %s" % (errors, fname))
print("%d TRACES found in %s" % (traces, fname))
if verbose:
for item in items:
print item
print "\n\n"
print(item)
print("\n\n")
def main():
+4 -4
View File
@@ -118,8 +118,8 @@ if __name__ == '__main__':
unskips = sorted(set(unskips))
if unskips:
print "The following bugs have been fixed and the corresponding skips"
print "should be removed from the test cases:"
print
print("The following bugs have been fixed and the corresponding skips")
print("should be removed from the test cases:")
print()
for bug in unskips:
print " %7s" % bug
print(" %7s" % bug)
+8 -8
View File
@@ -12,7 +12,7 @@
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License
# under the License.
import json
import os
@@ -151,14 +151,14 @@ def main(argv):
elif CLI.command == 'stop':
resp, body = coverage_client.stop_coverage()
if not resp['status'] == '200':
print 'coverage stop failed with: %s:' % (resp['status'] + ': '
+ body)
print('coverage stop failed with: %s:' % (resp['status'] + ': '
+ body))
exit(int(resp['status']))
path = body['path']
if CLI.output:
shutil.copytree(path, CLI.output)
else:
print "Data files located at: %s" % path
print("Data files located at: %s" % path)
elif CLI.command == 'report':
if CLI.xml:
@@ -169,8 +169,8 @@ def main(argv):
else:
resp, body = coverage_client.report_coverage(file=CLI.filename)
if not resp['status'] == '200':
print 'coverage report failed with: %s:' % (resp['status'] + ': '
+ body)
print('coverage report failed with: %s:' % (resp['status'] + ': '
+ body))
exit(int(resp['status']))
path = body['path']
if CLI.output:
@@ -182,10 +182,10 @@ def main(argv):
else:
if not CLI.html:
path = os.path.dirname(path)
print 'Report files located at: %s' % path
print('Report files located at: %s' % path)
else:
print 'Invalid command'
print('Invalid command')
exit(1)