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

@ -236,7 +236,7 @@ class Client(BaseClient):
image_meta['size'] = len(body)
headers = util.image_meta_to_http_headers(image_meta)
if image_data:
headers['content-type'] = 'application/octet-stream'

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,11 +137,12 @@ class ModelBase(object):
def items(self):
return self.__dict__.items()
class Image(BASE, ModelBase):
"""Represents an image in the datastore"""
__tablename__ = 'images'
__prefix__ = 'img'
id = Column(Integer, primary_key=True)
name = Column(String(255))
type = Column(String(30))
@ -156,13 +157,13 @@ class Image(BASE, ModelBase):
raise exception.Invalid(
"Invalid image type '%s' for image." % type)
return type
@validates('status')
def validate_status(self, key, status):
if not status in ('available', 'pending', 'disabled'):
raise exception.Invalid("Invalid status '%s' for image." % status)
return status
class ImageProperty(BASE, ModelBase):
"""Represents an image properties in the datastore"""
@ -173,7 +174,7 @@ class ImageProperty(BASE, ModelBase):
id = Column(Integer, primary_key=True)
image_id = Column(Integer, ForeignKey('images.id'), nullable=False)
image = relationship(Image, backref=backref('properties'))
key = Column(String(255), index=True)
value = Column(Text)

View File

@ -73,7 +73,7 @@ class FilesystemBackend(Backend):
except OSError:
raise exception.NotAuthorized("You cannot delete file %s" % fn)
else:
raise exception.NotFound("File %s does not exist" % fn)
raise exception.NotFound("File %s does not exist" % fn)
def get_backend_class(backend):

View File

@ -114,12 +114,12 @@ class FilesystemBackend(glance.store.Backend):
:retval The location that was written, with file:// scheme prepended
"""
datadir = FLAGS.filesystem_store_datadir
if not os.path.exists(datadir):
os.makedirs(datadir)
filepath = os.path.join(datadir, str(id))
if os.path.exists(filepath):

View File

@ -19,6 +19,7 @@ import httplib
import glance.store
class HTTPBackend(glance.store.Backend):
""" An implementation of the HTTP Backend Adapter """
@ -35,11 +36,12 @@ 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, "", {})
try:
return glance.store._file_iter(conn.getresponse(), cls.CHUNKSIZE)
finally:

View File

@ -29,14 +29,14 @@ class SwiftBackend(glance.store.Backend):
@classmethod
def get(cls, parsed_uri, expected_size, conn_class=None):
"""
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.
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.
"""
(user, key, authurl, container, obj) = \
cls._parse_swift_tokens(parsed_uri)
# TODO(sirp): snet=False for now, however, if the instance of
# swift we're talking to is within our same region, we should set
# snet=True
@ -50,9 +50,10 @@ 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
@classmethod
@ -62,7 +63,7 @@ class SwiftBackend(glance.store.Backend):
"""
(user, key, authurl, container, obj) = \
cls._parse_swift_tokens(parsed_uri)
# TODO(sirp): snet=False for now, however, if the instance of
# swift we're talking to is within our same region, we should set
# snet=True
@ -76,7 +77,7 @@ class SwiftBackend(glance.store.Backend):
# TODO(jaypipes): What to return here? After reading the docs
# at swift.common.client, I'm not sure what to check for...
@classmethod
def _parse_swift_tokens(cls, parsed_uri):
"""