From 49a0f962f66d6c6ef297b03e2551c17b8572c7df Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Fri, 10 Feb 2012 23:29:33 +0800 Subject: [PATCH] Backslash continuation removal (Glance folsom-1) Fixes bug #1000636 Removes backslash continuations (except sqlalchemy and mox related code) Change-Id: I08e6db28f157d67be9fc11ec02cc0844c006a6df --- bin/glance | 28 ++++++++--------- bin/glance-cache-manage | 30 +++++++++---------- bin/glance-control | 12 ++++---- bin/glance-manage | 9 +++--- glance/common/client.py | 8 ++--- glance/openstack/common/setup.py | 4 +-- glance/registry/db/api.py | 28 ++++++++--------- glance/store/__init__.py | 4 +-- glance/store/filesystem.py | 4 +-- glance/store/s3.py | 3 +- glance/store/swift.py | 8 ++--- glance/tests/functional/test_bin_glance.py | 24 +++++++-------- .../v1/test_bin_glance_cache_manage.py | 4 +-- .../functional/v1/test_cache_middleware.py | 4 +-- glance/tests/functional/v1/test_misc.py | 8 ++--- glance/tests/unit/test_config.py | 10 +++---- glance/tests/unit/test_s3_store.py | 3 +- glance/tests/unit/test_wsgi.py | 4 +-- glance/tests/utils.py | 4 +-- 19 files changed, 98 insertions(+), 101 deletions(-) diff --git a/bin/glance b/bin/glance index 2bbd9c8935..a5bc8e266f 100755 --- a/bin/glance +++ b/bin/glance @@ -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)) diff --git a/bin/glance-cache-manage b/bin/glance-cache-manage index 9286ad0ff3..1411d69541 100755 --- a/bin/glance-cache-manage +++ b/bin/glance-cache-manage @@ -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) diff --git a/bin/glance-control b/bin/glance-control index e35b5d4e4e..84e9705c26 100755 --- a/bin/glance-control +++ b/bin/glance-control @@ -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 diff --git a/bin/glance-manage b/bin/glance-manage index 59296fdf19..22bdcdf5f0 100755 --- a/bin/glance-manage +++ b/bin/glance-manage @@ -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] ") + conf = config.GlanceConfigOpts(default_config_files=default_cfg_files, + usage="%prog [options] ") glance.registry.db.add_options(conf) args = conf() config.setup_logging(conf) diff --git a/glance/common/client.py b/glance/common/client.py index 82f03001cd..a3ebfb9d37 100644 --- a/glance/common/client.py +++ b/glance/common/client.py @@ -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, diff --git a/glance/openstack/common/setup.py b/glance/openstack/common/setup.py index 40178903c8..58544a2615 100644 --- a/glance/openstack/common/setup.py +++ b/glance/openstack/common/setup.py @@ -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: diff --git a/glance/registry/db/api.py b/glance/registry/db/api.py index 860ce58031..de57ffc01b 100644 --- a/glance/registry/db/api.py +++ b/glance/registry/db/api.py @@ -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 diff --git a/glance/store/__init__.py b/glance/store/__init__.py index a128fd6125..4a8e6e24d1 100644 --- a/glance/store/__init__.py +++ b/glance/store/__init__.py @@ -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 diff --git a/glance/store/filesystem.py b/glance/store/filesystem.py index 09452d0a65..fe5b840a5d 100644 --- a/glance/store/filesystem.py +++ b/glance/store/filesystem.py @@ -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) diff --git a/glance/store/s3.py b/glance/store/s3.py index 1e0f4a2235..4c9d3732ab 100644 --- a/glance/store/s3.py +++ b/glance/store/s3.py @@ -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) diff --git a/glance/store/swift.py b/glance/store/swift.py index e6645a9bde..63aa3b40fb 100644 --- a/glance/store/swift.py +++ b/glance/store/swift.py @@ -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) diff --git a/glance/tests/functional/test_bin_glance.py b/glance/tests/functional/test_bin_glance.py index e33e1e9ab1..579f42ba7c 100644 --- a/glance/tests/functional/test_bin_glance.py +++ b/glance/tests/functional/test_bin_glance.py @@ -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) diff --git a/glance/tests/functional/v1/test_bin_glance_cache_manage.py b/glance/tests/functional/v1/test_bin_glance_cache_manage.py index ebab599dbb..2bf51545bb 100644 --- a/glance/tests/functional/v1/test_bin_glance_cache_manage.py +++ b/glance/tests/functional/v1/test_bin_glance_cache_manage.py @@ -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) diff --git a/glance/tests/functional/v1/test_cache_middleware.py b/glance/tests/functional/v1/test_cache_middleware.py index a194e27a55..7532b67061 100644 --- a/glance/tests/functional/v1/test_cache_middleware.py +++ b/glance/tests/functional/v1/test_cache_middleware.py @@ -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) diff --git a/glance/tests/functional/v1/test_misc.py b/glance/tests/functional/v1/test_misc.py index 47184bbbf5..66701737bf 100644 --- a/glance/tests/functional/v1/test_misc.py +++ b/glance/tests/functional/v1/test_misc.py @@ -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, diff --git a/glance/tests/unit/test_config.py b/glance/tests/unit/test_config.py index c2e862fd5d..0044e1b855 100644 --- a/glance/tests/unit/test_config.py +++ b/glance/tests/unit/test_config.py @@ -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) diff --git a/glance/tests/unit/test_s3_store.py b/glance/tests/unit/test_s3_store.py index afcf5f0c92..29f398ab8d 100644 --- a/glance/tests/unit/test_s3_store.py +++ b/glance/tests/unit/test_s3_store.py @@ -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( diff --git a/glance/tests/unit/test_wsgi.py b/glance/tests/unit/test_wsgi.py index b1635cf685..96aa25c07f 100644 --- a/glance/tests/unit/test_wsgi.py +++ b/glance/tests/unit/test_wsgi.py @@ -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") diff --git a/glance/tests/utils.py b/glance/tests/utils.py index 45189c5487..bb6359282e 100644 --- a/glance/tests/utils.py +++ b/glance/tests/utils.py @@ -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)