Skip to content

Commit 8bbd902

Browse files
committed
Adds hacking to pep8 tox tests. Fixes many errors
1 parent 484d4ee commit 8bbd902

File tree

134 files changed

+2487
-2247
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+2487
-2247
lines changed

SoftLayer/API.py

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
"""
88
import time
99

10-
from .consts import API_PUBLIC_ENDPOINT, API_PRIVATE_ENDPOINT, USER_AGENT
11-
from .transports import make_xml_rpc_api_call
12-
from .auth import TokenAuthentication
13-
from .config import get_client_settings
14-
10+
from SoftLayer import auth as slauth
11+
from SoftLayer import config
12+
from SoftLayer import consts
13+
from SoftLayer import transports
1514

15+
API_PUBLIC_ENDPOINT = consts.API_PUBLIC_ENDPOINT
16+
API_PRIVATE_ENDPOINT = consts.API_PRIVATE_ENDPOINT
1617
__all__ = ['Client', 'TimedClient', 'API_PUBLIC_ENDPOINT',
1718
'API_PRIVATE_ENDPOINT']
1819

@@ -29,7 +30,7 @@
2930

3031

3132
class Client(object):
32-
""" A SoftLayer API client.
33+
"""A SoftLayer API client.
3334
3435
:param username: an optional API username if you wish to bypass the
3536
package's built-in username
@@ -58,13 +59,13 @@ class Client(object):
5859
def __init__(self, username=None, api_key=None, endpoint_url=None,
5960
timeout=None, auth=None, config_file=None, proxy=None):
6061

61-
settings = get_client_settings(username=username,
62-
api_key=api_key,
63-
endpoint_url=endpoint_url,
64-
timeout=timeout,
65-
auth=auth,
66-
proxy=proxy,
67-
config_file=config_file)
62+
settings = config.get_client_settings(username=username,
63+
api_key=api_key,
64+
endpoint_url=endpoint_url,
65+
timeout=timeout,
66+
auth=auth,
67+
proxy=proxy,
68+
config_file=config_file)
6869
self.auth = settings.get('auth')
6970
self.endpoint_url = (
7071
settings.get('endpoint_url') or API_PUBLIC_ENDPOINT).rstrip('/')
@@ -78,8 +79,7 @@ def __init__(self, username=None, api_key=None, endpoint_url=None,
7879
def authenticate_with_password(self, username, password,
7980
security_question_id=None,
8081
security_question_answer=None):
81-
""" Performs Username/Password Authentication and gives back an auth
82-
handler to use to create a client that uses token-based auth.
82+
"""Performs Username/Password Authentication
8383
8484
:param string username: your SoftLayer username
8585
:param string password: your SoftLayer password
@@ -94,11 +94,11 @@ def authenticate_with_password(self, username, password,
9494
password,
9595
security_question_id,
9696
security_question_answer)
97-
self.auth = TokenAuthentication(res['userId'], res['hash'])
97+
self.auth = slauth.TokenAuthentication(res['userId'], res['hash'])
9898
return res['userId'], res['hash']
9999

100100
def __getitem__(self, name):
101-
""" Get a SoftLayer Service.
101+
"""Get a SoftLayer Service.
102102
103103
:param name: The name of the service. E.G. Account
104104
@@ -112,7 +112,7 @@ def __getitem__(self, name):
112112
return Service(self, name)
113113

114114
def call(self, service, method, *args, **kwargs):
115-
""" Make a SoftLayer API call
115+
"""Make a SoftLayer API call
116116
117117
:param service: the name of the SoftLayer API service
118118
:param method: the method to call on the service
@@ -162,7 +162,7 @@ def call(self, service, method, *args, **kwargs):
162162
}
163163

164164
http_headers = {
165-
'User-Agent': USER_AGENT,
165+
'User-Agent': consts.USER_AGENT,
166166
'Content-Type': 'application/xml',
167167
}
168168

@@ -174,17 +174,17 @@ def call(self, service, method, *args, **kwargs):
174174
http_headers.update(kwargs.get('raw_headers'))
175175

176176
uri = '/'.join([self.endpoint_url, service])
177-
return make_xml_rpc_api_call(uri, method, args,
178-
headers=headers,
179-
http_headers=http_headers,
180-
timeout=self.timeout,
181-
proxy=self.proxy)
177+
return transports.make_xml_rpc_api_call(uri, method, args,
178+
headers=headers,
179+
http_headers=http_headers,
180+
timeout=self.timeout,
181+
proxy=self.proxy)
182182

183183
__call__ = call
184184

185185
def iter_call(self, service, method,
186186
chunk=100, limit=None, offset=0, *args, **kwargs):
187-
""" A generator that deals with paginating through results.
187+
"""A generator that deals with paginating through results.
188188
189189
:param service: the name of the SoftLayer API service
190190
:param method: the method to call on the service
@@ -234,7 +234,7 @@ def iter_call(self, service, method,
234234
break
235235

236236
def __format_object_mask(self, objectmask, service):
237-
""" Format new and old style object masks into proper headers.
237+
"""Format new and old style object masks into proper headers.
238238
239239
:param objectmask: a string- or dict-based object mask
240240
:param service: a SoftLayer API service name
@@ -246,15 +246,15 @@ def __format_object_mask(self, objectmask, service):
246246
mheader = self._prefix + 'ObjectMask'
247247

248248
objectmask = objectmask.strip()
249-
if not objectmask.startswith('mask') \
250-
and not objectmask.startswith('['):
249+
if (not objectmask.startswith('mask')
250+
and not objectmask.startswith('[')):
251251
objectmask = "mask[%s]" % objectmask
252252

253253
return {mheader: {'mask': objectmask}}
254254

255255
def __repr__(self):
256-
return "<Client: endpoint=%s, user=%r>" \
257-
% (self.endpoint_url, self.auth)
256+
return "<Client: endpoint=%s, user=%r>" % (self.endpoint_url,
257+
self.auth)
258258

259259
__str__ = __repr__
260260

@@ -263,19 +263,20 @@ def __len__(self):
263263

264264

265265
class TimedClient(Client):
266-
""" Subclass of Client()
266+
"""Client that records API call timings.
267267
268268
Using this class will time every call to the API and store it in an
269269
internal list. This will have a slight impact on your client's memory
270270
usage and performance. You should only use this for debugging.
271+
271272
"""
272273

