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

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

View File

@ -26,8 +26,8 @@ import logging
import time import time
import sqlalchemy import sqlalchemy
import sqlalchemy.orm import sqlalchemy.orm as sa_orm
import sqlalchemy.sql import sqlalchemy.sql as sa_sql
from glance.common import exception from glance.common import exception
from glance.db.sqlalchemy import migration from glance.db.sqlalchemy import migration
@ -145,7 +145,7 @@ def get_session(autocommit=True, expire_on_commit=False):
global _MAKER global _MAKER
if not _MAKER: if not _MAKER:
assert _ENGINE assert _ENGINE
_MAKER = sqlalchemy.orm.sessionmaker(bind=_ENGINE, _MAKER = sa_orm.sessionmaker(bind=_ENGINE,
autocommit=autocommit, autocommit=autocommit,
expire_on_commit=expire_on_commit) expire_on_commit=expire_on_commit)
return _MAKER() return _MAKER()
@ -230,9 +230,9 @@ def image_get(context, image_id, session=None, force_show_deleted=False):
session = session or get_session() session = session or get_session()
try: try:
query = session.query(models.Image).\ query = session.query(models.Image)\
options(sqlalchemy.orm.joinedload(models.Image.properties)).\ .options(sa_orm.joinedload(models.Image.properties))\
filter_by(id=image_id) .filter_by(id=image_id)
# filter out deleted images if context disallows it # filter out deleted images if context disallows it
if not force_show_deleted and not can_show_deleted(context): 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() image = query.one()
except sqlalchemy.orm.exc.NoResultFound: except sa_orm.exc.NoResultFound:
raise exception.NotFound("No image found with ID %s" % image_id) raise exception.NotFound("No image found with ID %s" % image_id)
# Make sure they can look at it # 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, " raise ValueError(_("Unknown sort direction, "
"must be 'desc' or 'asc'")) "must be 'desc' or 'asc'"))
criteria = sqlalchemy.sql.and_(*crit_attrs) criteria = sa_sql.and_(*crit_attrs)
criteria_list.append(criteria) criteria_list.append(criteria)
f = sqlalchemy.sql.or_(*criteria_list) f = sa_sql.or_(*criteria_list)
query = query.filter(f) query = query.filter(f)
if limit is not None: if limit is not None:
@ -442,8 +442,8 @@ def image_get_all(context, filters=None, marker=None, limit=None,
filters = filters or {} filters = filters or {}
session = get_session() session = get_session()
query = session.query(models.Image).\ query = session.query(models.Image)\
options(sqlalchemy.orm.joinedload(models.Image.properties)) .options(sa_orm.joinedload(models.Image.properties))
if 'is_public' in filters and filters['is_public'] is not None: if 'is_public' in filters and filters['is_public'] is not None:
the_filter = [models.Image.is_public == filters['is_public']] 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) models.Image.members.any(member=context.owner, deleted=False)
]) ])
if len(the_filter) > 1: if len(the_filter) > 1:
query = query.filter(sqlalchemy.sql.or_(*the_filter)) query = query.filter(sa_sql.or_(*the_filter))
else: else:
query = query.filter(the_filter[0]) query = query.filter(the_filter[0])
del filters['is_public'] 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): def image_tag_delete(context, image_id, value, session=None):
"""Delete an image tag.""" """Delete an image tag."""
session = session or get_session() session = session or get_session()
query = session.query(models.ImageTag).\ query = session.query(models.ImageTag)\
filter_by(image_id=image_id).\ .filter_by(image_id=image_id)\
filter_by(value=value).\ .filter_by(value=value)\
filter_by(deleted=False) .filter_by(deleted=False)
try: try:
tag_ref = query.one() tag_ref = query.one()
except sqlalchemy.orm.exc.NoResultFound: except sa_orm.exc.NoResultFound:
raise exception.NotFound() raise exception.NotFound()
tag_ref.delete(session=session) 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): def image_tag_get_all(context, image_id, session=None):
"""Get a list of tags for a specific image.""" """Get a list of tags for a specific image."""
session = session or get_session() session = session or get_session()
tags = session.query(models.ImageTag).\ tags = session.query(models.ImageTag)\
filter_by(image_id=image_id).\ .filter_by(image_id=image_id)\
filter_by(deleted=False).\ .filter_by(deleted=False)\
order_by(sqlalchemy.asc(models.ImageTag.created_at)).\ .order_by(sqlalchemy.asc(models.ImageTag.created_at))\
all() .all()
return [tag['value'] for tag in tags] 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_table = sqlalchemy.Table('images', meta, autoload=True)
images = images_table.select(images_table.c.location.startswith('swift')).\ images = images_table.select(images_table.c.location.startswith('swift'))\
execute() .execute()
for image in images: for image in images:
fixed_uri = fix_uri_credentials(image['location'], to_quoted) fixed_uri = fix_uri_credentials(image['location'], to_quoted)
images_table.update().\ images_table.update()\
where(images_table.c.id == image['id']).\ .where(images_table.c.id == image['id'])\
values(location=fixed_uri).execute() .values(location=fixed_uri).execute()
def fix_uri_credentials(uri, to_quoted): def fix_uri_credentials(uri, to_quoted):

