Only pep8 violations fix

fix pep8 violations

fix tox configurtion for pep8

fix pretty print for actions that return a response body

Change-Id: I39a529bda8780649a5159761af7103eee8520412
This commit is contained in:
Vipul Sabhaya 2012-10-30 13:47:05 -07:00
parent 88c74ba804
commit 844492a8eb
9 changed files with 41 additions and 34 deletions

@ -42,7 +42,7 @@ class Authenticator(object):
""" """
URL_REQUIRED=True URL_REQUIRED = True
def __init__(self, client, type, url, username, password, tenant, def __init__(self, client, type, url, username, password, tenant,
region=None, service_type=None, service_name=None, region=None, service_type=None, service_name=None,

@ -209,12 +209,13 @@ COMMANDS = {'auth': common.Auth,
'version': VersionCommands, 'version': VersionCommands,
} }
def main(): def main():
# Parse arguments # Parse arguments
load_file=True load_file = True
for index, arg in enumerate(sys.argv): for index, arg in enumerate(sys.argv):
if (arg == "auth" and len(sys.argv) > (index + 1) if (arg == "auth" and len(sys.argv) > (index + 1)
and sys.argv[index + 1]=="login"): and sys.argv[index + 1] == "login"):
load_file = False load_file = False
oparser = common.CliOptions.create_optparser(load_file) oparser = common.CliOptions.create_optparser(load_file)
@ -226,7 +227,7 @@ def main():
common.print_commands(COMMANDS) common.print_commands(COMMANDS)
if options.verbose: if options.verbose:
os.environ['RDC_PP'] = "True" os.environ['RDC_PP'] = "True"
os.environ['REDDWARFCLIENT_DEBUG'] = "True" os.environ['REDDWARFCLIENT_DEBUG'] = "True"
# Pop the command and check if it's in the known commands # Pop the command and check if it's in the known commands

@ -194,9 +194,9 @@ class ReddwarfHTTPClient(httplib2.Http):
raise exceptions.from_response(resp, body) raise exceptions.from_response(resp, body)
def morph_request(self, kwargs): def morph_request(self, kwargs):
kwargs['headers']['Accept'] = 'application/json' kwargs['headers']['Accept'] = 'application/json'
kwargs['headers']['Content-Type'] = 'application/json' kwargs['headers']['Content-Type'] = 'application/json'
if 'body' in kwargs: if 'body' in kwargs:
kwargs['body'] = json.dumps(kwargs['body']) kwargs['body'] = json.dumps(kwargs['body'])
def morph_response_body(self, body_string): def morph_response_body(self, body_string):
@ -274,7 +274,6 @@ class ReddwarfHTTPClient(httplib2.Http):
self.service_url = service_url self.service_url = service_url
class Dbaas(object): class Dbaas(object):
""" """
Top-level object to access the Rackspace Database as a Service API. Top-level object to access the Rackspace Database as a Service API.

@ -75,20 +75,20 @@ class CliOptions(object):
APITOKEN = os.path.expanduser("~/.apitoken") APITOKEN = os.path.expanduser("~/.apitoken")
DEFAULT_VALUES = { DEFAULT_VALUES = {
'username':None, 'username': None,
'apikey':None, 'apikey': None,
'tenant_id':None, 'tenant_id': None,
'auth_url':None, 'auth_url': None,
'auth_type':'keystone', 'auth_type': 'keystone',
'service_type':'reddwarf', 'service_type': 'reddwarf',
'service_name':'Reddwarf', 'service_name': 'Reddwarf',
'region':'RegionOne', 'region': 'RegionOne',
'service_url':None, 'service_url': None,
'insecure':False, 'insecure': False,
'verbose':False, 'verbose': False,
'debug':False, 'debug': False,
'token':None, 'token': None,
'xml':None, 'xml': None,
} }
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -111,7 +111,6 @@ class CliOptions(object):
print("ERROR: Token file found at %s was corrupt." % cls.APITOKEN) print("ERROR: Token file found at %s was corrupt." % cls.APITOKEN)
return cls.default() return cls.default()
@classmethod @classmethod
def save_from_instance_fields(cls, instance): def save_from_instance_fields(cls, instance):
apitoken = cls.default() apitoken = cls.default()
@ -121,7 +120,6 @@ class CliOptions(object):
with open(cls.APITOKEN, 'wb') as token: with open(cls.APITOKEN, 'wb') as token:
pickle.dump(apitoken, token, protocol=2) pickle.dump(apitoken, token, protocol=2)
@classmethod @classmethod
def create_optparser(cls, load_file): def create_optparser(cls, load_file):
oparser = optparse.OptionParser( oparser = optparse.OptionParser(
@ -131,6 +129,7 @@ class CliOptions(object):
file = cls.load_from_file() file = cls.load_from_file()
else: else:
file = cls.default() file = cls.default()
def add_option(*args, **kwargs): def add_option(*args, **kwargs):
if len(args) == 1: if len(args) == 1:
name = args[0] name = args[0]
@ -165,7 +164,6 @@ class CliOptions(object):
add_option("token", help="Token from a prior login.") add_option("token", help="Token from a prior login.")
add_option("xml", action="store_true", help="Changes format to XML.") add_option("xml", action="store_true", help="Changes format to XML.")
oparser.add_option("--secure", action="store_false", dest="insecure", oparser.add_option("--secure", action="store_false", dest="insecure",
help="Run in insecure mode for https endpoints.") help="Run in insecure mode for https endpoints.")
oparser.add_option("--json", action="store_false", dest="xml", oparser.add_option("--json", action="store_false", dest="xml",
@ -256,6 +254,7 @@ class CommandsBase(object):
if self.verbose: if self.verbose:
self._safe_exec(func, *args, **kwargs) self._safe_exec(func, *args, **kwargs)
return # Skip this, since the verbose stuff will show up anyway. return # Skip this, since the verbose stuff will show up anyway.
def wrapped_func(): def wrapped_func():
result = func(*args, **kwargs) result = func(*args, **kwargs)
if result: if result:

@ -35,8 +35,8 @@ class DiagnosticsInterrogator(base.ManagerWithFind):
""" """
Get the diagnostics of the guest on the instance. Get the diagnostics of the guest on the instance.
""" """
return self._get("/mgmt/instances/%s/diagnostics" % base.getid(instance), return self._get("/mgmt/instances/%s/diagnostics" %
"diagnostics") base.getid(instance), "diagnostics")
class HwInfo(base.Resource): class HwInfo(base.Resource):

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
class UnsupportedVersion(Exception): class UnsupportedVersion(Exception):
"""Indicates that the user is trying to use an unsupported """Indicates that the user is trying to use an unsupported
version of the API""" version of the API"""
@ -55,6 +56,7 @@ class ResponseFormatError(Exception):
"""Could not parse the response format.""" """Could not parse the response format."""
pass pass
class AmbiguousEndpoints(Exception): class AmbiguousEndpoints(Exception):
"""Found more than one matching endpoint in Service Catalog.""" """Found more than one matching endpoint in Service Catalog."""
def __init__(self, endpoints=None): def __init__(self, endpoints=None):

@ -155,9 +155,10 @@ class Instances(base.ManagerWithFind):
""" """
body = {'reset-password': {}} body = {'reset-password': {}}
return self._action(instance_id, body) return self._action(instance_id, body)
Instances.resize_flavor = Instances.resize_instance Instances.resize_flavor = Instances.resize_instance
class InstanceStatus(object): class InstanceStatus(object):
ACTIVE = "ACTIVE" ACTIVE = "ACTIVE"

@ -6,15 +6,15 @@ from reddwarfclient import exceptions
from reddwarfclient.client import ReddwarfHTTPClient from reddwarfclient.client import ReddwarfHTTPClient
XML_NS = { None: "http://docs.openstack.org/database/api/v1.0" } XML_NS = {None: "http://docs.openstack.org/database/api/v1.0"}
# This dictionary contains XML paths of things that should become list items. # This dictionary contains XML paths of things that should become list items.
LISTIFY = { LISTIFY = {
"accounts":[[]], "accounts": [[]],
"databases":[[]], "databases": [[]],
"flavors": [[]], "flavors": [[]],
"instances": [[]], "instances": [[]],
"links" : [["flavor", "instance", "instances"], "links": [["flavor", "instance", "instances"],
["instance", "instances"]], ["instance", "instances"]],
"hosts": [[]], "hosts": [[]],
"devices": [[]], "devices": [[]],
@ -24,6 +24,7 @@ LISTIFY = {
REQUEST_AS_LIST = set(['databases', 'users']) REQUEST_AS_LIST = set(['databases', 'users'])
def element_ancestors_match_list(element, list): def element_ancestors_match_list(element, list):
""" """
For element root at <foo><blah><root></blah></foo> matches against For element root at <foo><blah><root></blah></foo> matches against
@ -55,9 +56,10 @@ def element_to_json(name, element):
else: else:
return element_to_dict(element) return element_to_dict(element)
def root_element_to_json(name, element): def root_element_to_json(name, element):
"""Returns a tuple of the root JSON value, plus the links if found.""" """Returns a tuple of the root JSON value, plus the links if found."""
if name == "rootEnabled": # Why oh why were we inconsistent here? :'( if name == "rootEnabled": # Why oh why were we inconsistent here? :'(
return bool(element.text), None return bool(element.text), None
elif element_must_be_list(element, name): elif element_must_be_list(element, name):
return element_to_list(element, True) return element_to_list(element, True)
@ -203,7 +205,7 @@ class ReddwarfXmlClient(ReddwarfHTTPClient):
raise exceptions.ResponseFormatError() raise exceptions.ResponseFormatError()
root_name = normalize_tag(root_element) root_name = normalize_tag(root_element)
root_value, links = root_element_to_json(root_name, root_element) root_value, links = root_element_to_json(root_name, root_element)
result = { root_name:root_value } result = {root_name: root_value}
if links: if links:
result['links'] = links result['links'] = links
return result return result

@ -11,3 +11,6 @@ deps =
commands = commands =
sphinx-build -b doctest {toxinidir}/docs/source {envtmpdir}/html sphinx-build -b doctest {toxinidir}/docs/source {envtmpdir}/html
sphinx-build -b html {toxinidir}/docs/source {envtmpdir}/html sphinx-build -b html {toxinidir}/docs/source {envtmpdir}/html
[testenv:pep8]
commands = pep8 --repeat --show-source --exclude=.venv,.tox,dist,doc reddwarfclient setup.py