273274
def __init__(self, *args, **kwargs):
274275
self.last_calls = []
275276
super(TimedClient, self).__init__(*args, **kwargs)
276277

277278
def call(self, service, method, *args, **kwargs):
278-
""" See Client.call for documentation. """
279+
"""See Client.call for documentation."""
279280
start_time = time.time()
280281
result = super(TimedClient, self).call(service, method, *args,
281282
**kwargs)
@@ -285,7 +286,7 @@ def call(self, service, method, *args, **kwargs):
285286
return result
286287

287288
def get_last_calls(self):
288-
""" Retrieves the last_calls property.
289+
"""Retrieves the last_calls property.
289290
290291
This property will contain a list of tuples in the form
291292
('SERVICE.METHOD', initiated_utc_timestamp, execution_time)
@@ -296,7 +297,8 @@ def get_last_calls(self):
296297

297298

298299
class Service(object):
299-
""" A SoftLayer Service.
300+
"""A SoftLayer Service.
301+
300302
:param client: A SoftLayer.API.Client instance
301303
:param name str: The service name
302304
@@ -306,7 +308,7 @@ def __init__(self, client, name):
306308
self.name = name
307309

308310
def call(self, name, *args, **kwargs):
309-
""" Make a SoftLayer API call
311+
"""Make a SoftLayer API call.
310312
311313
:param method: the method to call on the service
312314
:param \\*args: (optional) arguments for the remote call
@@ -333,7 +335,7 @@ def call(self, name, *args, **kwargs):
333335
__call__ = call
334336

335337
def iter_call(self, name, *args, **kwargs):
336-
""" A generator that deals with paginating through results.
338+
"""A generator that deals with paginating through results.
337339
338340
:param method: the method to call on the service
339341
:param integer chunk: result size for each API call

SoftLayer/CLI/core.py

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@
4444
"""
4545
# :license: MIT, see LICENSE for more details.
4646

47-
import sys
4847
import logging
48+
import sys
4949

50-
from docopt import docopt, DocoptExit
50+
import docopt
5151

52-
from SoftLayer import Client, TimedClient, SoftLayerError, SoftLayerAPIError
53-
from SoftLayer.consts import VERSION
54-
from .helpers import CLIAbort, ArgumentError, format_output, KeyValueTable
55-
from .environment import Environment, InvalidCommand, InvalidModule
52+
import SoftLayer
53+
from SoftLayer.CLI import environment
54+
from SoftLayer.CLI import exceptions
55+
from SoftLayer.CLI import formatting
56+
from SoftLayer import consts
5657

5758

5859
DEBUG_LOGGING_MAP = {
@@ -66,25 +67,25 @@
6667

6768

6869
class CommandParser(object):
69-
""" Helper class to parse commands
70+
"""Helper class to parse commands.
7071
7172
:param env: Environment instance
7273
"""
7374
def __init__(self, env):
7475
self.env = env
7576

7677
def get_main_help(self):
77-
""" Get main help text """
78+
"""Get main help text."""
7879
return __doc__.strip()
7980

8081
def get_module_help(self, module_name):
81-
""" Get help text for a module """
82+
"""Get help text for a module."""
8283
module = self.env.load_module(module_name)
8384
arg_doc = module.__doc__
8485
return arg_doc.strip()
8586

8687
def get_command_help(self, module_name, command_name):
87-
""" Get help text for a specific command """
88+
"""Get help text for a specific command."""
8889
command = self.env.get_command(module_name, command_name)
8990

9091
default_format = 'raw'
@@ -113,35 +114,37 @@ def get_command_help(self, module_name, command_name):
113114
return arg_doc.strip()
114115

