diff options
author | Zhongyue Luo <lzyeval@gmail.com> | 2012-02-11 20:18:08 +0800 |
---|---|---|
committer | Zhongyue Luo <lzyeval@gmail.com> | 2012-02-11 23:22:54 +0800 |
commit | 684ea9f2eef2926d3e5856eea124a47e475ff3ae (patch) | |
tree | 62d1ebebf3dcd3690e086fab01cc1124067e6fbb | |
parent | 2ad09351f3c4f69ffcae16815b76eb28cb07a9b7 (diff) | |
download | oslo-684ea9f2eef2926d3e5856eea124a47e475ff3ae.tar.gz oslo-684ea9f2eef2926d3e5856eea124a47e475ff3ae.tar.xz oslo-684ea9f2eef2926d3e5856eea124a47e475ff3ae.zip |
PEP8 cleanup (openstack-common)
Fixes bug #930625
Remove backslash continuations in openstack-common.
Fix type checking taboos.
Change-Id: I49ddb9ff5fa5af760dcfccb52cb4793b71e02f19
-rw-r--r-- | openstack/common/config.py | 28 | ||||
-rw-r--r-- | openstack/common/utils.py | 10 | ||||
-rw-r--r-- | openstack/common/wsgi.py | 8 | ||||
-rw-r--r-- | setup.py | 5 | ||||
-rw-r--r-- | tests/unit/test_cfg.py | 4 | ||||
-rw-r--r-- | tests/unit/test_wsgi.py | 4 | ||||
-rw-r--r-- | update.py | 6 |
7 files changed, 32 insertions, 33 deletions
diff --git a/openstack/common/config.py b/openstack/common/config.py index a5fc3f0..7ae703e 100644 --- a/openstack/common/config.py +++ b/openstack/common/config.py @@ -62,8 +62,8 @@ def add_common_options(parser): :param parser: optparse.OptionParser """ - help_text = "The following configuration options are common to "\ - "this app's programs." + help_text = ("The following configuration options are common to " + "this app's programs.") group = optparse.OptionGroup(parser, "Common Options", help_text) group.add_option('-v', '--verbose', default=False, dest="verbose", @@ -88,8 +88,8 @@ def add_log_options(parser): :param parser: optparse.OptionParser """ - help_text = "The following configuration options are specific to logging "\ - "functionality for this program." + help_text = ("The following configuration options are specific to " + "logging functionality for this program.") group = optparse.OptionGroup(parser, "Logging Options", help_text) group.add_option('--log-config', default=None, metavar="PATH", @@ -133,10 +133,10 @@ def setup_logging(options, conf): # If either the CLI option or the conf value # is True, we set to True - debug = options.get('debug') or \ - get_option(conf, 'debug', type='bool', default=False) - verbose = options.get('verbose') or \ - get_option(conf, 'verbose', type='bool', default=False) + debug = (options.get('debug') or + get_option(conf, 'debug', type='bool', default=False)) + verbose = (options.get('verbose') or + get_option(conf, 'verbose', type='bool', default=False)) root_logger = logging.root if debug: root_logger.setLevel(logging.DEBUG) @@ -157,8 +157,8 @@ def setup_logging(options, conf): if not logfile: logfile = conf.get('log_file') - use_syslog = options.get('use_syslog') or \ - get_option(conf, 'use_syslog', type='bool', default=False) + use_syslog = (options.get('use_syslog') or + get_option(conf, 'use_syslog', type='bool', default=False)) if use_syslog: handler = logging.handlers.SysLogHandler(address='/dev/log') @@ -289,10 +289,10 @@ def load_paste_app(app_name, options, args, config_dir=None): # We only update the conf dict for the verbose and debug # flags. Everything else must be set up in the conf file... - debug = options.get('debug') or \ - get_option(conf, 'debug', type='bool', default=False) - verbose = options.get('verbose') or \ - get_option(conf, 'verbose', type='bool', default=False) + debug = (options.get('debug') or + get_option(conf, 'debug', type='bool', default=False)) + verbose = (options.get('verbose') or + get_option(conf, 'verbose', type='bool', default=False)) conf['debug'] = debug conf['verbose'] = verbose diff --git a/openstack/common/utils.py b/openstack/common/utils.py index fe7b63d..9b30020 100644 --- a/openstack/common/utils.py +++ b/openstack/common/utils.py @@ -25,7 +25,6 @@ import os import random import shlex import sys -import types from eventlet import greenthread from eventlet.green import subprocess @@ -60,9 +59,9 @@ def bool_from_string(subject): Useful for JSON-decoded stuff and config file parsing """ - if isinstance(subject, types.BooleanType): + if isinstance(subject, bool): return subject - if isinstance(subject, types.StringTypes): + if isinstance(subject, basestring): if subject.strip().lower() in ('true', 'on', '1'): return True return False @@ -120,8 +119,9 @@ def execute(*cmd, **kwargs): _returncode = obj.returncode # pylint: disable=E1101 if _returncode: LOG.debug(_('Result was %s') % _returncode) - if type(check_exit_code) == types.IntType \ - and _returncode != check_exit_code: + if (isinstance(check_exit_code, int) and + not isinstance(check_exit_code, bool) and + _returncode != check_exit_code): (stdout, stderr) = result raise exception.ProcessExecutionError( exit_code=_returncode, diff --git a/openstack/common/wsgi.py b/openstack/common/wsgi.py index 128ae8c..c08e4d7 100644 --- a/openstack/common/wsgi.py +++ b/openstack/common/wsgi.py @@ -495,8 +495,8 @@ class ResponseSerializer(object): } self.body_serializers.update(body_serializers or {}) - self.headers_serializer = headers_serializer or \ - ResponseHeadersSerializer() + self.headers_serializer = (headers_serializer or + ResponseHeadersSerializer()) def serialize(self, response_data, content_type, action='default'): """Serialize a dict into a string and wrap in a wsgi.Request object. @@ -550,8 +550,8 @@ class RequestDeserializer(object): } self.body_deserializers.update(body_deserializers or {}) - self.headers_deserializer = headers_deserializer or \ - RequestHeadersDeserializer() + self.headers_deserializer = (headers_deserializer or + RequestHeadersDeserializer()) def deserialize(self, request): """Extract necessary pieces of the request. @@ -16,9 +16,8 @@ write_requirements() setup(name='openstack.common', version=version, description="Common components for Openstack", - long_description="""\ -Common components for Openstack including paster templates. -""", + long_description="Common components for Openstack " + "including paster templates.", classifiers=[ 'Development Status :: 4 - Beta', 'License :: OSI Approved :: Apache Software License', diff --git a/tests/unit/test_cfg.py b/tests/unit/test_cfg.py index 8dd6352..3a931da 100644 --- a/tests/unit/test_cfg.py +++ b/tests/unit/test_cfg.py @@ -115,8 +115,8 @@ class LeftoversTestCase(BaseTestCase): class FindConfigFilesTestCase(BaseTestCase): def test_find_config_files(self): - config_files = \ - [os.path.expanduser('~/.blaa/blaa.conf'), '/etc/foo.conf'] + config_files = [os.path.expanduser('~/.blaa/blaa.conf'), + '/etc/foo.conf'] self.stubs.Set(sys, 'argv', ['foo']) self.stubs.Set(os.path, 'exists', lambda p: p in config_files) diff --git a/tests/unit/test_wsgi.py b/tests/unit/test_wsgi.py index c400329..16c5345 100644 --- a/tests/unit/test_wsgi.py +++ b/tests/unit/test_wsgi.py @@ -68,8 +68,8 @@ class RequestTest(unittest.TestCase): self.assertEqual(result, "application/json") 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/xml") @@ -40,7 +40,7 @@ Or: Where ../myproj is a project directory which contains a differently named configuration file, or: - $> python update.py --config-file ../myproj/myproj/openstack/common.conf \ + $> python update.py --config-file ../myproj/myproj/openstack/common.conf --dest-dir ../myproj Where ../myproject is a project directory, but the configuration file is @@ -136,8 +136,8 @@ def _copy_file(path, base, dest_dir): def _copy_module(mod, base, dest_dir): - print "Copying openstack.common.%s under the %s module in %s" % \ - (mod, base, dest_dir) + print ("Copying openstack.common.%s under the %s module in %s" % + (mod, base, dest_dir)) if '.' in mod: path = _mod_to_path('openstack.common') |