Just a bit of PEP8ing

This commit is contained in:
gholt
2010-09-15 20:52:54 -07:00
parent 9b9c64d27c
commit c138ad99a2
16 changed files with 28 additions and 15 deletions

View File

@@ -23,4 +23,3 @@ class AccountReplicator(db_replicator.Replicator):
brokerclass = db.AccountBroker brokerclass = db.AccountBroker
datadir = account_server.DATADIR datadir = account_server.DATADIR
default_port = 6002 default_port = 6002

View File

@@ -328,6 +328,7 @@ class AccountController(object):
self.logger.info(log_message) self.logger.info(log_message)
return res(env, start_response) return res(env, start_response)
def app_factory(global_conf, **local_conf): def app_factory(global_conf, **local_conf):
"""paste.deploy app factory for creating WSGI account server apps""" """paste.deploy app factory for creating WSGI account server apps"""
conf = global_conf.copy() conf = global_conf.copy()

View File

@@ -638,6 +638,7 @@ YOU HAVE A FEW OPTIONS:
""" Used by the eventlet.wsgi.server """ """ Used by the eventlet.wsgi.server """
return self.handleREST(env, start_response) return self.handleREST(env, start_response)
def app_factory(global_conf, **local_conf): def app_factory(global_conf, **local_conf):
conf = global_conf.copy() conf = global_conf.copy()
conf.update(local_conf) conf.update(local_conf)

View File

