From c138ad99a2d1c968de0eda7f2c7368662e9a117d Mon Sep 17 00:00:00 2001 From: gholt Date: Wed, 15 Sep 2010 20:52:54 -0700 Subject: [PATCH] Just a bit of PEP8ing --- swift/account/replicator.py | 1 - swift/account/server.py | 1 + swift/auth/server.py | 1 + swift/common/client.py | 6 +++--- swift/common/daemon.py | 1 + swift/common/direct_client.py | 4 ++-- swift/common/middleware/healthcheck.py | 1 + swift/common/middleware/memcache.py | 3 +++ swift/common/ring/builder.py | 4 ++-- swift/common/utils.py | 4 ++++ swift/common/wsgi.py | 4 ++-- swift/container/replicator.py | 2 +- swift/container/server.py | 1 + swift/obj/replicator.py | 6 +++--- swift/obj/server.py | 1 + swift/proxy/server.py | 3 ++- 16 files changed, 28 insertions(+), 15 deletions(-) diff --git a/swift/account/replicator.py b/swift/account/replicator.py index 6d0ffb9cea..60c409d112 100644 --- a/swift/account/replicator.py +++ b/swift/account/replicator.py @@ -23,4 +23,3 @@ class AccountReplicator(db_replicator.Replicator): brokerclass = db.AccountBroker datadir = account_server.DATADIR default_port = 6002 - diff --git a/swift/account/server.py b/swift/account/server.py index b5e84aa5bc..a1fbdfb06c 100644 --- a/swift/account/server.py +++ b/swift/account/server.py @@ -328,6 +328,7 @@ class AccountController(object): self.logger.info(log_message) return res(env, start_response) + def app_factory(global_conf, **local_conf): """paste.deploy app factory for creating WSGI account server apps""" conf = global_conf.copy() diff --git a/swift/auth/server.py b/swift/auth/server.py index 756f40caeb..e8214db354 100644 --- a/swift/auth/server.py +++ b/swift/auth/server.py @@ -638,6 +638,7 @@ YOU HAVE A FEW OPTIONS: """ Used by the eventlet.wsgi.server """ return self.handleREST(env, start_response) + def app_factory(global_conf, **local_conf): conf = global_conf.copy() conf.update(local_conf) diff --git a/swift/common/client.py b/swift/common/client.py index e17afee958..22562ede37 100644 --- a/swift/common/client.py +++ b/swift/common/client.py @@ -195,7 +195,7 @@ def get_account(url, token, marker=None, limit=None, prefix=None, :param full_listing: if True, return a full listing, else returns a max of 10000 listings :returns: a tuple of (response headers, a list of containers) The response - headers will be a dict and all header names will be lowercase. + headers will be a dict and all header names will be lowercase. :raises ClientException: HTTP GET request failed """ if not http_conn: @@ -310,7 +310,7 @@ def get_container(url, token, container, marker=None, limit=None, :param full_listing: if True, return a full listing, else returns a max of 10000 listings :returns: a tuple of (response headers, a list of objects) The response - headers will be a dict and all header names will be lowercase. + headers will be a dict and all header names will be lowercase. :raises ClientException: HTTP GET request failed """ if not http_conn: @@ -489,7 +489,7 @@ def get_object(url, token, container, name, http_conn=None, the object's contents before making another request. :returns: a tuple of (response headers, the object's contents) The response - headers will be a dict and all header names will be lowercase. + headers will be a dict and all header names will be lowercase. :raises ClientException: HTTP GET request failed """ if http_conn: diff --git a/swift/common/daemon.py b/swift/common/daemon.py index 80d3eff4c7..ffa4fd759d 100644 --- a/swift/common/daemon.py +++ b/swift/common/daemon.py @@ -18,6 +18,7 @@ import sys import signal from swift.common import utils + class Daemon(object): """Daemon base class""" diff --git a/swift/common/direct_client.py b/swift/common/direct_client.py index 71fe3005a4..e17c86ce53 100644 --- a/swift/common/direct_client.py +++ b/swift/common/direct_client.py @@ -89,7 +89,7 @@ def direct_get_container(node, part, account, container, marker=None, :param conn_timeout: timeout in seconds for establishing the connection :param response_timeout: timeout in seconds for getting the response :returns: a tuple of (response headers, a list of objects) The response - headers will be a dict and all header names will be lowercase. + headers will be a dict and all header names will be lowercase. """ path = '/%s/%s' % (account, container) qs = 'format=json' @@ -196,7 +196,7 @@ def direct_get_object(node, part, account, container, obj, conn_timeout=5, :param response_timeout: timeout in seconds for getting the response :param resp_chunk_size: if defined, chunk size of data to read. :returns: a tuple of (response headers, the object's contents) The response - headers will be a dict and all header names will be lowercase. + headers will be a dict and all header names will be lowercase. """ path = '/%s/%s/%s' % (account, container, obj) with Timeout(conn_timeout): diff --git a/swift/common/middleware/healthcheck.py b/swift/common/middleware/healthcheck.py index 3bfc745bc2..e0da092fc3 100644 --- a/swift/common/middleware/healthcheck.py +++ b/swift/common/middleware/healthcheck.py @@ -37,6 +37,7 @@ class HealthCheckMiddleware(object): else: return self.app(env, start_response) + def filter_factory(global_conf, **local_conf): def healthcheck_filter(app): return HealthCheckMiddleware(app) diff --git a/swift/common/middleware/memcache.py b/swift/common/middleware/memcache.py index 8b7030eafa..62cd1bdf03 100644 --- a/swift/common/middleware/memcache.py +++ b/swift/common/middleware/memcache.py @@ -14,10 +14,12 @@ from swift.common.memcached import MemcacheRing + class MemcacheMiddleware(object): """ Caching middleware that manages caching in swift. """ + def __init__(self, app, conf): self.app = app self.memcache = MemcacheRing([s.strip() for s in @@ -28,6 +30,7 @@ class MemcacheMiddleware(object): env['swift.cache'] = self.memcache return self.app(env, start_response) + def filter_factory(global_conf, **local_conf): conf = global_conf.copy() conf.update(local_conf) diff --git a/swift/common/ring/builder.py b/swift/common/ring/builder.py index 46ce76e149..ea1e5a17d3 100644 --- a/swift/common/ring/builder.py +++ b/swift/common/ring/builder.py @@ -104,8 +104,8 @@ class RingBuilder(object): self._ring = RingData([], devs, 32 - self.part_power) else: self._ring = \ - RingData([array('H', p2d) for p2d in self._replica2part2dev], - devs, 32 - self.part_power) + RingData([array('H', p2d) for p2d in self._replica2part2dev], + devs, 32 - self.part_power) return self._ring def add_dev(self, dev): diff --git a/swift/common/utils.py b/swift/common/utils.py index 49813be668..a6a42a4870 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -58,6 +58,7 @@ HASH_PATH_SUFFIX = os.environ.get('SWIFT_HASH_PATH_SUFFIX', 'endcap') # Used when reading config values TRUE_VALUES = set(('true', '1', 'yes', 'True', 'Yes')) + def load_libc_function(func_name): """ Attempt to find the function in libc, otherwise return a no-op func. @@ -521,15 +522,18 @@ def unlink_older_than(path, mtime): except OSError: pass + def item_from_env(env, item_name): item = env.get(item_name, None) if item is None: logging.error("ERROR: %s could not be found in env!" % item_name) return item + def cache_from_env(env): return item_from_env(env, 'swift.cache') + def readconf(conf, section_name, log_name=None): c = ConfigParser() if not c.read(conf): diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index 13c16aad7f..306f0e2980 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -56,9 +56,9 @@ def monkey_patch_mimetools(): mimetools.Message.parsetype = parsetype + # We might be able to pull pieces of this out to test, but right now it seems # like more work than it's worth. - def run_wsgi(conf_file, app_section, *args, **kwargs): # pragma: no cover """ Loads common settings from conf, then instantiates app and runs @@ -72,7 +72,7 @@ def run_wsgi(conf_file, app_section, *args, **kwargs): # pragma: no cover conf = appconfig('config:%s' % conf_file, name=app_section) log_name = conf.get('log_name', app_section) app = loadapp('config:%s' % conf_file, - global_conf={'log_name':log_name}) + global_conf={'log_name': log_name}) except Exception, e: print "Error trying to load config %s: %s" % (conf_file, e) return diff --git a/swift/container/replicator.py b/swift/container/replicator.py index c264ce680e..0b344ecbcd 100644 --- a/swift/container/replicator.py +++ b/swift/container/replicator.py @@ -16,10 +16,10 @@ from swift.container import server as container_server from swift.common import db, db_replicator + class ContainerReplicator(db_replicator.Replicator): server_type = 'container' ring_file = 'container.ring.gz' brokerclass = db.ContainerBroker datadir = container_server.DATADIR default_port = 6001 - diff --git a/swift/container/server.py b/swift/container/server.py index 63a44fcabc..4134c15e11 100644 --- a/swift/container/server.py +++ b/swift/container/server.py @@ -416,6 +416,7 @@ class ContainerController(object): self.logger.info(log_message) return res(env, start_response) + def app_factory(global_conf, **local_conf): """paste.deploy app factory for creating WSGI container server apps""" conf = global_conf.copy() diff --git a/swift/obj/replicator.py b/swift/obj/replicator.py index 45a77980de..581bf7de2b 100644 --- a/swift/obj/replicator.py +++ b/swift/obj/replicator.py @@ -197,7 +197,7 @@ class ObjectReplicator(Daemon): Replicate objects. Encapsulates most logic and data needed by the object replication process. - Each call to .replicate() performs one replication pass. It's up to the + Each call to .replicate() performs one replication pass. It's up to the caller to do this in a loop. """ @@ -514,7 +514,7 @@ class ObjectReplicator(Daemon): start = time.time() self.logger.info("Running object replicator in script mode.") self.replicate() - total = (time.time() - start)/60 + total = (time.time() - start) / 60 self.logger.info( "Object replication complete. (%.02f minutes)" % total) @@ -526,7 +526,7 @@ class ObjectReplicator(Daemon): self.logger.info("Starting object replication pass.") # Run the replicator self.replicate() - total = (time.time() - start)/60 + total = (time.time() - start) / 60 self.logger.info( "Object replication complete. (%.02f minutes)" % total) self.logger.debug('Replication sleeping for %s seconds.' % diff --git a/swift/obj/server.py b/swift/obj/server.py index c76f44f331..49f707bdb3 100644 --- a/swift/obj/server.py +++ b/swift/obj/server.py @@ -592,6 +592,7 @@ class ObjectController(object): sleep(slow) return res(env, start_response) + def app_factory(global_conf, **local_conf): """paste.deploy app factory for creating WSGI object server apps""" conf = global_conf.copy() diff --git a/swift/proxy/server.py b/swift/proxy/server.py index 5f6a92c8fb..dd868dcd0c 100644 --- a/swift/proxy/server.py +++ b/swift/proxy/server.py @@ -1138,7 +1138,7 @@ class AccountController(Controller): if error_response: return error_response account_partition, accounts = \ - self.app.account_ring.get_nodes( self.account_name) + self.app.account_ring.get_nodes(self.account_name) headers = {'X-Timestamp': normalize_timestamp(time.time()), 'X-CF-Trans-Id': self.trans_id} headers.update(value for value in req.headers.iteritems() @@ -1434,6 +1434,7 @@ class Application(BaseApplication): body='Slow down', request=req) return None + def app_factory(global_conf, **local_conf): """paste.deploy app factory for creating WSGI proxy apps.""" conf = global_conf.copy()