Backslash continuation removal (Glance folsom-1)

Fixes bug #1000636

Removes backslash continuations (except sqlalchemy and mox related code)

Change-Id: I08e6db28f157d67be9fc11ec02cc0844c006a6df
This commit is contained in:
Zhongyue Luo 2012-02-10 23:29:33 +08:00
parent 77552aaac7
commit 49a0f962f6
19 changed files with 98 additions and 101 deletions

View File

@ -63,8 +63,8 @@ def catch_error(action):
ret = func(*args, **kwargs)
return SUCCESS if ret is None else ret
except exception.Forbidden:
print "Not authorized to make this request. Check "\
"your credentials (OS_AUTH_USER, OS_AUTH_KEY, ...)."
print ("Not authorized to make this request. Check "
"your credentials (OS_AUTH_USER, OS_AUTH_KEY, ...).")
return FAILURE
except exception.ClientConfigurationError:
raise
@ -214,11 +214,11 @@ the command line using standard redirection. For example:
EXAMPLES
===============================================================================
%(prog)s add name="My Image" disk_format=raw container_format=ovf \\
location=http://images.ubuntu.org/images/lucid-10.04-i686.iso \\
%(prog)s add name="My Image" disk_format=raw container_format=ovf \
location=http://images.ubuntu.org/images/lucid-10.04-i686.iso \
distro="Ubuntu 10.04 LTS"
%(prog)s add name="My Image" disk_format=raw container_format=ovf \\
%(prog)s add name="My Image" disk_format=raw container_format=ovf \
distro="Ubuntu 10.04 LTS" < /tmp/myimage.iso"""
c = get_client(options)
@ -448,8 +448,8 @@ Deletes an image from Glance"""
print "as the first argument"
return FAILURE
if not options.force and \
not user_confirm("Delete image %s?" % (image_id,), default=False):
if not (options.force or
user_confirm("Delete image %s?" % (image_id,), default=False)):
print 'Not deleting image %s' % (image_id,)
return FAILURE
@ -534,8 +534,8 @@ def _images_index(client, filters, limit, print_header=False, **kwargs):
suppress_pagination = (options.force or
(getattr(os, 'isatty') and not os.isatty(sys.stdout.fileno())))
if not suppress_pagination and len(images) == limit and \
not user_confirm("Fetch next page?", True):
if not (suppress_pagination or len(images) != limit or
user_confirm("Fetch next page?", True)):
return SUCCESS
parameters['marker'] = images[-1]['id']
@ -593,8 +593,8 @@ def _images_details(client, filters, limit, print_header=False, **kwargs):
print_image_formatted(client, image)
print "=" * 80
if not options.force and len(images) == limit and \
not user_confirm("Fetch next page?", True):
if not (options.force or len(images) != limit or
user_confirm("Fetch next page?", True)):
return SUCCESS
parameters["marker"] = images[-1]['id']
@ -633,8 +633,8 @@ def images_clear(options, args):
%(prog)s clear [options]
Deletes all images from a Glance server"""
if not options.force and \
not user_confirm("Delete all images?", default=False):
if not (options.force or
user_confirm("Delete all images?", default=False)):
print 'Not deleting any images'
return FAILURE
@ -998,7 +998,7 @@ def user_confirm(prompt, default=False):
prompt_default = "[y/N]"
# for bug 884116, don't issue the prompt if stdin isn't a tty
if not hasattr(sys.stdin, 'isatty') or not sys.stdin.isatty():
if not (hasattr(sys.stdin, 'isatty') and sys.stdin.isatty()):
return default
answer = raw_input("%s %s " % (prompt, prompt_default))

View File

@ -61,8 +61,8 @@ def catch_error(action):
options.host)
return FAILURE
except exception.Forbidden:
print "Not authorized to make this request. Check "\
"your credentials (OS_AUTH_USER, OS_AUTH_KEY, ...)."
print ("Not authorized to make this request. Check "
"your credentials (OS_AUTH_USER, OS_AUTH_KEY, ...).")
return FAILURE
except Exception, e:
options = args[0]
@ -147,9 +147,9 @@ Queues an image for caching"""
print "from the cache as the first argument"
return FAILURE
if not options.force and \
not user_confirm("Queue image %s for caching?" % (image_id,),
default=False):
if (not options.force and
not user_confirm("Queue image %s for caching?" % (image_id,),
default=False)):
return SUCCESS
client = get_client(options)
@ -174,9 +174,9 @@ Deletes an image from the cache"""
print "from the cache as the first argument"
return FAILURE
if not options.force and \
not user_confirm("Delete cached image %s?" % (image_id,),
default=False):
if (not options.force and
not user_confirm("Delete cached image %s?" % (image_id,),
default=False)):
return SUCCESS
client = get_client(options)
@ -194,8 +194,8 @@ def delete_all_cached_images(options, args):
%(prog)s delete-all-cached-images [options]
Removes all images from the cache"""
if not options.force and \
not user_confirm("Delete all cached images?", default=False):
if (not options.force and
not user_confirm("Delete all cached images?", default=False)):
return SUCCESS
client = get_client(options)
@ -220,9 +220,9 @@ Deletes an image from the cache"""
print "from the cache as the first argument"
return FAILURE
if not options.force and \
not user_confirm("Delete queued image %s?" % (image_id,),
default=False):
if (not options.force and
not user_confirm("Delete queued image %s?" % (image_id,),
default=False)):
return SUCCESS
client = get_client(options)
@ -240,8 +240,8 @@ def delete_all_queued_images(options, args):
%(prog)s delete-all-queued-images [options]
Removes all images from the cache queue"""
if not options.force and \
not user_confirm("Delete all queued images?", default=False):
if (not options.force and
not user_confirm("Delete all queued images?", default=False)):
return SUCCESS
client = get_client(options)

