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
This commit is contained in:
Dirk Mueller 2013-06-20 20:36:59 +02:00
parent cbc29e43be
commit 8aba2d602e
19 changed files with 31 additions and 31 deletions

View File

@ -101,7 +101,7 @@ class SwiftRecon(object):
self.server_type = 'object' self.server_type = 'object'
def _gen_stats(self, stats, name=None): 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] cstats = [x for x in stats if x is not None]
if len(cstats) > 0: if len(cstats) > 0:
ret_dict = {'low': min(cstats), 'high': max(cstats), ret_dict = {'low': min(cstats), 'high': max(cstats),

View File

@ -43,7 +43,7 @@ def main():
try: try:
os.mkdir(lock_dir) os.mkdir(lock_dir)
except OSError as e: except OSError as e:
logger.critical(_(str(e))) logger.critical(str(e))
print str(e) print str(e)
sys.exit(1) sys.exit(1)
try: try:

View File

@ -76,26 +76,26 @@ class AccountReaper(Daemon):
self.reap_not_done_after = reap_warn_after + self.delay_reaping self.reap_not_done_after = reap_warn_after + self.delay_reaping
def get_account_ring(self): 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: if not self.account_ring:
self.account_ring = Ring(self.swift_dir, ring_name='account') self.account_ring = Ring(self.swift_dir, ring_name='account')
return self.account_ring return self.account_ring
def get_container_ring(self): 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: if not self.container_ring:
self.container_ring = Ring(self.swift_dir, ring_name='container') self.container_ring = Ring(self.swift_dir, ring_name='container')
return self.container_ring return self.container_ring
def get_object_ring(self): 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: if not self.object_ring:
self.object_ring = Ring(self.swift_dir, ring_name='object') self.object_ring = Ring(self.swift_dir, ring_name='object')
return self.object_ring return self.object_ring
def run_forever(self, *args, **kwargs): def run_forever(self, *args, **kwargs):
""" """Main entry point when running the reaper in normal daemon mode.
Main entry point when running the reaper in its normal daemon mode.
This repeatedly calls :func:`reap_once` no quicker than the This repeatedly calls :func:`reap_once` no quicker than the
configuration interval. configuration interval.
""" """

View File

@ -1 +1 @@
""" Code common to all of Swift. """ """Code common to all of Swift."""

View File

@ -173,7 +173,7 @@ class DatabaseBroker(object):
def __init__(self, db_file, timeout=BROKER_TIMEOUT, logger=None, def __init__(self, db_file, timeout=BROKER_TIMEOUT, logger=None,
account=None, container=None, pending_timeout=10, account=None, container=None, pending_timeout=10,
stale_reads_ok=False): stale_reads_ok=False):
""" Encapsulates working with a database. """ """Encapsulates working with a database."""
self.conn = None self.conn = None
self.db_file = db_file self.db_file = db_file
self.pending_file = self.db_file + '.pending' self.pending_file = self.db_file + '.pending'
@ -332,7 +332,7 @@ class DatabaseBroker(object):
except sqlite3.DatabaseError: except sqlite3.DatabaseError:
try: try:
conn.close() conn.close()
except: except Exception:
pass pass
self.possibly_quarantine(*sys.exc_info()) self.possibly_quarantine(*sys.exc_info())
except (Exception, Timeout): except (Exception, Timeout):

View File

@ -611,7 +611,7 @@ class Server():
pid = self.spawn(conf_file, **kwargs) pid = self.spawn(conf_file, **kwargs)
except OSError, e: except OSError, e:
if e.errno == errno.ENOENT: 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 print _("%s does not exist") % self.cmd
break break
pids[pid] = conf_file pids[pid] = conf_file

View File

@ -178,7 +178,7 @@ class MemcacheRing(object):
server, e, action='connecting', sock=sock) server, e, action='connecting', sock=sock)
def _return_conn(self, server, fp, 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)) self._client_cache[server].append((fp, sock))
def set(self, key, value, serialize=True, timeout=0, time=0, def set(self, key, value, serialize=True, timeout=0, time=0,

View File

@ -53,7 +53,7 @@ from swift.proxy.controllers.base import get_account_info
class AccountQuotaMiddleware(object): class AccountQuotaMiddleware(object):
""" Account quota middleware """Account quota middleware
See above for a full description. See above for a full description.

View File

@ -481,7 +481,7 @@ class FormPost(object):
def filter_factory(global_conf, **local_conf): 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 = global_conf.copy()
conf.update(local_conf) conf.update(local_conf)
return lambda app: FormPost(app, conf) return lambda app: FormPost(app, conf)

View File

@ -155,7 +155,7 @@ class KeystoneAuth(object):
def _authorize_cross_tenant(self, user_id, user_name, def _authorize_cross_tenant(self, user_id, user_name,
tenant_id, tenant_name, roles): 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 '*' Match tenant:user, tenant and user could be its id, name or '*'

View File

@ -474,7 +474,7 @@ class StaticWeb(object):
def filter_factory(global_conf, **local_conf): 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 = global_conf.copy()
conf.update(local_conf) conf.update(local_conf)

View File

@ -481,7 +481,7 @@ class TempURL(object):
def filter_factory(global_conf, **local_conf): 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 = global_conf.copy()
conf.update(local_conf) conf.update(local_conf)
return lambda app: TempURL(app, conf) return lambda app: TempURL(app, conf)

View File

@ -335,7 +335,7 @@ class FallocateWrapper(object):
"libc. Leaving as a no-op.")) "libc. Leaving as a no-op."))
def __call__(self, fd, mode, offset, length): 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: if FALLOCATE_RESERVE > 0:
st = os.fstatvfs(fd) st = os.fstatvfs(fd)
free = st.f_frsize * st.f_bavail - length.value free = st.f_frsize * st.f_bavail - length.value
@ -1019,8 +1019,8 @@ def drop_privileges(user):
os.setsid() os.setsid()
except OSError: except OSError:
pass pass
os.chdir('/') # in case you need to rmdir on where you started the daemon 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.umask(0o22) # ensure files are created with the correct privileges
def capture_stdio(logger, **kwargs): def capture_stdio(logger, **kwargs):

