Clean up pep8 E127 violations

Fixed E127 errors.
All ignores are to be removed in the next sequence of patches.

Change-Id: I56839ebe63dbccbb830dfed8923892c7c0837d7e
This commit is contained in:
Zhongyue Luo 2012-09-20 11:34:38 +08:00
parent c5a1635a6b
commit c05dd1c819
17 changed files with 103 additions and 107 deletions

View File

@ -40,7 +40,7 @@ common_opts = [
help=_('Whether to allow users to specify image properties '
'beyond what the image schema provides')),
cfg.StrOpt('data_api', default='glance.db.sqlalchemy.api',
help=_('Python module path of data access API')),
help=_('Python module path of data access API')),
cfg.IntOpt('limit_param_default', default=25,
help=_('Default value for the number of items returned by a '
'request if not specified explicitly in the request')),

View File

@ -144,8 +144,8 @@ def _filter_images(images, filters, context):
for p in image['properties']:
properties = {p['name']: p['value'],
'deleted': p['deleted']}
add = properties.get(key) == value and \
properties.get('deleted') is False
add = (properties.get(key) == value and
properties.get('deleted') is False)
if not add:
break
@ -161,8 +161,8 @@ def _filter_images(images, filters, context):
can_see = image['is_public'] or has_ownership or context.is_admin
if can_see:
return has_ownership or \
(can_see and image['is_public'] == is_public_filter)
return (has_ownership or
(can_see and image['is_public'] == is_public_filter))
else:
return False

View File