@@ -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 :param full_listing: if True, return a full listing, else returns a max
of 10000 listings of 10000 listings
:returns: a tuple of (response headers, a list of containers) The response :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 :raises ClientException: HTTP GET request failed
""" """
if not http_conn: 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 :param full_listing: if True, return a full listing, else returns a max
of 10000 listings of 10000 listings
:returns: a tuple of (response headers, a list of objects) 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.
:raises ClientException: HTTP GET request failed :raises ClientException: HTTP GET request failed
""" """
if not http_conn: 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 the object's contents before making another
request. request.
:returns: a tuple of (response headers, the object's contents) The response :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 :raises ClientException: HTTP GET request failed
""" """
if http_conn: if http_conn:

View File

@@ -18,6 +18,7 @@ import sys
import signal import signal
from swift.common import utils from swift.common import utils
class Daemon(object): class Daemon(object):
"""Daemon base class""" """Daemon base class"""

View File

@@ -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 conn_timeout: timeout in seconds for establishing the connection
:param response_timeout: timeout in seconds for getting the response :param response_timeout: timeout in seconds for getting the response
:returns: a tuple of (response headers, a list of objects) 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) path = '/%s/%s' % (account, container)
qs = 'format=json' 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 response_timeout: timeout in seconds for getting the response
:param resp_chunk_size: if defined, chunk size of data to read. :param resp_chunk_size: if defined, chunk size of data to read.
:returns: a tuple of (response headers, the object's contents) The response :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) path = '/%s/%s/%s' % (account, container, obj)
with Timeout(conn_timeout): with Timeout(conn_timeout):

View File

@@ -37,6 +37,7 @@ class HealthCheckMiddleware(object):
else: else:
return self.app(env, start_response) return self.app(env, start_response)
def filter_factory(global_conf, **local_conf): def filter_factory(global_conf, **local_conf):
def healthcheck_filter(app): def healthcheck_filter(app):
return HealthCheckMiddleware(app) return HealthCheckMiddleware(app)

View File

@@ -14,10 +14,12 @@
from swift.common.memcached import MemcacheRing from swift.common.memcached import MemcacheRing
class MemcacheMiddleware(object): class MemcacheMiddleware(object):
""" """
Caching middleware that manages caching in swift. Caching middleware that manages caching in swift.
""" """
def __init__(self, app, conf): def __init__(self, app, conf):
self.app = app self.app = app
self.memcache = MemcacheRing([s.strip() for s in self.memcache = MemcacheRing([s.strip() for s in
@@ -28,6 +30,7 @@ class MemcacheMiddleware(object):
env['swift.cache'] = self.memcache env['swift.cache'] = self.memcache
return self.app(env, start_response) return self.app(env, start_response)
def filter_factory(global_conf, **local_conf): def filter_factory(global_conf, **local_conf):
conf = global_conf.copy() conf = global_conf.copy()
conf.update(local_conf) conf.update(local_conf)

View File

@@ -104,8 +104,8 @@ class RingBuilder(object):
self._ring = RingData([], devs, 32 - self.part_power) self._ring = RingData([], devs, 32 - self.part_power)
else: else:
self._ring = \ self._ring = \
RingData([array('H', p2d) for p2d in self._replica2part2dev], RingData([array('H', p2d) for p2d in self._replica2part2dev],
devs, 32 - self.part_power) devs, 32 - self.part_power)
return self._ring return self._ring
def add_dev(self, dev): def add_dev(self, dev):

View File

@@ -58,6 +58,7 @@ HASH_PATH_SUFFIX = os.environ.get('SWIFT_HASH_PATH_SUFFIX', 'endcap')
# Used when reading config values # Used when reading config values
TRUE_VALUES = set(('true', '1', 'yes', 'True', 'Yes')) TRUE_VALUES = set(('true', '1', 'yes', 'True', 'Yes'))
def load_libc_function(func_name): def load_libc_function(func_name):
""" """
Attempt to find the function in libc, otherwise return a no-op func. 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: except OSError:
pass pass
def item_from_env(env, item_name): def item_from_env(env, item_name):
item = env.get(item_name, None) item = env.get(item_name, None)
if item is None: if item is None:
logging.error("ERROR: %s could not be found in env!" % item_name) logging.error("ERROR: %s could not be found in env!" % item_name)
return item return item
def cache_from_env(env): def cache_from_env(env):
return item_from_env(env, 'swift.cache') return item_from_env(env, 'swift.cache')
def readconf(conf, section_name, log_name=None): def readconf(conf, section_name, log_name=None):
c = ConfigParser() c = ConfigParser()
if not c.read(conf): if not c.read(conf):

View File

@@ -56,9 +56,9 @@ def monkey_patch_mimetools():
mimetools.Message.parsetype = parsetype mimetools.Message.parsetype = parsetype
# We might be able to pull pieces of this out to test, but right now it seems # We might be able to pull pieces of this out to test, but right now it seems
# like more work than it's worth. # like more work than it's worth.
def run_wsgi(conf_file, app_section, *args, **kwargs): # pragma: no cover def run_wsgi(conf_file, app_section, *args, **kwargs): # pragma: no cover
""" """
Loads common settings from conf, then instantiates app and runs 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) conf = appconfig('config:%s' % conf_file, name=app_section)
log_name = conf.get('log_name', app_section) log_name = conf.get('log_name', app_section)
app = loadapp('config:%s' % conf_file, app = loadapp('config:%s' % conf_file,
global_conf={'log_name':log_name}) global_conf={'log_name': log_name})
except Exception, e: except Exception, e:
print "Error trying to load config %s: %s" % (conf_file, e) print "Error trying to load config %s: %s" % (conf_file, e)
return return

View File

@@ -16,10 +16,10 @@
from swift.container import server as container_server from swift.container import server as container_server
from swift.common import db, db_replicator from swift.common import db, db_replicator
class ContainerReplicator(db_replicator.Replicator): class ContainerReplicator(db_replicator.Replicator):
server_type = 'container' server_type = 'container'
ring_file = 'container.ring.gz' ring_file = 'container.ring.gz'
brokerclass = db.ContainerBroker brokerclass = db.ContainerBroker
datadir = container_server.DATADIR datadir = container_server.DATADIR
default_port = 6001 default_port = 6001

View File

@@ -416,6 +416,7 @@ class ContainerController(object):
self.logger.info(log_message) self.logger.info(log_message)
return res(env, start_response) return res(env, start_response)
def app_factory(global_conf, **local_conf): def app_factory(global_conf, **local_conf):
"""paste.deploy app factory for creating WSGI container server apps""" """paste.deploy app factory for creating WSGI container server apps"""
conf = global_conf.copy() conf = global_conf.copy()

View File

@@ -197,7 +197,7 @@ class ObjectReplicator(Daemon):
Replicate objects. Replicate objects.
Encapsulates most logic and data needed by the object replication process. 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. caller to do this in a loop.
""" """
@@ -514,7 +514,7 @@ class ObjectReplicator(Daemon):
start = time.time() start = time.time()
self.logger.info("Running object replicator in script mode.") self.logger.info("Running object replicator in script mode.")
self.replicate() self.replicate()
total = (time.time() - start)/60 total = (time.time() - start) / 60
self.logger.info( self.logger.info(
"Object replication complete. (%.02f minutes)" % total) "Object replication complete. (%.02f minutes)" % total)
@@ -526,7 +526,7 @@ class ObjectReplicator(Daemon):
self.logger.info("Starting object replication pass.") self.logger.info("Starting object replication pass.")
# Run the replicator # Run the replicator
self.replicate() self.replicate()
total = (time.time() - start)/60 total = (time.time() - start) / 60
self.logger.info( self.logger.info(
"Object replication complete. (%.02f minutes)" % total) "Object replication complete. (%.02f minutes)" % total)
self.logger.debug('Replication sleeping for %s seconds.' % self.logger.debug('Replication sleeping for %s seconds.' %

View File

@@ -592,6 +592,7 @@ class ObjectController(object):
sleep(slow) sleep(slow)
return res(env, start_response) return res(env, start_response)
def app_factory(global_conf, **local_conf): def app_factory(global_conf, **local_conf):
"""paste.deploy app factory for creating WSGI object server apps""" """paste.deploy app factory for creating WSGI object server apps"""
conf = global_conf.copy() conf = global_conf.copy()

View File

@@ -1138,7 +1138,7 @@ class AccountController(Controller):
if error_response: if error_response:
return error_response return error_response
account_partition, accounts = \ 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()), headers = {'X-Timestamp': normalize_timestamp(time.time()),
'X-CF-Trans-Id': self.trans_id} 'X-CF-Trans-Id': self.trans_id}
headers.update(value for value in req.headers.iteritems() headers.update(value for value in req.headers.iteritems()
@@ -1434,6 +1434,7 @@ class Application(BaseApplication):
body='Slow down', request=req) body='Slow down', request=req)
return None return None
def app_factory(global_conf, **local_conf): def app_factory(global_conf, **local_conf):
"""paste.deploy app factory for creating WSGI proxy apps.""" """paste.deploy app factory for creating WSGI proxy apps."""
conf = global_conf.copy() conf = global_conf.copy()