View File

@ -94,8 +94,8 @@ def do_start(verb, server, conf, args):
if verb != 'Respawn':
for pid_file, pid in pid_files(server, conf):
if os.path.exists('/proc/%s' % pid):
print "%s appears to already be running: %s" % \
(server, pid_file)
print ("%s appears to already be running: %s" %
(server, pid_file))
return
else:
print "Removing stale pid file %s" % pid_file
@ -205,8 +205,8 @@ def do_start(verb, server, conf, args):
def get_pid_file(pid, conf):
return os.path.abspath(conf.pid_file) if conf.pid_file else \
'/var/run/glance/%s.pid' % server
return (os.path.abspath(conf.pid_file) if conf.pid_file else
'/var/run/glance/%s.pid' % server)
def do_stop(server, conf, args, graceful=False):
@ -234,8 +234,8 @@ def do_stop(server, conf, args, graceful=False):
break
time.sleep(0.1)
else:
print 'Waited 15 seconds for pid %s (%s) to die; giving up' % \
(pid, pid_file)
print ('Waited 15 seconds for pid %s (%s) to die; giving up' %
(pid, pid_file))
if not did_anything:
print 'No %s running' % server

View File

@ -99,12 +99,11 @@ def main():
try:
# We load the glance-registry config section because
# sql_connection is only part of the glance registry.
default_config_files = \
cfg.find_config_files(project='glance', prog='glance-registry')
default_cfg_files = cfg.find_config_files(project='glance',
prog='glance-registry')
conf = \
config.GlanceConfigOpts(default_config_files=default_config_files,
usage="%prog [options] <cmd>")
conf = config.GlanceConfigOpts(default_config_files=default_cfg_files,
usage="%prog [options] <cmd>")
glance.registry.db.add_options(conf)
args = conf()
config.setup_logging(conf)

View File