@ -26,8 +26,8 @@ import logging
import time
import sqlalchemy
import sqlalchemy.orm
import sqlalchemy.sql
import sqlalchemy.orm as sa_orm
import sqlalchemy.sql as sa_sql
from glance.common import exception
from glance.db.sqlalchemy import migration
@ -145,9 +145,9 @@ def get_session(autocommit=True, expire_on_commit=False):
global _MAKER
if not _MAKER:
assert _ENGINE
_MAKER = sqlalchemy.orm.sessionmaker(bind=_ENGINE,
autocommit=autocommit,
expire_on_commit=expire_on_commit)
_MAKER = sa_orm.sessionmaker(bind=_ENGINE,
autocommit=autocommit,
expire_on_commit=expire_on_commit)
return _MAKER()
@ -174,7 +174,7 @@ def wrap_db_error(f):
remaining_attempts = _MAX_RETRIES
while True:
LOG.warning(_('SQL connection failed. %d attempts left.'),
remaining_attempts)
remaining_attempts)
remaining_attempts -= 1
time.sleep(_RETRY_INTERVAL)
try:
@ -230,9 +230,9 @@ def image_get(context, image_id, session=None, force_show_deleted=False):
session = session or get_session()
try:
query = session.query(models.Image).\
options(sqlalchemy.orm.joinedload(models.Image.properties)).\
filter_by(id=image_id)
query = session.query(models.Image)\
.options(sa_orm.joinedload(models.Image.properties))\
.filter_by(id=image_id)
# filter out deleted images if context disallows it
if not force_show_deleted and not can_show_deleted(context):
@ -240,7 +240,7 @@ def image_get(context, image_id, session=None, force_show_deleted=False):
image = query.one()
except sqlalchemy.orm.exc.NoResultFound:
except sa_orm.exc.NoResultFound:
raise exception.NotFound("No image found with ID %s" % image_id)
# Make sure they can look at it
@ -414,10 +414,10 @@ def paginate_query(query, model, limit, sort_keys, marker=None,
raise ValueError(_("Unknown sort direction, "
"must be 'desc' or 'asc'"))
criteria = sqlalchemy.sql.and_(*crit_attrs)
criteria = sa_sql.and_(*crit_attrs)
criteria_list.append(criteria)
f = sqlalchemy.sql.or_(*criteria_list)
f = sa_sql.or_(*criteria_list)
query = query.filter(f)
if limit is not None:
@ -442,8 +442,8 @@ def image_get_all(context, filters=None, marker=None, limit=None,
filters = filters or {}
session = get_session()
query = session.query(models.Image).\
options(sqlalchemy.orm.joinedload(models.Image.properties))
query = session.query(models.Image)\
.options(sa_orm.joinedload(models.Image.properties))
if 'is_public' in filters and filters['is_public'] is not None:
the_filter = [models.Image.is_public == filters['is_public']]
@ -453,7 +453,7 @@ def image_get_all(context, filters=None, marker=None, limit=None,
models.Image.members.any(member=context.owner, deleted=False)
])
if len(the_filter) > 1:
query = query.filter(sqlalchemy.sql.or_(*the_filter))
query = query.filter(sa_sql.or_(*the_filter))
else:
query = query.filter(the_filter[0])
del filters['is_public']
@ -768,13 +768,13 @@ def image_tag_create(context, image_id, value, session=None):
def image_tag_delete(context, image_id, value, session=None):
"""Delete an image tag."""
session = session or get_session()
query = session.query(models.ImageTag).\
filter_by(image_id=image_id).\
filter_by(value=value).\
filter_by(deleted=False)
query = session.query(models.ImageTag)\
.filter_by(image_id=image_id)\
.filter_by(value=value)\
.filter_by(deleted=False)
try:
tag_ref = query.one()
except sqlalchemy.orm.exc.NoResultFound:
except sa_orm.exc.NoResultFound:
raise exception.NotFound()
tag_ref.delete(session=session)
@ -783,9 +783,9 @@ def image_tag_delete(context, image_id, value, session=None):
def image_tag_get_all(context, image_id, session=None):
"""Get a list of tags for a specific image."""
session = session or get_session()
tags = session.query(models.ImageTag).\
filter_by(image_id=image_id).\
filter_by(deleted=False).\
order_by(sqlalchemy.asc(models.ImageTag.created_at)).\
all()
tags = session.query(models.ImageTag)\
.filter_by(image_id=image_id)\
.filter_by(deleted=False)\
.order_by(sqlalchemy.asc(models.ImageTag.created_at))\
.all()
return [tag['value'] for tag in tags]

View File

@ -50,14 +50,14 @@ def migrate_location_credentials(migrate_engine, to_quoted):
images_table = sqlalchemy.Table('images', meta, autoload=True)
images = images_table.select(images_table.c.location.startswith('swift')).\
execute()
images = images_table.select(images_table.c.location.startswith('swift'))\
.execute()
for image in images:
fixed_uri = fix_uri_credentials(image['location'], to_quoted)
images_table.update().\
where(images_table.c.id == image['id']).\
values(location=fixed_uri).execute()
images_table.update()\
.where(images_table.c.id == image['id'])\
.values(location=fixed_uri).execute()
def fix_uri_credentials(uri, to_quoted):

View File

@ -170,7 +170,7 @@ class ImageCache(object):
overage = current_size - max_size
LOG.debug(_("Image cache currently %(overage)d bytes over max "
"size. Starting prune to max size of %(max_size)d ") %
locals())
locals())
total_bytes_pruned = 0
total_files_pruned = 0

View File

