From cdee965095e4015a5cd5328a781590481788d40a Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 31 Jan 2013 13:31:41 -0600 Subject: [PATCH] Upgraded to PEP8 1.3.3 to stay aligned with Nova, etc. Made all the necessary changes to pass new PEP8 standards. Also cleaned up docstrings to conform to the HACKING stanards. Change-Id: Ib8df3030da7a7885655689ab5da0717748c9edbe --- openstackclient/common/clientmanager.py | 25 +++------ openstackclient/common/command.py | 8 +-- openstackclient/common/exceptions.py | 57 +++++++------------- openstackclient/common/utils.py | 4 +- openstackclient/shell.py | 72 +++++++++++++------------ setup.py | 53 +++++++++--------- tox.ini | 2 +- 7 files changed, 93 insertions(+), 128 deletions(-) diff --git a/openstackclient/common/clientmanager.py b/openstackclient/common/clientmanager.py index f6f6642..830ecde 100644 --- a/openstackclient/common/clientmanager.py +++ b/openstackclient/common/clientmanager.py @@ -13,8 +13,7 @@ # under the License. # -"""Manage access to the clients, including authenticating when needed. -""" +"""Manage access to the clients, including authenticating when needed.""" import logging @@ -22,13 +21,12 @@ from openstackclient.compute import client as compute_client from openstackclient.identity import client as identity_client from openstackclient.image import client as image_client + LOG = logging.getLogger(__name__) class ClientCache(object): - """Descriptor class for caching created client handles. - """ - + """Descriptor class for caching created client handles.""" def __init__(self, factory): self.factory = factory self._handle = None @@ -41,20 +39,14 @@ class ClientCache(object): class ClientManager(object): - """Manages access to API clients, including authentication. - """ - + """Manages access to API clients, including authentication.""" compute = ClientCache(compute_client.make_client) identity = ClientCache(identity_client.make_client) image = ClientCache(image_client.make_client) - def __init__(self, token=None, url=None, - auth_url=None, - tenant_name=None, tenant_id=None, - username=None, password=None, - region_name=None, - api_version=None, - ): + def __init__(self, token=None, url=None, auth_url=None, tenant_name=None, + tenant_id=None, username=None, password=None, + region_name=None, api_version=None): self._token = token self._url = url self._auth_url = auth_url @@ -74,8 +66,7 @@ class ClientManager(object): return def get_endpoint_for_service_type(self, service_type): - """Return the endpoint URL for the service type. - """ + """Return the endpoint URL for the service type.""" # See if we are using password flow auth, i.e. we have a # service catalog to select endpoints from if self._service_catalog: diff --git a/openstackclient/common/command.py b/openstackclient/common/command.py index cfcb605..64e855d 100644 --- a/openstackclient/common/command.py +++ b/openstackclient/common/command.py @@ -13,17 +13,13 @@ # under the License. # -""" -OpenStack base command -""" +"""OpenStack base command""" from cliff.command import Command class OpenStackCommand(Command): - """Base class for OpenStack commands - """ - + """Base class for OpenStack commands.""" api = None def run(self, parsed_args): diff --git a/openstackclient/common/exceptions.py b/openstackclient/common/exceptions.py index 9dfb4bc..ab043db 100644 --- a/openstackclient/common/exceptions.py +++ b/openstackclient/common/exceptions.py @@ -13,9 +13,7 @@ # under the License. # -""" -Exception definitions. -""" +"""Exception definitions.""" class CommandError(Exception): @@ -27,8 +25,7 @@ class AuthorizationFailure(Exception): class NoTokenLookupException(Exception): - """This form of authentication does not support looking up - endpoints from an existing token.""" + """This does not support looking up endpoints from an existing token.""" pass @@ -38,15 +35,12 @@ class EndpointNotFound(Exception): class UnsupportedVersion(Exception): - """Indicates that the user is trying to use an unsupported - version of the API""" + """The user is trying to use an unsupported version of the API""" pass class ClientException(Exception): - """ - The base exception class for all exceptions this library raises. - """ + """The base exception class for all exceptions this library raises.""" def __init__(self, code, message=None, details=None): self.code = code self.message = message or self.__class__.message @@ -57,59 +51,44 @@ class ClientException(Exception): class BadRequest(ClientException): - """ - HTTP 400 - Bad request: you sent some malformed data. - """ + """HTTP 400 - Bad request: you sent some malformed data.""" http_status = 400 message = "Bad request" class Unauthorized(ClientException): - """ - HTTP 401 - Unauthorized: bad credentials. - """ + """HTTP 401 - Unauthorized: bad credentials.""" http_status = 401 message = "Unauthorized" class Forbidden(ClientException): - """ - HTTP 403 - Forbidden: your credentials don't give you access to this - resource. - """ + """HTTP 403 - Forbidden: not authorized to access to this resource.""" http_status = 403 message = "Forbidden" class NotFound(ClientException): - """ - HTTP 404 - Not found - """ + """HTTP 404 - Not found""" http_status = 404 message = "Not found" class Conflict(ClientException): - """ - HTTP 409 - Conflict - """ + """HTTP 409 - Conflict""" http_status = 409 message = "Conflict" class OverLimit(ClientException): - """ - HTTP 413 - Over limit: you're over the API limits for this time period. - """ + """HTTP 413 - Over limit: reached the API limits for this time period.""" http_status = 413 message = "Over limit" # NotImplemented is a python keyword. class HTTPNotImplemented(ClientException): - """ - HTTP 501 - Not Implemented: the server does not support this operation. - """ + """HTTP 501 - Not Implemented: server does not support this operation.""" http_status = 501 message = "Not Implemented" @@ -120,14 +99,18 @@ class HTTPNotImplemented(ClientException): # for c in ClientException.__subclasses__()) # # Instead, we have to hardcode it: -_code_map = dict((c.http_status, c) for c in [BadRequest, Unauthorized, - Forbidden, NotFound, OverLimit, HTTPNotImplemented]) +_code_map = dict((c.http_status, c) for c in [ + BadRequest, + Unauthorized, + Forbidden, + NotFound, + OverLimit, + HTTPNotImplemented +]) def from_response(response, body): - """ - Return an instance of a ClientException or subclass - based on an httplib2 response. + """Return an instance of a ClientException based on an httplib2 response. Usage:: diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py index 19cca3f..6477285 100644 --- a/openstackclient/common/utils.py +++ b/openstackclient/common/utils.py @@ -13,9 +13,7 @@ # under the License. # -""" -Common client utilities -""" +"""Common client utilities""" import os import sys diff --git a/openstackclient/shell.py b/openstackclient/shell.py index c007fc5..5dc0457 100644 --- a/openstackclient/shell.py +++ b/openstackclient/shell.py @@ -13,9 +13,7 @@ # under the License. # -""" -Command-line interface to the OpenStack APIs -""" +"""Command-line interface to the OpenStack APIs""" import getpass import logging @@ -59,8 +57,7 @@ class OpenStackShell(App): super(OpenStackShell, self).__init__( description=__doc__.strip(), version=VERSION, - command_manager=CommandManager('openstack.cli'), - ) + command_manager=CommandManager('openstack.cli')) # This is instantiated in initialize_app() only when using # password flow auth @@ -69,57 +66,64 @@ class OpenStackShell(App): def build_option_parser(self, description, version): parser = super(OpenStackShell, self).build_option_parser( description, - version, - ) + version) # Global arguments - parser.add_argument('--os-auth-url', metavar='', + parser.add_argument( + '--os-auth-url', + metavar='', default=env('OS_AUTH_URL'), help='Authentication URL (Env: OS_AUTH_URL)') - - parser.add_argument('--os-tenant-name', metavar='', + parser.add_argument( + '--os-tenant-name', + metavar='', default=env('OS_TENANT_NAME'), help='Authentication tenant name (Env: OS_TENANT_NAME)') - - parser.add_argument('--os-tenant-id', metavar='', + parser.add_argument( + '--os-tenant-id', + metavar='', default=env('OS_TENANT_ID'), help='Authentication tenant ID (Env: OS_TENANT_ID)') - - parser.add_argument('--os-username', metavar='', + parser.add_argument( + '--os-username', + metavar='', default=utils.env('OS_USERNAME'), help='Authentication username (Env: OS_USERNAME)') - - parser.add_argument('--os-password', metavar='', + parser.add_argument( + '--os-password', + metavar='', default=utils.env('OS_PASSWORD'), help='Authentication password (Env: OS_PASSWORD)') - - parser.add_argument('--os-region-name', metavar='', + parser.add_argument( + '--os-region-name', + metavar='', default=env('OS_REGION_NAME'), help='Authentication region name (Env: OS_REGION_NAME)') - - parser.add_argument('--os-identity-api-version', + parser.add_argument( + '--os-identity-api-version', metavar='', default=env('OS_IDENTITY_API_VERSION', default='2.0'), help='Identity API version, default=2.0 ' - '(Env: OS_IDENTITY_API_VERSION)') - - parser.add_argument('--os-compute-api-version', + '(Env: OS_IDENTITY_API_VERSION)') + parser.add_argument( + '--os-compute-api-version', metavar='', default=env('OS_COMPUTE_API_VERSION', default='2'), help='Compute API version, default=2 ' - '(Env: OS_COMPUTE_API_VERSION)') - - parser.add_argument('--os-image-api-version', + '(Env: OS_COMPUTE_API_VERSION)') + parser.add_argument( + '--os-image-api-version', metavar='', default=env('OS_IMAGE_API_VERSION', default='1.0'), - help='Image API version, default=1.0 ' - '(Env: OS_IMAGE_API_VERSION)') - - parser.add_argument('--os-token', metavar='', + help='Image API version, default=1.0 (Env: OS_IMAGE_API_VERSION)') + parser.add_argument( + '--os-token', + metavar='', default=env('OS_TOKEN'), help='Defaults to env[OS_TOKEN]') - - parser.add_argument('--os-url', metavar='', + parser.add_argument( + '--os-url', + metavar='', default=env('OS_URL'), help='Defaults to env[OS_URL]') @@ -198,8 +202,7 @@ class OpenStackShell(App): username=self.options.os_username, password=self.options.os_password, region_name=self.options.os_region_name, - api_version=self.api_version, - ) + api_version=self.api_version) return def init_keyring_backend(self): @@ -260,7 +263,6 @@ class OpenStackShell(App): def prepare_to_run_command(self, cmd): """Set up auth and API versions""" self.log.debug('prepare_to_run_command %s', cmd.__class__.__name__) - self.log.debug("api: %s" % cmd.api if hasattr(cmd, 'api') else None) return diff --git a/setup.py b/setup.py index 4d4f240..6ee3d45 100644 --- a/setup.py +++ b/setup.py @@ -40,14 +40,14 @@ setuptools.setup( author_email='openstack@lists.launchpad.net', packages=setuptools.find_packages(exclude=['tests', 'tests.*']), classifiers=[ - 'Development Status :: 2 - Pre-Alpha', - 'Environment :: Console', - 'Environment :: OpenStack', - 'Intended Audience :: Developers', - 'Intended Audience :: Information Technology', - 'License :: OSI Approved :: Apache Software License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', + 'Development Status :: 2 - Pre-Alpha', + 'Environment :: Console', + 'Environment :: OpenStack', + 'Intended Audience :: Developers', + 'Intended Audience :: Information Technology', + 'License :: OSI Approved :: Apache Software License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', ], install_requires=requires, dependency_links=dependency_links, @@ -56,25 +56,23 @@ setuptools.setup( 'console_scripts': ['openstack=openstackclient.shell:main'], 'openstack.cli': [ 'create_endpoint=' + - 'openstackclient.identity.v2_0.endpoint:CreateEndpoint', + 'openstackclient.identity.v2_0.endpoint:CreateEndpoint', 'delete_endpoint=' + - 'openstackclient.identity.v2_0.endpoint:DeleteEndpoint', + 'openstackclient.identity.v2_0.endpoint:DeleteEndpoint', 'list_endpoint=' + - 'openstackclient.identity.v2_0.endpoint:ListEndpoint', + 'openstackclient.identity.v2_0.endpoint:ListEndpoint', 'show_endpoint=' + - 'openstackclient.identity.v2_0.endpoint:ShowEndpoint', - + 'openstackclient.identity.v2_0.endpoint:ShowEndpoint', 'add_role=' + - 'openstackclient.identity.v2_0.role:AddRole', + 'openstackclient.identity.v2_0.role:AddRole', 'create_role=' + - 'openstackclient.identity.v2_0.role:CreateRole', + 'openstackclient.identity.v2_0.role:CreateRole', 'delete_role=' + - 'openstackclient.identity.v2_0.role:DeleteRole', + 'openstackclient.identity.v2_0.role:DeleteRole', 'list_role=openstackclient.identity.v2_0.role:ListRole', 'remove_role=' + - 'openstackclient.identity.v2_0.role:RemoveRole', + 'openstackclient.identity.v2_0.role:RemoveRole', 'show_role=openstackclient.identity.v2_0.role:ShowRole', - 'create_server=openstackclient.compute.v2.server:CreateServer', 'delete_server=openstackclient.compute.v2.server:DeleteServer', 'list_server=openstackclient.compute.v2.server:ListServer', @@ -85,26 +83,23 @@ setuptools.setup( 'show_server=openstackclient.compute.v2.server:ShowServer', 'suspend_server=openstackclient.compute.v2.server:SuspendServer', 'unpause_server=openstackclient.compute.v2.server:UnpauseServer', - 'create_service=' + - 'openstackclient.identity.v2_0.service:CreateService', + 'openstackclient.identity.v2_0.service:CreateService', 'delete_service=' + - 'openstackclient.identity.v2_0.service:DeleteService', + 'openstackclient.identity.v2_0.service:DeleteService', 'list_service=openstackclient.identity.v2_0.service:ListService', 'show_service=openstackclient.identity.v2_0.service:ShowService', - 'create_tenant=' + - 'openstackclient.identity.v2_0.tenant:CreateTenant', + 'openstackclient.identity.v2_0.tenant:CreateTenant', 'delete_tenant=' + - 'openstackclient.identity.v2_0.tenant:DeleteTenant', + 'openstackclient.identity.v2_0.tenant:DeleteTenant', 'list_tenant=openstackclient.identity.v2_0.tenant:ListTenant', 'set_tenant=openstackclient.identity.v2_0.tenant:SetTenant', 'show_tenant=openstackclient.identity.v2_0.tenant:ShowTenant', - 'create_user=' + - 'openstackclient.identity.v2_0.user:CreateUser', + 'openstackclient.identity.v2_0.user:CreateUser', 'delete_user=' + - 'openstackclient.identity.v2_0.user:DeleteUser', + 'openstackclient.identity.v2_0.user:DeleteUser', 'list_user=openstackclient.identity.v2_0.user:ListUser', 'set_user=openstackclient.identity.v2_0.user:SetUser', 'show_user=openstackclient.identity.v2_0.user:ShowUser', @@ -118,9 +113,9 @@ setuptools.setup( 'show_group=openstackclient.identity.v3.group:ShowGroup', 'list_group=openstackclient.identity.v3.group:ListGroup', 'create_project=' + - 'openstackclient.identity.v3.project:CreateProject', + 'openstackclient.identity.v3.project:CreateProject', 'delete_project=' + - 'openstackclient.identity.v3.project:DeleteProject', + 'openstackclient.identity.v3.project:DeleteProject', 'set_project=openstackclient.identity.v3.project:SetProject', 'show_project=openstackclient.identity.v3.project:ShowProject', 'list_project=openstackclient.identity.v3.project:ListProject', diff --git a/tox.ini b/tox.ini index 6b4a96d..fb1b2ba 100644 --- a/tox.ini +++ b/tox.ini @@ -11,7 +11,7 @@ deps = -r{toxinidir}/tools/pip-requires commands = python setup.py testr --testr-args='{posargs}' [testenv:pep8] -deps = pep8==1.1 +deps = pep8==1.3.3 commands = pep8 --repeat --show-source openstackclient setup.py [testenv:venv]