115116
def parse_main_args(self, args):
116-
""" Parse root arguments """
117+
"""Parse root arguments."""
117118
main_help = self.get_main_help()
118-
arguments = docopt(
119+
arguments = docopt.docopt(
119120
main_help,
120-
version=VERSION,
121+
version=consts.VERSION,
121122
argv=args,
122123
options_first=True)
123124
arguments['<module>'] = self.env.get_module_name(arguments['<module>'])
124125
return arguments
125126

126127
def parse_module_args(self, module_name, args):
127-
""" Parse module arguments """
128+
"""Parse module arguments."""
128129
arg_doc = self.get_module_help(module_name)
129-
arguments = docopt(
130+
arguments = docopt.docopt(
130131
arg_doc,
131-
version=VERSION,
132+
version=consts.VERSION,
132133
argv=[module_name] + args,
133134
options_first=True)
134135
return arguments
135136

136137
def parse_command_args(self, module_name, command_name, args):
137-
""" Parse command arguments """
138+
"""Parse command arguments."""
138139
command = self.env.get_command(module_name, command_name)
139140
arg_doc = self.get_command_help(module_name, command_name)
140-
arguments = docopt(arg_doc, version=VERSION, argv=[module_name] + args)
141+
arguments = docopt.docopt(arg_doc,
142+
version=consts.VERSION,
143+
argv=[module_name] + args)
141144
return command, arguments
142145

143146
def parse(self, args):
144-
""" Parse entire tree of arguments """
147+
"""Parse entire tree of arguments."""
145148
# handle `sl ...`
146149
main_args = self.parse_main_args(args)
147150
module_name = main_args['<module>']
@@ -159,10 +162,8 @@ def parse(self, args):
159162
main_args['<args>'])
160163

161164

162-
def main(args=sys.argv[1:], env=Environment()):
163-
"""
164-
Entry point for the command-line client.
165-
"""
165+
def main(args=sys.argv[1:], env=environment.Environment()):
166+
"""Entry point for the command-line client."""
166167
# Parse Top-Level Arguments
167168
exit_status = 0
168169
resolver = CommandParser(env)
@@ -182,64 +183,65 @@ def main(args=sys.argv[1:], env=Environment()):
182183
'config_file': command_args.get('--config')
183184
}
184185
if command_args.get('--timings'):
185-
client = TimedClient(**kwargs)
186+
client = SoftLayer.TimedClient(**kwargs)
186187
else:
187-
client = Client(**kwargs)
188+
client = SoftLayer.Client(**kwargs)
188189

189190
# Do the thing
190191
runnable = command(client=client, env=env)
191192
data = runnable.execute(command_args)
192193
if data:
193194
out_format = command_args.get('--format', 'table')
194195
if out_format not in VALID_FORMATS:
195-
raise ArgumentError('Invalid format "%s"' % out_format)
196-
output = format_output(data, fmt=out_format)
196+
raise exceptions.ArgumentError('Invalid format "%s"'
197+
% out_format)
198+
output = formatting.format_output(data, fmt=out_format)
197199
if output:
198200
env.out(output)
199201

200202
if command_args.get('--timings'):
201203
out_format = command_args.get('--format', 'table')
202204
api_calls = client.get_last_calls()
203-
timing_table = KeyValueTable(['call', 'time'])
205+
timing_table = formatting.KeyValueTable(['call', 'time'])
204206

205207
for call, _, duration in api_calls:
206208
timing_table.add_row([call, duration])
207209

208-
env.err(format_output(timing_table, fmt=out_format))
210+
env.err(formatting.format_output(timing_table, fmt=out_format))
209211

210-
except InvalidCommand as ex:
212+
except exceptions.InvalidCommand as ex:
211213
env.err(resolver.get_module_help(ex.module_name))
212214
if ex.command_name:
213215
env.err('')
214216
env.err(str(ex))
215217
exit_status = 1
216-
except InvalidModule as ex:
218+
except exceptions.InvalidModule as ex:
217219
env.err(resolver.get_main_help())
218220
if ex.module_name:
219221
env.err('')
220222
env.err(str(ex))
221223
exit_status = 1
222-
except DocoptExit as ex:
224+
except docopt.DocoptExit as ex:
223225
env.err(ex.usage)
224226
env.err(
225227
'\nUnknown argument(s), use -h or --help for available options')
226228
exit_status = 127
227229
except KeyboardInterrupt:
228230
env.out('')
229231
exit_status = 1
230-
except CLIAbort as ex:
232+
except exceptions.CLIAbort as ex:
231233
env.err(str(ex.message))
232234
exit_status = ex.code
233235
except SystemExit as ex:
234236
exit_status = ex.code
235-
except SoftLayerAPIError as ex:
237+
except SoftLayer.SoftLayerAPIError as ex:
236238
if 'invalid api token' in ex.faultString.lower():
237239
env.out("Authentication Failed: To update your credentials, use "
238240
"'sl config setup'")
239241
else:
240242
env.err(str(ex))
241243
exit_status = 1
242-
except SoftLayerError as ex:
244+
except SoftLayer.SoftLayerError as ex:
243245
env.err(str(ex))
244246
exit_status = 1
245247
except Exception:

0 commit comments

Comments
 (0)