@ -97,17 +97,21 @@ def get_client(host, port=None, timeout=None, use_ssl=False, username=None,
else:
force_strategy = None
creds = dict(username=username or
os.getenv('OS_AUTH_USER', os.getenv('OS_USERNAME')),
password=password or
os.getenv('OS_AUTH_KEY', os.getenv('OS_PASSWORD')),
tenant=tenant or
os.getenv('OS_AUTH_TENANT',
os.getenv('OS_TENANT_NAME')),
auth_url=auth_url or os.getenv('OS_AUTH_URL'),
strategy=force_strategy or auth_strategy or
os.getenv('OS_AUTH_STRATEGY', 'noauth'),
region=region or os.getenv('OS_REGION_NAME'))
creds = {
'username': username or
os.getenv('OS_AUTH_USER', os.getenv('OS_USERNAME')),
'password': password or
os.getenv('OS_AUTH_KEY', os.getenv('OS_PASSWORD')),
'tenant': tenant or
os.getenv('OS_AUTH_TENANT', os.getenv('OS_TENANT_NAME')),
'auth_url': auth_url or
os.getenv('OS_AUTH_URL'),
'strategy': force_strategy or
auth_strategy or
os.getenv('OS_AUTH_STRATEGY', 'noauth'),
'region': region or
os.getenv('OS_REGION_NAME'),
}
if creds['strategy'] == 'keystone' and not creds['auth_url']:
msg = ("--os_auth_url option or OS_AUTH_URL environment variable "

View File

@ -275,8 +275,8 @@ class Driver(base.Driver):
final_path = self.get_image_filepath(image_id)
LOG.debug(_("Fetch finished, moving "
"'%(incomplete_path)s' to '%(final_path)s'"),
dict(incomplete_path=incomplete_path,
final_path=final_path))
dict(incomplete_path=incomplete_path,
final_path=final_path))
os.rename(incomplete_path, final_path)
# Make sure that we "pop" the image from the queue...

View File

@ -318,8 +318,8 @@ def make_member_list(members, **attr_map):
"""
def _fetch_memb(memb, attr_map):
return dict([(k, memb[v]) for k, v in attr_map.items()
if v in memb.keys()])
return dict([(k, memb[v])
for k, v in attr_map.items() if v in memb.keys()])
# Return the list of members with the given attribute mapping
return [_fetch_memb(memb, attr_map) for memb in members

View File

@ -602,7 +602,7 @@ class Store(glance.store.base.Store):
raise
def set_acls(self, location, public=False, read_tenants=[],
write_tenants=[]):
write_tenants=[]):
"""
Sets the read and write access control list for an image in the
backend store.

View File

@ -200,12 +200,9 @@ class ApiServer(Server):
self.key_file = ""
self.cert_file = ""
self.metadata_encryption_key = "012345678901234567890123456789ab"
self.image_dir = os.path.join(self.test_dir,
"images")
self.pid_file = pid_file or os.path.join(self.test_dir,
"api.pid")
self.scrubber_datadir = os.path.join(self.test_dir,
"scrubber")
self.image_dir = os.path.join(self.test_dir, "images")
self.pid_file = pid_file or os.path.join(self.test_dir, "api.pid")
self.scrubber_datadir = os.path.join(self.test_dir, "scrubber")
self.log_file = os.path.join(self.test_dir, "api.log")
self.s3_store_host = "s3.amazonaws.com"
self.s3_store_access_key = ""
@ -360,8 +357,7 @@ class RegistryServer(Server):
self.sql_connection = os.environ.get('GLANCE_TEST_SQL_CONNECTION',
default_sql_connection)
self.pid_file = os.path.join(self.test_dir,
"registry.pid")
self.pid_file = os.path.join(self.test_dir, "registry.pid")
self.log_file = os.path.join(self.test_dir, "registry.log")
self.owner_is_tenant = True
self.server_control_options = '--capture-output'

View File

@ -77,8 +77,8 @@ class TestScrubber(functional.FunctionalTest):
time.sleep(5)
response, content = http.request(path, 'HEAD')
if response['x-image-meta-status'] == 'deleted' and \
response['x-image-meta-deleted'] == 'True':
if (response['x-image-meta-status'] == 'deleted' and
response['x-image-meta-deleted'] == 'True'):
break
else:
continue
@ -138,8 +138,8 @@ class TestScrubber(functional.FunctionalTest):
time.sleep(5)
response, content = http.request(path, 'HEAD')
if response['x-image-meta-status'] == 'deleted' and \
response['x-image-meta-deleted'] == 'True':
if (response['x-image-meta-status'] == 'deleted' and
response['x-image-meta-deleted'] == 'True'):
break
else:
continue

View File

@ -183,7 +183,7 @@ def stub_out_registry_and_store_server(stubs, base_dir):
stubs.Set(glance.common.client.BaseClient, 'get_connection_type',
fake_get_connection_type)
setattr(glance.common.client.BaseClient, '_stub_orig_sendable',
glance.common.client.BaseClient._sendable)
glance.common.client.BaseClient._sendable)
stubs.Set(glance.common.client.BaseClient, '_sendable',
fake_sendable)

