From de2e5aa462a9515ac228690b68b84af5974db1ea Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sun, 28 Apr 2013 18:32:12 -0700 Subject: [PATCH] Update to flake8 instead of pep8. Change-Id: I3d4a31111c3044da06611405ce80f208ef8a0ce3 --- bin/swift-account-audit | 34 ++++++++++++++++++--------------- bin/swift-dispersion-populate | 1 - bin/swift-dispersion-report | 1 - bin/swift-drive-audit | 2 +- bin/swift-object-info | 1 - bin/swift-oldies | 2 -- bin/swift-ring-builder | 4 ++-- swift/proxy/controllers/base.py | 6 +++--- tools/test-requires | 6 +++++- tox.ini | 11 ++++++++--- 10 files changed, 38 insertions(+), 30 deletions(-) diff --git a/bin/swift-account-audit b/bin/swift-account-audit index be10cc01cd..179bdade2d 100755 --- a/bin/swift-account-audit +++ b/bin/swift-account-audit @@ -161,7 +161,6 @@ class Auditor(object): marker = '' results = True while results: - node_id = node['id'] try: conn = http_connect(node['ip'], node['port'], node['device'], part, 'GET', @@ -310,34 +309,39 @@ class Auditor(object): self.pool.waitall() def print_stats(self): + + def _print_stat(name, stat): + # Right align stat name in a field of 18 characters + print "{0:>18}: {1}".format(name, stat) + print - print " Accounts checked: %d" % self.accounts_checked + _print_stat("Accounts checked", self.accounts_checked) if self.account_not_found: - print " Missing Replicas: %d" % self.account_not_found + _print_stat("Missing Replicas", self.account_not_found) if self.account_exceptions: - print " Exceptions: %d" % self.account_exceptions + _print_stat("Exceptions", self.account_exceptions) if self.account_container_mismatch: - print "Container mismatch: %d" % self.account_container_mismatch + _print_stat("Container mismatch", self.account_container_mismatch) if self.account_object_mismatch: - print " Object mismatch: %d" % self.account_object_mismatch + _print_stat("Object mismatch", self.account_object_mismatch) print - print "Containers checked: %d" % self.containers_checked + _print_stat("Containers checked", self.containers_checked) if self.container_not_found: - print " Missing Replicas: %d" % self.container_not_found + _print_stat("Missing Replicas", self.container_not_found) if self.container_exceptions: - print " Exceptions: %d" % self.container_exceptions + _print_stat("Exceptions", self.container_exceptions) if self.container_count_mismatch: - print " Count mismatch: %d" % self.container_count_mismatch + _print_stat("Count mismatch", self.container_count_mismatch) if self.container_obj_mismatch: - print " Object mismatch: %d" % self.container_obj_mismatch + _print_stat("Object mismatch", self.container_obj_mismatch) print - print " Objects checked: %d" % self.objects_checked + _print_stat("Objects checked", self.objects_checked) if self.object_not_found: - print " Missing Replicas: %d" % self.object_not_found + _print_stat("Missing Replicas", self.object_not_found) if self.object_exceptions: - print " Exceptions: %d" % self.object_exceptions + _print_stat("Exceptions", self.object_exceptions) if self.object_checksum_mismatch: - print " MD5 Mismatch: %d" % self.object_checksum_mismatch + _print_stat("MD5 Mismatch", self.object_checksum_mismatch) if __name__ == '__main__': diff --git a/bin/swift-dispersion-populate b/bin/swift-dispersion-populate index 0e3142956f..324c6442df 100755 --- a/bin/swift-dispersion-populate +++ b/bin/swift-dispersion-populate @@ -14,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import traceback from ConfigParser import ConfigParser from cStringIO import StringIO diff --git a/bin/swift-dispersion-report b/bin/swift-dispersion-report index 21e3f0669c..f2d864b54e 100755 --- a/bin/swift-dispersion-report +++ b/bin/swift-dispersion-report @@ -14,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os from ConfigParser import ConfigParser from optparse import OptionParser from sys import exit, stdout, stderr diff --git a/bin/swift-drive-audit b/bin/swift-drive-audit index dc5d265db8..46ddcb2722 100755 --- a/bin/swift-drive-audit +++ b/bin/swift-drive-audit @@ -44,7 +44,7 @@ def get_devices(device_dir, logger): device['block_device'] = block_device try: device_num = os.stat(block_device).st_rdev - except OSError, e: + except OSError: # If we can't stat the device, then something weird is going on logger.error("Error: Could not stat %s!" % block_device) diff --git a/bin/swift-object-info b/bin/swift-object-info index bf612cc5b7..3ecd1ced2d 100755 --- a/bin/swift-object-info +++ b/bin/swift-object-info @@ -15,7 +15,6 @@ # limitations under the License. import sys -import cPickle as pickle from datetime import datetime from hashlib import md5 diff --git a/bin/swift-oldies b/bin/swift-oldies index 15f34e5281..4012ba7811 100755 --- a/bin/swift-oldies +++ b/bin/swift-oldies @@ -1,8 +1,6 @@ #!/usr/bin/env python import optparse -import os -import signal import subprocess import sys diff --git a/bin/swift-ring-builder b/bin/swift-ring-builder index 8187c6d571..9ac6b3c2cd 100755 --- a/bin/swift-ring-builder +++ b/bin/swift-ring-builder @@ -91,8 +91,8 @@ swift-ring-builder if d is not None)) zones = len(set((d['region'], d['zone']) for d in builder.devs if d is not None)) - dev_count = len([d for d in builder.devs - if d is not None]) + dev_count = len([dev for dev in builder.devs + if dev is not None]) balance = builder.get_balance() print '%d partitions, %.6f replicas, %d regions, %d zones, ' \ '%d devices, %.02f balance' % (builder.parts, builder.replicas, diff --git a/swift/proxy/controllers/base.py b/swift/proxy/controllers/base.py index f577eaa322..006514ed05 100644 --- a/swift/proxy/controllers/base.py +++ b/swift/proxy/controllers/base.py @@ -183,9 +183,9 @@ def cors_validation(func): expose_headers.append(header.lower()) if cors_info.get('expose_headers'): expose_headers.extend( - [a.strip() - for a in cors_info['expose_headers'].split(' ') - if a.strip()]) + [header_line.strip() + for header_line in cors_info['expose_headers'].split(' ') + if header_line.strip()]) resp.headers['Access-Control-Expose-Headers'] = \ ', '.join(expose_headers) diff --git a/tools/test-requires b/tools/test-requires index 01c80d919f..c2b0d7a836 100644 --- a/tools/test-requires +++ b/tools/test-requires @@ -1,8 +1,12 @@ +# Install bounded pep8/pyflakes first, then let flake8 install +pep8==1.4.5 +pyflakes==0.7.2 +flake8==2.0 + coverage nose nosexcover openstack.nose_plugin nosehtmloutput -pep8==1.3.3 sphinx>=1.1.2 mock>=0.8.0 diff --git a/tox.ini b/tox.ini index 004958cc49..c6e6131096 100644 --- a/tox.ini +++ b/tox.ini @@ -18,13 +18,18 @@ commands = nosetests test/unit {posargs} downloadcache = ~/cache/pip [testenv:pep8] -deps = pep8==1.3.3 commands = - pep8 --repeat --show-source --exclude=.venv,.tox,dist,doc,test . - pep8 --repeat --show-pep8 --show-source --filename=swift* bin + flake8 + flake8 --filename=swift* bin [testenv:cover] setenv = NOSE_WITH_COVERAGE=1 [testenv:venv] commands = {posargs} + +[flake8] +ignore = H +builtins = _ +exclude = .venv,.tox,dist,doc,test,*egg +show-source = True