From 8aba2d602ef913ebdcaebd46510324299dfc3e39 Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Thu, 20 Jun 2013 20:36:59 +0200 Subject: [PATCH] Start using Hacking Instead of blacklisting Hacking globally, only blacklist those that currently occur frequently (for a later followup patch), and fix the rest. In detail: H101 Use TODO(NAME) H201 no 'except:' at least use 'except Exception:' H231 octal number 022 should be written as 0o22 H401 docstring should not start with a space H701 Empty localization string Change-Id: Ib3b3d56b68d1cf15d3b67ac9749fcbdb876dc52a --- bin/swift-recon | 2 +- bin/swift-recon-cron | 2 +- swift/account/reaper.py | 10 +++++----- swift/common/__init__.py | 2 +- swift/common/db.py | 4 ++-- swift/common/manager.py | 2 +- swift/common/memcached.py | 2 +- swift/common/middleware/account_quotas.py | 2 +- swift/common/middleware/formpost.py | 2 +- swift/common/middleware/keystoneauth.py | 2 +- swift/common/middleware/staticweb.py | 2 +- swift/common/middleware/tempurl.py | 2 +- swift/common/utils.py | 6 +++--- swift/common/wsgi.py | 10 +++++----- swift/obj/server.py | 2 +- swift/obj/updater.py | 2 +- swift/proxy/controllers/obj.py | 4 ++-- test-requirements.txt | 2 +- tox.ini | 2 +- 19 files changed, 31 insertions(+), 31 deletions(-) diff --git a/bin/swift-recon b/bin/swift-recon index 5c82e1bfa4..62f18aa275 100755 --- a/bin/swift-recon +++ b/bin/swift-recon @@ -101,7 +101,7 @@ class SwiftRecon(object): self.server_type = 'object' def _gen_stats(self, stats, name=None): - """ compute various stats from a list of values """ + """Compute various stats from a list of values.""" cstats = [x for x in stats if x is not None] if len(cstats) > 0: ret_dict = {'low': min(cstats), 'high': max(cstats), diff --git a/bin/swift-recon-cron b/bin/swift-recon-cron index d8cb010780..1924c4776c 100755 --- a/bin/swift-recon-cron +++ b/bin/swift-recon-cron @@ -43,7 +43,7 @@ def main(): try: os.mkdir(lock_dir) except OSError as e: - logger.critical(_(str(e))) + logger.critical(str(e)) print str(e) sys.exit(1) try: diff --git a/swift/account/reaper.py b/swift/account/reaper.py index 790b8663b0..d65323cd01 100644 --- a/swift/account/reaper.py +++ b/swift/account/reaper.py @@ -76,26 +76,26 @@ class AccountReaper(Daemon): self.reap_not_done_after = reap_warn_after + self.delay_reaping def get_account_ring(self): - """ The account :class:`swift.common.ring.Ring` for the cluster. """ + """The account :class:`swift.common.ring.Ring` for the cluster.""" if not self.account_ring: self.account_ring = Ring(self.swift_dir, ring_name='account') return self.account_ring def get_container_ring(self): - """ The container :class:`swift.common.ring.Ring` for the cluster. """ + """The container :class:`swift.common.ring.Ring` for the cluster.""" if not self.container_ring: self.container_ring = Ring(self.swift_dir, ring_name='container') return self.container_ring def get_object_ring(self): - """ The object :class:`swift.common.ring.Ring` for the cluster. """ + """The object :class:`swift.common.ring.Ring` for the cluster.""" if not self.object_ring: self.object_ring = Ring(self.swift_dir, ring_name='object') return self.object_ring def run_forever(self, *args, **kwargs): - """ - Main entry point when running the reaper in its normal daemon mode. + """Main entry point when running the reaper in normal daemon mode. + This repeatedly calls :func:`reap_once` no quicker than the configuration interval. """ diff --git a/swift/common/__init__.py b/swift/common/__init__.py index 880a66aa87..56aa6012d4 100644 --- a/swift/common/__init__.py +++ b/swift/common/__init__.py @@ -1 +1 @@ -""" Code common to all of Swift. """ +"""Code common to all of Swift.""" diff --git a/swift/common/db.py b/swift/common/db.py index da38599aea..de140bdf1c 100644 --- a/swift/common/db.py +++ b/swift/common/db.py @@ -173,7 +173,7 @@ class DatabaseBroker(object): def __init__(self, db_file, timeout=BROKER_TIMEOUT, logger=None, account=None, container=None, pending_timeout=10, stale_reads_ok=False): - """ Encapsulates working with a database. """ + """Encapsulates working with a database.""" self.conn = None self.db_file = db_file self.pending_file = self.db_file + '.pending' @@ -332,7 +332,7 @@ class DatabaseBroker(object): except sqlite3.DatabaseError: try: conn.close() - except: + except Exception: pass self.possibly_quarantine(*sys.exc_info()) except (Exception, Timeout): diff --git a/swift/common/manager.py b/swift/common/manager.py index cb01430008..3328731709 100644 --- a/swift/common/manager.py +++ b/swift/common/manager.py @@ -611,7 +611,7 @@ class Server(): pid = self.spawn(conf_file, **kwargs) except OSError, e: if e.errno == errno.ENOENT: - # TODO: should I check if self.cmd exists earlier? + #TODO(clayg): should I check if self.cmd exists earlier? print _("%s does not exist") % self.cmd break pids[pid] = conf_file diff --git a/swift/common/memcached.py b/swift/common/memcached.py index 03ab5e235a..fd468b6a46 100644 --- a/swift/common/memcached.py +++ b/swift/common/memcached.py @@ -178,7 +178,7 @@ class MemcacheRing(object): server, e, action='connecting', sock=sock) def _return_conn(self, server, fp, sock): - """ Returns a server connection to the pool """ + """Returns a server connection to the pool.""" self._client_cache[server].append((fp, sock)) def set(self, key, value, serialize=True, timeout=0, time=0, diff --git a/swift/common/middleware/account_quotas.py b/swift/common/middleware/account_quotas.py index 633a686800..ced16d27df 100644 --- a/swift/common/middleware/account_quotas.py +++ b/swift/common/middleware/account_quotas.py @@ -53,7 +53,7 @@ from swift.proxy.controllers.base import get_account_info class AccountQuotaMiddleware(object): - """ Account quota middleware + """Account quota middleware See above for a full description. diff --git a/swift/common/middleware/formpost.py b/swift/common/middleware/formpost.py index c68fe6d4bb..05311a97e0 100644 --- a/swift/common/middleware/formpost.py +++ b/swift/common/middleware/formpost.py @@ -481,7 +481,7 @@ class FormPost(object): def filter_factory(global_conf, **local_conf): - """ Returns the WSGI filter for use with paste.deploy. """ + """Returns the WSGI filter for use with paste.deploy.""" conf = global_conf.copy() conf.update(local_conf) return lambda app: FormPost(app, conf) diff --git a/swift/common/middleware/keystoneauth.py b/swift/common/middleware/keystoneauth.py index 367192b4fc..5c09c85ad7 100644 --- a/swift/common/middleware/keystoneauth.py +++ b/swift/common/middleware/keystoneauth.py @@ -155,7 +155,7 @@ class KeystoneAuth(object): def _authorize_cross_tenant(self, user_id, user_name, tenant_id, tenant_name, roles): - """ Check cross-tenant ACLs + """Check cross-tenant ACLs. Match tenant:user, tenant and user could be its id, name or '*' diff --git a/swift/common/middleware/staticweb.py b/swift/common/middleware/staticweb.py index 18924f6465..f63bab62e1 100644 --- a/swift/common/middleware/staticweb.py +++ b/swift/common/middleware/staticweb.py @@ -474,7 +474,7 @@ class StaticWeb(object): def filter_factory(global_conf, **local_conf): - """ Returns a Static Web WSGI filter for use with paste.deploy. """ + """Returns a Static Web WSGI filter for use with paste.deploy.""" conf = global_conf.copy() conf.update(local_conf) diff --git a/swift/common/middleware/tempurl.py b/swift/common/middleware/tempurl.py index 11ab896af5..4182e313e0 100644 --- a/swift/common/middleware/tempurl.py +++ b/swift/common/middleware/tempurl.py @@ -481,7 +481,7 @@ class TempURL(object): def filter_factory(global_conf, **local_conf): - """ Returns the WSGI filter for use with paste.deploy. """ + """Returns the WSGI filter for use with paste.deploy.""" conf = global_conf.copy() conf.update(local_conf) return lambda app: TempURL(app, conf) diff --git a/swift/common/utils.py b/swift/common/utils.py index 77a651cd90..b0f5abd1a5 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -335,7 +335,7 @@ class FallocateWrapper(object): "libc. Leaving as a no-op.")) def __call__(self, fd, mode, offset, length): - """ The length parameter must be a ctypes.c_uint64 """ + """The length parameter must be a ctypes.c_uint64.""" if FALLOCATE_RESERVE > 0: st = os.fstatvfs(fd) free = st.f_frsize * st.f_bavail - length.value @@ -1019,8 +1019,8 @@ def drop_privileges(user): os.setsid() except OSError: pass - os.chdir('/') # in case you need to rmdir on where you started the daemon - os.umask(022) # ensure files are created with the correct privileges + os.chdir('/') # in case you need to rmdir on where you started the daemon + os.umask(0o22) # ensure files are created with the correct privileges def capture_stdio(logger, **kwargs): diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index 891183a7a9..f5a735394d 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -165,11 +165,11 @@ def get_socket(conf, default_port=8080): if hasattr(socket, 'TCP_KEEPIDLE'): sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 600) if warn_ssl: - ssl_warning_message = 'WARNING: SSL should only be enabled for ' \ - 'testing purposes. Use external SSL ' \ - 'termination for a production deployment.' + ssl_warning_message = _('WARNING: SSL should only be enabled for ' + 'testing purposes. Use external SSL ' + 'termination for a production deployment.') get_logger(conf).warning(ssl_warning_message) - print _(ssl_warning_message) + print(ssl_warning_message) return sock @@ -224,7 +224,7 @@ def run_server(conf, logger, sock): pool.waitall() -# TODO: pull more pieces of this to test more +#TODO(clayg): pull more pieces of this to test more def run_wsgi(conf_path, app_section, *args, **kwargs): """ Runs the server using the specified number of workers. diff --git a/swift/obj/server.py b/swift/obj/server.py index 7dac34d8b3..08d665c646 100644 --- a/swift/obj/server.py +++ b/swift/obj/server.py @@ -528,7 +528,7 @@ class ObjectController(object): int(conf.get('expiring_objects_container_divisor') or 86400) def _diskfile(self, device, partition, account, container, obj, **kwargs): - """ Utility method for instantiating a DiskFile. """ + """Utility method for instantiating a DiskFile.""" kwargs.setdefault('bytes_per_sync', self.bytes_per_sync) kwargs.setdefault('disk_chunk_size', self.disk_chunk_size) kwargs.setdefault('logger', self.logger) diff --git a/swift/obj/updater.py b/swift/obj/updater.py index 4fdd02eb97..5fad8754c2 100644 --- a/swift/obj/updater.py +++ b/swift/obj/updater.py @@ -107,7 +107,7 @@ class ObjectUpdater(Daemon): time.sleep(self.interval - elapsed) def run_once(self, *args, **kwargs): - """Run the updater once""" + """Run the updater once.""" self.logger.info(_('Begin object update single threaded sweep')) begin = time.time() self.successes = 0 diff --git a/swift/proxy/controllers/obj.py b/swift/proxy/controllers/obj.py index 5a0877c6f1..c098bd5978 100644 --- a/swift/proxy/controllers/obj.py +++ b/swift/proxy/controllers/obj.py @@ -266,7 +266,7 @@ class SegmentedIterable(object): return iter(self).next() def __iter__(self): - """ Standard iterator function that returns the object's contents. """ + """Standard iterator function that returns the object's contents.""" try: while True: if not self.segment_iter: @@ -804,7 +804,7 @@ class ObjectController(Controller): return conn elif resp.status == HTTP_INSUFFICIENT_STORAGE: self.error_limit(node, _('ERROR Insufficient Storage')) - except: + except Exception: self.exception_occurred(node, _('Object'), _('Expect: 100-continue on %s') % path) diff --git a/test-requirements.txt b/test-requirements.txt index c2b0d7a836..fdebbb6e4e 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,7 +2,7 @@ pep8==1.4.5 pyflakes==0.7.2 flake8==2.0 - +hacking>=0.5.6,<0.6 coverage nose nosexcover diff --git a/tox.ini b/tox.ini index 03092b8e04..afe2377c72 100644 --- a/tox.ini +++ b/tox.ini @@ -28,7 +28,7 @@ commands = commands = {posargs} [flake8] -ignore = H +ignore = H203,H301,H302,H306,H402,H404,H702,H703 builtins = _ exclude = .venv,.tox,dist,doc,test,*egg show-source = True