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,
region=None, service_type=None, service_name=None,

@ -209,12 +209,13 @@ COMMANDS = {'auth': common.Auth,
'version': VersionCommands,
}
def main():
# Parse arguments
load_file=True
load_file = True
for index, arg in enumerate(sys.argv):
if (arg == "auth" and len(sys.argv) > (index + 1)
and sys.argv[index + 1]=="login"):
and sys.argv[index + 1] == "login"):
load_file = False
oparser = common.CliOptions.create_optparser(load_file)
@ -226,7 +227,7 @@ def main():
common.print_commands(COMMANDS)
if options.verbose:
os.environ['RDC_PP'] = "True"
os.environ['RDC_PP'] = "True"
os.environ['REDDWARFCLIENT_DEBUG'] = "True"
# 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)
def morph_request(self, kwargs):
kwargs['headers']['Accept'] = 'application/json'
kwargs['headers']['Content-Type'] = 'application/json'
if 'body' in kwargs:
kwargs['headers']['Accept'] = 'application/json'
kwargs['headers']['Content-Type'] = 'application/json'
if 'body' in kwargs:
kwargs['body'] = json.dumps(kwargs['body'])
def morph_response_body(self, body_string):
@ -274,7 +274,6 @@ class ReddwarfHTTPClient(httplib2.Http):
self.service_url = service_url
class Dbaas(object):
"""
Top-level object to access the Rackspace Database as a Service API.

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

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

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

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

@ -6,15 +6,15 @@ from reddwarfclient import exceptions
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.
LISTIFY = {
"accounts":[[]],
"databases":[[]],
"accounts": [[]],
"databases": [[]],
"flavors": [[]],
"instances": [[]],
"links" : [["flavor", "instance", "instances"],
"links": [["flavor", "instance", "instances"],
["instance", "instances"]],
"hosts": [[]],
"devices": [[]],
@ -24,6 +24,7 @@ LISTIFY = {
REQUEST_AS_LIST = set(['databases', 'users'])
def element_ancestors_match_list(element, list):
"""
For element root at <foo><blah><root></blah></foo> matches against
@ -55,9 +56,10 @@ def element_to_json(name, element):
else:
return element_to_dict(element)
def root_element_to_json(name, element):
"""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
elif element_must_be_list(element, name):
return element_to_list(element, True)
@ -203,7 +205,7 @@ class ReddwarfXmlClient(ReddwarfHTTPClient):
raise exceptions.ResponseFormatError()
root_name = normalize_tag(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:
result['links'] = links
return result

@ -11,3 +11,6 @@ deps =
commands =
sphinx-build -b doctest {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