View File

@ -37,36 +37,33 @@ glance_replicator = imp.load_source('glance_replicator',
sys.dont_write_bytecode = False
IMG_RESPONSE_ACTIVE = {'content-length': '0',
'property-image_state': 'available',
'min_ram': '0',
'disk_format': 'aki',
'updated_at': '2012-06-25T02:10:36',
'date': 'Thu, 28 Jun 2012 07:20:05 GMT',
'owner': '8aef75b5c0074a59aa99188fdb4b9e90',
'id': '6d55dd55-053a-4765-b7bc-b30df0ea3861',
'size': '4660272',
'property-image_location':
('ubuntu-bucket/oneiric-server-cloudimg-amd64-'
'vmlinuz-generic.manifest.xml'),
'property-architecture': 'x86_64',
'etag': 'f46cfe7fb3acaff49a3567031b9b53bb',
'location':
('http://127.0.0.1:9292/v1/images/'
'6d55dd55-053a-4765-b7bc-b30df0ea3861'),
'container_format': 'aki',
'status': 'active',
'deleted': 'False',
'min_disk': '0',
'is_public': 'False',
'name':
('ubuntu-bucket/oneiric-server-cloudimg-amd64-'
'vmlinuz-generic'),
'checksum': 'f46cfe7fb3acaff49a3567031b9b53bb',
'created_at': '2012-06-25T02:10:32',
'protected': 'False',
'content-type': 'text/html; charset=UTF-8'
}
IMG_RESPONSE_ACTIVE = {
'content-length': '0',
'property-image_state': 'available',
'min_ram': '0',
'disk_format': 'aki',
'updated_at': '2012-06-25T02:10:36',
'date': 'Thu, 28 Jun 2012 07:20:05 GMT',
'owner': '8aef75b5c0074a59aa99188fdb4b9e90',
'id': '6d55dd55-053a-4765-b7bc-b30df0ea3861',
'size': '4660272',
'property-image_location': 'ubuntu-bucket/oneiric-server-cloudimg-amd64-'
'vmlinuz-generic.manifest.xml',
'property-architecture': 'x86_64',
'etag': 'f46cfe7fb3acaff49a3567031b9b53bb',
'location': 'http://127.0.0.1:9292/v1/images/'
'6d55dd55-053a-4765-b7bc-b30df0ea3861',
'container_format': 'aki',
'status': 'active',
'deleted': 'False',
'min_disk': '0',
'is_public': 'False',
'name': 'ubuntu-bucket/oneiric-server-cloudimg-amd64-vmlinuz-generic',
'checksum': 'f46cfe7fb3acaff49a3567031b9b53bb',
'created_at': '2012-06-25T02:10:32',
'protected': 'False',
'content-type': 'text/html; charset=UTF-8'
}
IMG_RESPONSE_QUEUED = copy.copy(IMG_RESPONSE_ACTIVE)
IMG_RESPONSE_QUEUED['status'] = 'queued'

View File

@ -106,7 +106,7 @@ def stub_out_swiftclient(stubs, swift_store_auth_version):
read_len = fixture_object.len
if read_len > MAX_SWIFT_OBJECT_SIZE:
msg = ('Image size:%d exceeds Swift max:%d' %
(read_len, MAX_SWIFT_OBJECT_SIZE))
(read_len, MAX_SWIFT_OBJECT_SIZE))
raise swiftclient.ClientException(
msg, http_status=httplib.REQUEST_ENTITY_TOO_LARGE)
fixture_objects[fixture_key] = fixture_object
@ -323,7 +323,7 @@ class SwiftTests(object):
expected_swift_size = FIVE_KB
expected_swift_contents = "*" * expected_swift_size
expected_checksum = \
hashlib.md5(expected_swift_contents).hexdigest()
hashlib.md5(expected_swift_contents).hexdigest()
image_swift = StringIO.StringIO(expected_swift_contents)
@ -638,8 +638,7 @@ class TestStoreAuthV1(base.StoreClearingUnitTest, SwiftTests):
self.config(**conf)
super(TestStoreAuthV1, self).setUp()
self.stubs = stubout.StubOutForTesting()
stub_out_swiftclient(self.stubs,
conf['swift_store_auth_version'])
stub_out_swiftclient(self.stubs, conf['swift_store_auth_version'])
self.store = Store()
def tearDown(self):