View File

@ -165,11 +165,11 @@ def get_socket(conf, default_port=8080):
if hasattr(socket, 'TCP_KEEPIDLE'): if hasattr(socket, 'TCP_KEEPIDLE'):
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 600) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 600)
if warn_ssl: if warn_ssl:
ssl_warning_message = 'WARNING: SSL should only be enabled for ' \ ssl_warning_message = _('WARNING: SSL should only be enabled for '
'testing purposes. Use external SSL ' \ 'testing purposes. Use external SSL '
'termination for a production deployment.' 'termination for a production deployment.')
get_logger(conf).warning(ssl_warning_message) get_logger(conf).warning(ssl_warning_message)
print _(ssl_warning_message) print(ssl_warning_message)
return sock return sock
@ -224,7 +224,7 @@ def run_server(conf, logger, sock):
pool.waitall() 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): def run_wsgi(conf_path, app_section, *args, **kwargs):
""" """
Runs the server using the specified number of workers. Runs the server using the specified number of workers.

View File

@ -528,7 +528,7 @@ class ObjectController(object):
int(conf.get('expiring_objects_container_divisor') or 86400) int(conf.get('expiring_objects_container_divisor') or 86400)
def _diskfile(self, device, partition, account, container, obj, **kwargs): 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('bytes_per_sync', self.bytes_per_sync)
kwargs.setdefault('disk_chunk_size', self.disk_chunk_size) kwargs.setdefault('disk_chunk_size', self.disk_chunk_size)
kwargs.setdefault('logger', self.logger) kwargs.setdefault('logger', self.logger)

View File

@ -107,7 +107,7 @@ class ObjectUpdater(Daemon):
time.sleep(self.interval - elapsed) time.sleep(self.interval - elapsed)
def run_once(self, *args, **kwargs): def run_once(self, *args, **kwargs):
"""Run the updater once""" """Run the updater once."""
self.logger.info(_('Begin object update single threaded sweep')) self.logger.info(_('Begin object update single threaded sweep'))
begin = time.time() begin = time.time()
self.successes = 0 self.successes = 0

View File

@ -266,7 +266,7 @@ class SegmentedIterable(object):
return iter(self).next() return iter(self).next()
def __iter__(self): def __iter__(self):
""" Standard iterator function that returns the object's contents. """ """Standard iterator function that returns the object's contents."""
try: try:
while True: while True:
if not self.segment_iter: if not self.segment_iter:
@ -804,7 +804,7 @@ class ObjectController(Controller):
return conn return conn
elif resp.status == HTTP_INSUFFICIENT_STORAGE: elif resp.status == HTTP_INSUFFICIENT_STORAGE:
self.error_limit(node, _('ERROR Insufficient Storage')) self.error_limit(node, _('ERROR Insufficient Storage'))
except: except Exception:
self.exception_occurred(node, _('Object'), self.exception_occurred(node, _('Object'),
_('Expect: 100-continue on %s') % path) _('Expect: 100-continue on %s') % path)

View File

@ -2,7 +2,7 @@
pep8==1.4.5 pep8==1.4.5
pyflakes==0.7.2 pyflakes==0.7.2
flake8==2.0 flake8==2.0
hacking>=0.5.6,<0.6
coverage coverage
nose nose
nosexcover nosexcover

View File

@ -28,7 +28,7 @@ commands =
commands = {posargs} commands = {posargs}
[flake8] [flake8]
ignore = H ignore = H203,H301,H302,H306,H402,H404,H702,H703
builtins = _ builtins = _
exclude = .venv,.tox,dist,doc,test,*egg exclude = .venv,.tox,dist,doc,test,*egg
show-source = True show-source = True