Add PEP8 check and fix related issues
- Add PEP8 section to tox.ini - Add hacking to requirements to enforce OpenStack style requirements - Fix formatting issues flagged by flake8 check - Add copyright notices to all remaining files - Update .gitignore file Change-Id: Iaeee85a78a6625c6ffb711988a77e13e1b5e5dab
This commit is contained in:
parent
0acfda92d8
commit
d64a16bf2f
4
.gitignore
vendored
4
.gitignore
vendored
@ -52,3 +52,7 @@ coverage.xml
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# IDE Project Files
|
||||
*.project
|
||||
*.pydev*
|
||||
*.idea
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
import jsonutil
|
||||
|
||||
from docopt import docopt
|
||||
import prettytable
|
||||
import requests
|
||||
|
||||
@ -31,15 +30,15 @@ def dump_response(keys, rows):
|
||||
for key in keys:
|
||||
if key in row:
|
||||
x.add_row([key, row[key]])
|
||||
print x
|
||||
print(x)
|
||||
|
||||
|
||||
def get(url, cmd, params, debug=False):
|
||||
final = "%s/%s" % (url, cmd)
|
||||
if debug:
|
||||
print 'URL: %s' % final
|
||||
print('URL: %s' % final)
|
||||
for item in params.items():
|
||||
print " : %s='%s'" % item
|
||||
print(" : %s='%s'" % item)
|
||||
ret = requests.get(final, params=params)
|
||||
ret.raise_for_status()
|
||||
return ret.json(object_hook=jsonutil.object_hook)
|
||||
|
@ -1,6 +1,21 @@
|
||||
import datetime
|
||||
import timex
|
||||
# Copyright (c) 2014 Dark Secret Software Inc.
|
||||
# Copyright (c) 2015 Rackspace
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import iso8601
|
||||
import timex
|
||||
|
||||
|
||||
def _present(dct, name):
|
||||
|
@ -14,9 +14,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
import argparse
|
||||
import prettytable
|
||||
import sys
|
||||
|
||||
import base
|
||||
|
||||
@ -26,26 +24,37 @@ class Streams(object):
|
||||
self.url = url
|
||||
if subparser:
|
||||
parser = subparser.add_parser('streams')
|
||||
parser.add_argument('--name', metavar='trigger_name',
|
||||
parser.add_argument(
|
||||
'--name', metavar='trigger_name',
|
||||
help='Return streams of type trigger_name.')
|
||||
parser.add_argument('--from', metavar='datetime', dest='_from',
|
||||
parser.add_argument(
|
||||
'--from', metavar='datetime', dest='_from',
|
||||
help='Return streams last updated after datetime')
|
||||
parser.add_argument('--to', metavar='datetime',
|
||||
parser.add_argument(
|
||||
'--to', metavar='datetime',
|
||||
help='Return streams last updated before datetime')
|
||||
parser.add_argument('--traits', metavar='trait_list',
|
||||
parser.add_argument(
|
||||
'--traits', metavar='trait_list',
|
||||
help='Return streams with specific distinguishing traits.')
|
||||
parser.add_argument('--details', action='store_true',
|
||||
default=False, help='Return full event details.')
|
||||
parser.add_argument('--state', choices=['active', 'firing',
|
||||
'expiring', 'error', 'expire_error', 'completed',
|
||||
'retry_fire', 'retry_expire'],
|
||||
parser.add_argument(
|
||||
'--details', action='store_true',
|
||||
default=False,
|
||||
help='Return full event details.')
|
||||
parser.add_argument(
|
||||
'--state', choices=['active', 'firing',
|
||||
'expiring', 'error',
|
||||
'expire_error', 'completed',
|
||||
'retry_fire',
|
||||
'retry_expire'],
|
||||
help='Only return streams in this state.')
|
||||
|
||||
group = parser.add_mutually_exclusive_group()
|
||||
group.add_argument('--count', action='store_true',
|
||||
group.add_argument(
|
||||
'--count', action='store_true',
|
||||
default=False,
|
||||
help='Return a count of streams matching filter criteria.')
|
||||
group.add_argument('--id', metavar='stream_id', dest='stream_id',
|
||||
group.add_argument(
|
||||
'--id', metavar='stream_id', dest='stream_id',
|
||||
help='Return a single specific stream by id.')
|
||||
|
||||
def get_streams_count(self, from_datetime=None, to_datetime=None,
|
||||
@ -99,7 +108,7 @@ class Streams(object):
|
||||
rows = self.get_streams_count(from_datetime=_from, to_datetime=_to,
|
||||
name=_name, traits=trait_dict,
|
||||
state=_state, debug=_debug)
|
||||
print rows
|
||||
print(rows)
|
||||
keys = ['count']
|
||||
base.dump_response(keys, rows)
|
||||
return
|
||||
@ -121,17 +130,17 @@ class Streams(object):
|
||||
for key, value in row['distinguishing_traits'].items():
|
||||
x.add_row(["D.Trait", key, value])
|
||||
|
||||
print x
|
||||
print(x)
|
||||
|
||||
if 'events' in row.keys():
|
||||
# This has detail rows ... handle those separately.
|
||||
print "Events:"
|
||||
print("Events:")
|
||||
for event in row['events']:
|
||||
x = prettytable.PrettyTable(["Property", "Value"])
|
||||
sorted_keys = sorted(event.keys())
|
||||
for key in sorted_keys:
|
||||
x.add_row([key, event[key]])
|
||||
print x
|
||||
print(x)
|
||||
|
||||
|
||||
class Events(object):
|
||||
@ -139,23 +148,28 @@ class Events(object):
|
||||
self.url = url
|
||||
if subparser:
|
||||
parser = subparser.add_parser('events')
|
||||
parser.add_argument('--name', metavar='event_name',
|
||||
parser.add_argument(
|
||||
'--name', metavar='event_name',
|
||||
help='Return events of type event_name.')
|
||||
parser.add_argument('--from', metavar='datetime', dest='_from',
|
||||
parser.add_argument(
|
||||
'--from', metavar='datetime', dest='_from',
|
||||
help='Return events generated before datetime')
|
||||
parser.add_argument('--to', metavar='datetime',
|
||||
parser.add_argument(
|
||||
'--to', metavar='datetime',
|
||||
help='Return events generated after datetime')
|
||||
parser.add_argument('--traits', metavar='trait_list',
|
||||
parser.add_argument(
|
||||
'--traits', metavar='trait_list',
|
||||
help='Return events with specific traits.')
|
||||
|
||||
group = parser.add_mutually_exclusive_group()
|
||||
group.add_argument('--count', action='store_true',
|
||||
group.add_argument(
|
||||
'--count', action='store_true',
|
||||
default=False,
|
||||
help='Return a count of events matching filter criteria.')
|
||||
group.add_argument('--msg_id', metavar='message_id',
|
||||
group.add_argument(
|
||||
'--msg_id', metavar='message_id',
|
||||
help='Return a single specific event by message id.')
|
||||
|
||||
|
||||
def get_events_count(self, from_datetime=None, to_datetime=None,
|
||||
traits=None, name=None, debug=False):
|
||||
if traits:
|
||||
@ -232,7 +246,7 @@ class V1(object):
|
||||
|
||||
# This shouldn't be needed, but I'm being paranoid.
|
||||
if cmd not in self.resources:
|
||||
print "Unknown command: '%s'" % cmd
|
||||
print("Unknown command: '%s'" % cmd)
|
||||
return
|
||||
|
||||
self.resources[cmd]._cmdline(arguments)
|
||||
|
@ -1,3 +1,4 @@
|
||||
hacking>=0.10.0,<0.11
|
||||
docopt
|
||||
prettytable
|
||||
requests
|
||||
|
11
tox.ini
11
tox.ini
@ -1,5 +1,5 @@
|
||||
[tox]
|
||||
envlist = py26,py27
|
||||
envlist = py26,py27,pep8
|
||||
|
||||
[testenv]
|
||||
deps =
|
||||
@ -8,3 +8,12 @@ deps =
|
||||
mock
|
||||
|
||||
commands = nosetests -d -v --with-coverage --cover-inclusive --cover-package klugman []
|
||||
|
||||
[testenv:pep8]
|
||||
commands =
|
||||
flake8
|
||||
|
||||
[flake8]
|
||||
ignore =
|
||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,*db/__init__.py,*db/migrations/versions/*_.py
|
||||
show-source = True
|
||||
|
Loading…
Reference in New Issue
Block a user