@ -207,10 +207,10 @@ class BaseClient(object):
DEFAULT_DOC_ROOT = None
# Standard CA file locations for Debian/Ubuntu, RedHat/Fedora,
# Suse, FreeBSD/OpenBSD
DEFAULT_CA_FILE_PATH = '/etc/ssl/certs/ca-certificates.crt:'\
'/etc/pki/tls/certs/ca-bundle.crt:'\
'/etc/ssl/ca-bundle.pem:'\
'/etc/ssl/cert.pem'
DEFAULT_CA_FILE_PATH = ('/etc/ssl/certs/ca-certificates.crt:'
'/etc/pki/tls/certs/ca-bundle.crt:'
'/etc/ssl/ca-bundle.pem:'
'/etc/ssl/cert.pem')
OK_RESPONSE_CODES = (
httplib.OK,

View File

@ -137,8 +137,8 @@ def generate_authors():
new_authors = 'AUTHORS'
if os.path.isdir('.git'):
# don't include jenkins email address in AUTHORS file
git_log_cmd = "git log --format='%aN <%aE>' | sort -u | " \
"grep -v " + jenkins_email
git_log_cmd = ("git log --format='%aN <%aE>' | sort -u | "
"grep -v " + jenkins_email)
changelog = _run_shell_command(git_log_cmd)
mailmap = parse_mailmap()
with open(new_authors, 'w') as new_authors_fh:

View File

@ -27,8 +27,8 @@ import time
import sqlalchemy
from sqlalchemy import asc, create_engine, desc
from sqlalchemy.exc import IntegrityError, OperationalError, DBAPIError,\
DisconnectionError
from sqlalchemy.exc import (IntegrityError, OperationalError, DBAPIError,
DisconnectionError)
from sqlalchemy.orm import exc
from sqlalchemy.orm import joinedload
from sqlalchemy.orm import sessionmaker
@ -193,8 +193,8 @@ def wrap_db_error(f):
try:
return f(*args, **kwargs)
except OperationalError, e:
if remaining_attempts == 0 or \
not is_db_connection_error(e.args[0]):
if (remaining_attempts == 0 or
not is_db_connection_error(e.args[0])):
raise
except DBAPIError:
raise
@ -374,8 +374,8 @@ def image_get_all(context, filters=None, marker=None, limit=None,
session = get_session()
query = session.query(models.Image).\
options(joinedload(models.Image.properties)).\
options(joinedload(models.Image.members))
options(joinedload(models.Image.properties)).\
options(joinedload(models.Image.members))
if 'size_min' in filters:
query = query.filter(models.Image.size >= filters['size_min'])
@ -737,8 +737,8 @@ def image_member_get_memberships(context, member, marker=None, limit=None,
session = get_session()
query = session.query(models.ImageMember).\
options(joinedload(models.ImageMember.image)).\
filter_by(member=member)
options(joinedload(models.ImageMember.image)).\
filter_by(member=member)
if not can_show_deleted(context):
query = query.filter_by(deleted=False)
@ -782,9 +782,9 @@ def image_tag_delete(context, image_id, value):
"""Delete an image tag."""
session = get_session()
query = session.query(models.ImageTag).\
filter_by(image_id=image_id).\
filter_by(value=value).\
filter_by(deleted=False)
filter_by(image_id=image_id).\
filter_by(value=value).\
filter_by(deleted=False)
try:
tag_ref = query.one()
except exc.NoResultFound:
@ -797,7 +797,7 @@ def image_tag_get_all(context, image_id):
"""Get a list of tags for a specific image."""
session = get_session()
tags = session.query(models.ImageTag).\
filter_by(image_id=image_id).\
filter_by(deleted=False).\
all()
filter_by(image_id=image_id).\
filter_by(deleted=False).\
all()
return tags

View File

@ -270,8 +270,8 @@ def schedule_delete_from_backend(uri, conf, context, image_id, **kwargs):
exception.StoreDeleteNotSupported,
exception.NotFound):
exc_type = sys.exc_info()[0].__name__
msg = _("Failed to delete image at %s from store (%s)") % \
(uri, exc_type)
msg = (_("Failed to delete image at %s from store (%s)") %
(uri, exc_type))
logger.error(msg)
finally:
# avoid falling through to the delayed deletion logic

View File

@ -112,8 +112,8 @@ class Store(glance.store.base.Store):
self.datadir = self.conf.filesystem_store_datadir
if self.datadir is None:
reason = _("Could not find %s in configuration options.") % \
'filesystem_store_datadir'
reason = (_("Could not find %s in configuration options.") %
'filesystem_store_datadir')
logger.error(reason)
raise exception.BadStoreConfiguration(store_name="filesystem",
reason=reason)

View File

@ -229,8 +229,7 @@ class Store(glance.store.base.Store):
else: # Defaults http
self.full_s3_host = 'http://' + self.s3_host
self.s3_store_object_buffer_dir = \
self.conf.s3_store_object_buffer_dir
self.s3_store_object_buffer_dir = self.conf.s3_store_object_buffer_dir
def _option_get(self, param):
result = getattr(self.conf, param)

View File

@ -225,10 +225,10 @@ class Store(glance.store.base.Store):
# The config file has swift_store_large_object_*size in MB, but
# internally we store it in bytes, since the image_size parameter
# passed to add() is also in bytes.
self.large_object_size = \
self.conf.swift_store_large_object_size * ONE_MB
self.large_object_chunk_size = \
self.conf.swift_store_large_object_chunk_size * ONE_MB
_obj_size = self.conf.swift_store_large_object_size
self.large_object_size = _obj_size * ONE_MB
_obj_chunk_size = self.conf.swift_store_large_object_chunk_size
self.large_object_chunk_size = _obj_chunk_size * ONE_MB
except cfg.ConfigFileValueError, e:
reason = _("Error in configuration conf: %s") % e
logger.error(reason)

View File

@ -153,8 +153,8 @@ class TestBinGlance(functional.FunctionalTest):
line = lines[0]
image_id, name, disk_format, container_format, size = \
[c.strip() for c in line.split()]
img_info = [c.strip() for c in line.split()]
image_id, name, disk_format, container_format, size = img_info
self.assertEqual('MyImage', name)
self.assertEqual('0', size, "Expected image to be 0 bytes in size, "
@ -349,8 +349,8 @@ class TestBinGlance(functional.FunctionalTest):
line = lines[0]
image_id, name, disk_format, container_format, size = \
[c.strip() for c in line.split()]
img_info = [c.strip() for c in line.split()]
image_id, name, disk_format, container_format, size = img_info
self.assertEqual('MyImage', name)
self.assertEqual('0', size, "Expected image to be 0 bytes in size, "
@ -406,8 +406,8 @@ class TestBinGlance(functional.FunctionalTest):
line = lines[0]
image_id, name, disk_format, container_format, size = \
[c.strip() for c in line.split()]
img_info = [c.strip() for c in line.split()]
image_id, name, disk_format, container_format, size = img_info
self.assertEqual('MyImage', name)
self.assertEqual('3', size,
@ -503,8 +503,8 @@ class TestBinGlance(functional.FunctionalTest):
# 5. Update the image's Name attribute
updated_image_name = "Updated image name"
cmd = "bin/glance --port=%d update %s is_public=True name=\"%s\"" \
% (api_port, image_id, updated_image_name)
cmd = ("bin/glance --port=%d update %s is_public=True name=\"%s\"" %
(api_port, image_id, updated_image_name))
exitcode, out, err = execute(cmd)
@ -1100,8 +1100,8 @@ class TestBinGlance(functional.FunctionalTest):
line = lines[0]
image_id, name, disk_format, container_format, size = \
[c.strip() for c in line.split()]
img_info = [c.strip() for c in line.split()]
image_id, name, disk_format, container_format, size = img_info
self.assertEqual('MyImage', name)
# 3. Delete the image
@ -1113,8 +1113,8 @@ class TestBinGlance(functional.FunctionalTest):
self.assertTrue(out.startswith('You do not have permission'))
# 4. Remove image protection
cmd = "bin/glance --port=%d --force update %s" \
" protected=False" % (api_port, image_id)
cmd = ("bin/glance --port=%d --force update %s "
"protected=False" % (api_port, image_id))
exitcode, out, err = execute(cmd)

View File

@ -225,8 +225,8 @@ paste.app_factory = glance.common.wsgi:app_factory
glance.app_factory = glance.image_cache.queue_image:Queuer
""")
cmd = "bin/glance-cache-prefetcher --config-file %s" % \
cache_config_filepath
cmd = ("bin/glance-cache-prefetcher --config-file %s" %
cache_config_filepath)
exitcode, out, err = execute(cmd)

View File

@ -495,8 +495,8 @@ glance.app_factory = glance.image_cache.queue_image:Queuer
self.verify_no_cached_images()
cmd = "bin/glance-cache-prefetcher --config-file %s" % \
cache_config_filepath
cmd = ("bin/glance-cache-prefetcher --config-file %s" %
cache_config_filepath)
exitcode, out, err = execute(cmd)

View File

@ -113,10 +113,10 @@ class TestMiscellaneous(functional.FunctionalTest):
self.assertEqual(0, exitcode)
self.assertEqual('{"images": []}', out.strip())
cmd = "curl -X POST -H 'Content-Type: application/octet-stream' "\
"-H 'X-Image-Meta-Name: ImageName' "\
"-H 'X-Image-Meta-Disk-Format: Invalid' "\
"http://0.0.0.0:%d/v1/images" % api_port
cmd = ("curl -X POST -H 'Content-Type: application/octet-stream' "
"-H 'X-Image-Meta-Name: ImageName' "
"-H 'X-Image-Meta-Disk-Format: Invalid' "
"http://0.0.0.0:%d/v1/images" % api_port)
ignored, out, err = execute(cmd)
self.assertTrue('Invalid disk format' in out,

View File

@ -72,8 +72,8 @@ class TestPasteApp(unittest.TestCase):
def test_load_paste_app_with_paste_flavor(self):
paste_group = {'paste_deploy': {'flavor': 'incomplete'}}
pipeline = '[pipeline:glance-registry-incomplete]\n' + \
'pipeline = context registryapp'
pipeline = ('[pipeline:glance-registry-incomplete]\n'
'pipeline = context registryapp')
type = context.ContextMiddleware
self._do_test_load_paste_app(type, paste_group, paste_append=pipeline)
@ -89,9 +89,9 @@ class TestPasteApp(unittest.TestCase):
def test_load_paste_app_with_conf_name(self):
def fake_join(*args):
if len(args) == 2 and \
args[0].endswith('.glance') and \
args[1] == 'glance-cache.conf':
if (len(args) == 2 and
args[0].endswith('.glance') and
args[1] == 'glance-cache.conf'):
return os.path.join(os.getcwd(), 'etc', args[1])
else:
return orig_join(*args)

View File

@ -251,8 +251,7 @@ class TestStore(base.StoreClearingUnitTest):
expected_image_id = utils.generate_uuid()
expected_s3_size = FIVE_KB
expected_s3_contents = "*" * expected_s3_size
expected_checksum = \
hashlib.md5(expected_s3_contents).hexdigest()
expected_checksum = hashlib.md5(expected_s3_contents).hexdigest()
new_conf = S3_CONF.copy()
new_conf['s3_store_host'] = variation
expected_location = format_s3_location(

View File

@ -61,8 +61,8 @@ class RequestTest(unittest.TestCase):
def test_content_type_from_accept_json_xml_quality(self):
request = wsgi.Request.blank('/tests/123')
request.headers["Accept"] = \
"application/json; q=0.3, application/xml; q=0.9"
request.headers["Accept"] = ("application/json; q=0.3, "
"application/xml; q=0.9")
result = request.best_match_content_type()
self.assertEqual(result, "application/json")

View File

@ -87,8 +87,8 @@ class TestConfigOpts(config.GlanceConfigOpts):
def __call__(self):
self._write_tmp_config_file()
try:
super(TestConfigOpts, self).\
__call__(['--config-file', self.temp_file])
super(TestConfigOpts, self).__call__(['--config-file',
self.temp_file])
finally:
if self.clean:
os.remove(self.temp_file)