View File

@ -1837,7 +1837,7 @@ class TestRegistryAPI(base.IsolatedUnitTest):
Tests replacing image members raises right exception
"""
self.api = test_utils.FakeAuthMiddleware(rserver.API(self.mapper),
is_admin=False)
is_admin=False)
fixture = dict(member_id='pattieblack')
req = webob.Request.blank('/images/%s/members' % UUID2)
@ -1853,7 +1853,7 @@ class TestRegistryAPI(base.IsolatedUnitTest):
Tests adding image members raises right exception
"""
self.api = test_utils.FakeAuthMiddleware(rserver.API(self.mapper),
is_admin=False)
is_admin=False)
req = webob.Request.blank('/images/%s/members/pattieblack' % UUID2)
req.method = 'PUT'
@ -1865,7 +1865,7 @@ class TestRegistryAPI(base.IsolatedUnitTest):
Tests deleting image members raises right exception
"""
self.api = test_utils.FakeAuthMiddleware(rserver.API(self.mapper),
is_admin=False)
is_admin=False)
req = webob.Request.blank('/images/%s/members/pattieblack' % UUID2)
req.method = 'DELETE'
@ -3087,7 +3087,7 @@ class TestGlanceAPI(base.IsolatedUnitTest):
Tests replacing image members raises right exception
"""
self.api = test_utils.FakeAuthMiddleware(router.API(self.mapper),
is_admin=False)
is_admin=False)
fixture = dict(member_id='pattieblack')
req = webob.Request.blank('/images/%s/members' % UUID2)
@ -3103,7 +3103,7 @@ class TestGlanceAPI(base.IsolatedUnitTest):
Tests adding image members raises right exception
"""
self.api = test_utils.FakeAuthMiddleware(router.API(self.mapper),
is_admin=False)
is_admin=False)
req = webob.Request.blank('/images/%s/members/pattieblack' % UUID2)
req.method = 'PUT'
@ -3115,7 +3115,7 @@ class TestGlanceAPI(base.IsolatedUnitTest):
Tests deleting image members raises right exception
"""
self.api = test_utils.FakeAuthMiddleware(router.API(self.mapper),
is_admin=False)
is_admin=False)
req = webob.Request.blank('/images/%s/members/pattieblack' % UUID2)
req.method = 'DELETE'

View File

@ -58,7 +58,7 @@ def run_command(cmd, redirect_output=True, check_exit_code=True):
HAS_EASY_INSTALL = bool(run_command(['which', 'easy_install'],
check_exit_code=False).strip())
HAS_VIRTUALENV = bool(run_command(['which', 'virtualenv'],
check_exit_code=False).strip())
check_exit_code=False).strip())
def check_dependencies():

View File

@ -18,7 +18,7 @@ downloadcache = ~/cache/pip
[testenv:pep8]
deps = pep8==1.3.3
commands = pep8 --ignore=E125,E126,E127,E128,E711 --repeat --show-source --exclude=.venv,.tox,dist,doc,openstack .
commands = pep8 --ignore=E125,E126,E128,E711 --repeat --show-source --exclude=.venv,.tox,dist,doc,openstack .
[testenv:cover]
setenv = NOSE_WITH_COVERAGE=1