Fix all Glance's pep8 problems.

This commit is contained in:
Ewan Mellor 2011-01-04 20:32:07 +00:00 committed by Tarmac
commit eff29fca5d
11 changed files with 47 additions and 32 deletions

View File

@ -39,8 +39,8 @@ flags.DEFINE_integer('api_port', 9292, 'API server listens on this port')
def main(_args):
# NOTE(sirp): importing in main so that eventlet is imported AFTER daemonization
# see https://bugs.launchpad.net/bugs/687661
# NOTE(sirp): importing in main so that eventlet is imported AFTER
# daemonization. See https://bugs.launchpad.net/bugs/687661
from glance.common import wsgi
from glance.server import API
server = wsgi.Server()

View File

@ -38,9 +38,10 @@ flags.DEFINE_string('registry_host', '0.0.0.0',
flags.DEFINE_integer('registry_port', 9191,
'Registry server listens on this port')
def main(_args):
# NOTE(sirp): importing in main so that eventlet is imported AFTER daemonization
# see https://bugs.launchpad.net/bugs/687661
# NOTE(sirp): importing in main so that eventlet is imported AFTER
# daemonization. See https://bugs.launchpad.net/bugs/687661
from glance.common import wsgi
from glance.registry.server import API
server = wsgi.Server()

View File

@ -47,7 +47,7 @@ class ApiError(Error):
def __init__(self, message='Unknown', code='Unknown'):
self.message = message
self.code = code
super(ApiError, self).__init__('%s: %s'% (code, message))
super(ApiError, self).__init__('%s: %s' % (code, message))
class NotFound(Error):

View File

@ -39,6 +39,7 @@ from glance.common.exception import ProcessExecutionError
FLAGS = flags.FLAGS
TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
def import_class(import_str):
"""Returns a class from a string including module and class"""
mod_str, _sep, class_str = import_str.rpartition('.')
@ -48,6 +49,7 @@ def import_class(import_str):
except (ImportError, ValueError, AttributeError):
raise exception.NotFound('Class %s cannot be found' % class_str)
def import_object(import_str):
"""Returns an object including a module or module and class"""
try:
@ -57,6 +59,7 @@ def import_object(import_str):
cls = import_class(import_str)
return cls()
def fetchfile(url, target):
logging.debug("Fetching %s" % url)
# c = pycurl.Curl()
@ -68,6 +71,7 @@ def fetchfile(url, target):
# fp.close()
execute("curl --fail %s -o %s" % (url, target))
def execute(cmd, process_input=None, addl_env=None, check_exit_code=True):
logging.debug("Running cmd: %s", cmd)
env = os.environ.copy()
@ -83,7 +87,7 @@ def execute(cmd, process_input=None, addl_env=None, check_exit_code=True):
obj.stdin.close()
if obj.returncode:
logging.debug("Result was %s" % (obj.returncode))
if check_exit_code and obj.returncode <> 0:
if check_exit_code and obj.returncode != 0:
(stdout, stderr) = result
raise ProcessExecutionError(exit_code=obj.returncode,
stdout=stdout,
@ -109,7 +113,8 @@ def default_flagfile(filename='glance.conf'):
script_dir = os.path.dirname(inspect.stack()[-1][1])
filename = os.path.abspath(os.path.join(script_dir, filename))
if os.path.exists(filename):
sys.argv = sys.argv[:1] + ['--flagfile=%s' % filename] + sys.argv[1:]
sys.argv = \
sys.argv[:1] + ['--flagfile=%s' % filename] + sys.argv[1:]
def debug(arg):
@ -117,11 +122,11 @@ def debug(arg):
return arg
def runthis(prompt, cmd, check_exit_code = True):
def runthis(prompt, cmd, check_exit_code=True):
logging.debug("Running %s" % (cmd))
exit_code = subprocess.call(cmd.split(" "))
logging.debug(prompt % (exit_code))
if check_exit_code and exit_code <> 0:
if check_exit_code and exit_code != 0:
raise ProcessExecutionError(exit_code=exit_code,
stdout=None,
stderr=None,
@ -129,7 +134,9 @@ def runthis(prompt, cmd, check_exit_code = True):
def generate_uid(topic, size=8):
return '%s-%s' % (topic, ''.join([random.choice('01234567890abcdefghijklmnopqrstuvwxyz') for x in xrange(size)]))
return '%s-%s' % (topic, ''.join(
[random.choice('01234567890abcdefghijklmnopqrstuvwxyz')
for x in xrange(size)]))
def generate_mac():
@ -198,6 +205,7 @@ class LazyPluggable(object):
backend = self.__get_backend()
return getattr(backend, key)
def deferredToThread(f):
def g(*args, **kwargs):
return deferToThread(f, *args, **kwargs)

View File

@ -142,7 +142,9 @@ def _image_update(_context, values, image_id):
image_ref.save(session=session)
for key, value in properties.iteritems():
prop_values = {'image_id': image_ref.id, 'key': key, 'value': value}
prop_values = {'image_id': image_ref.id,
'key': key,
'value': value}
image_property_create(_context, prop_values)
return image_get(_context, image_ref.id)

View File

@ -137,6 +137,7 @@ class ModelBase(object):
def items(self):
return self.__dict__.items()
class Image(BASE, ModelBase):
"""Represents an image in the datastore"""
__tablename__ = 'images'

View File

@ -19,6 +19,7 @@ import httplib
import glance.store
class HTTPBackend(glance.store.Backend):
""" An implementation of the HTTP Backend Adapter """
@ -35,7 +36,8 @@ class HTTPBackend(glance.store.Backend):
elif parsed_uri.scheme == "https":
conn_class = httplib.HTTPSConnection
else:
raise glance.store.BackendException("scheme '%s' not supported for HTTPBackend")
raise glance.store.BackendException(
"scheme '%s' not supported for HTTPBackend")
conn = conn_class(parsed_uri.netloc)
conn.request("GET", parsed_uri.path, "", {})

View File

@ -31,8 +31,8 @@ class SwiftBackend(glance.store.Backend):
"""
Takes a parsed_uri in the format of:
swift://user:password@auth_url/container/file.gz.0, connects to the
swift instance at auth_url and downloads the file. Returns the generator
resp_body provided by get_object.
swift instance at auth_url and downloads the file. Returns the
generator resp_body provided by get_object.
"""
(user, key, authurl, container, obj) = \
cls._parse_swift_tokens(parsed_uri)
@ -50,8 +50,9 @@ class SwiftBackend(glance.store.Backend):
obj_size = int(resp_headers['content-length'])
if obj_size != expected_size:
raise glance.store.BackendException("Expected %s byte file, Swift has %s bytes"
% (expected_size, obj_size))
raise glance.store.BackendException(
"Expected %s byte file, Swift has %s bytes" %
(expected_size, obj_size))
return resp_body