View File

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

View File

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

View File

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

View File

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

View File

@ -37,7 +37,8 @@ glance_replicator = imp.load_source('glance_replicator',
sys.dont_write_bytecode = False sys.dont_write_bytecode = False
IMG_RESPONSE_ACTIVE = {'content-length': '0', IMG_RESPONSE_ACTIVE = {
'content-length': '0',
'property-image_state': 'available', 'property-image_state': 'available',
'min_ram': '0', 'min_ram': '0',
'disk_format': 'aki', 'disk_format': 'aki',
@ -46,22 +47,18 @@ IMG_RESPONSE_ACTIVE = {'content-length': '0',
'owner': '8aef75b5c0074a59aa99188fdb4b9e90', 'owner': '8aef75b5c0074a59aa99188fdb4b9e90',
'id': '6d55dd55-053a-4765-b7bc-b30df0ea3861', 'id': '6d55dd55-053a-4765-b7bc-b30df0ea3861',
'size': '4660272', 'size': '4660272',
'property-image_location': 'property-image_location': 'ubuntu-bucket/oneiric-server-cloudimg-amd64-'
('ubuntu-bucket/oneiric-server-cloudimg-amd64-' 'vmlinuz-generic.manifest.xml',
'vmlinuz-generic.manifest.xml'),
'property-architecture': 'x86_64', 'property-architecture': 'x86_64',
'etag': 'f46cfe7fb3acaff49a3567031b9b53bb', 'etag': 'f46cfe7fb3acaff49a3567031b9b53bb',
'location': 'location': 'http://127.0.0.1:9292/v1/images/'
('http://127.0.0.1:9292/v1/images/' '6d55dd55-053a-4765-b7bc-b30df0ea3861',
'6d55dd55-053a-4765-b7bc-b30df0ea3861'),
'container_format': 'aki', 'container_format': 'aki',
'status': 'active', 'status': 'active',
'deleted': 'False', 'deleted': 'False',
'min_disk': '0', 'min_disk': '0',
'is_public': 'False', 'is_public': 'False',
'name': 'name': 'ubuntu-bucket/oneiric-server-cloudimg-amd64-vmlinuz-generic',
('ubuntu-bucket/oneiric-server-cloudimg-amd64-'
'vmlinuz-generic'),
'checksum': 'f46cfe7fb3acaff49a3567031b9b53bb', 'checksum': 'f46cfe7fb3acaff49a3567031b9b53bb',
'created_at': '2012-06-25T02:10:32', 'created_at': '2012-06-25T02:10:32',
'protected': 'False', 'protected': 'False',

View File

@ -638,8 +638,7 @@ class TestStoreAuthV1(base.StoreClearingUnitTest, SwiftTests):
self.config(**conf) self.config(**conf)
super(TestStoreAuthV1, self).setUp() super(TestStoreAuthV1, self).setUp()
self.stubs = stubout.StubOutForTesting() self.stubs = stubout.StubOutForTesting()
stub_out_swiftclient(self.stubs, stub_out_swiftclient(self.stubs, conf['swift_store_auth_version'])
conf['swift_store_auth_version'])
self.store = Store() self.store = Store()
def tearDown(self): def tearDown(self):

View File

@ -18,7 +18,7 @@ downloadcache = ~/cache/pip
[testenv:pep8] [testenv:pep8]
deps = pep8==1.3.3 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] [testenv:cover]
setenv = NOSE_WITH_COVERAGE=1 setenv = NOSE_WITH_COVERAGE=1