Enable pep8 on ./tools directory
This patch fixes the pep8 issues of the tool scripts and configures tox to run pep8 on the tools directory. Change-Id: Ifed21e19dd2b382790a1e2a90d5153a8845c4b64
This commit is contained in:
parent
30824df1a4
commit
062ac3313d
@ -17,13 +17,14 @@
|
|||||||
|
|
||||||
"""pylint error checking."""
|
"""pylint error checking."""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pylint import lint
|
from pylint import lint
|
||||||
from pylint.reporters import text
|
from six.moves import cStringIO as StringIO # noqa
|
||||||
from six.moves import cStringIO as StringIO
|
|
||||||
|
|
||||||
# These variables will be useful if we will need to skip some pylint checks
|
# These variables will be useful if we will need to skip some pylint checks
|
||||||
ignore_codes = []
|
ignore_codes = []
|
||||||
@ -65,8 +66,9 @@ class LintOutput(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_msg_to_dict(cls, msg):
|
def from_msg_to_dict(cls, msg):
|
||||||
"""From the output of pylint msg, to a dict, where each key
|
"""From the output of pylint msg, to a dict.
|
||||||
is a unique error identifier, value is a list of LintOutput
|
|
||||||
|
Each key is a unique error identifier, value is a list of LintOutput
|
||||||
"""
|
"""
|
||||||
result = {}
|
result = {}
|
||||||
for line in msg.splitlines():
|
for line in msg.splitlines():
|
||||||
@ -108,9 +110,9 @@ class ErrorKeys(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def print_json(cls, errors, output=sys.stdout):
|
def print_json(cls, errors, output=sys.stdout):
|
||||||
print >>output, "# automatically generated by tools/lintstack.py"
|
print("# automatically generated by tools/lintstack.py", file=output)
|
||||||
for i in sorted(errors.keys()):
|
for i in sorted(errors.keys()):
|
||||||
print >>output, json.dumps(i)
|
print(json.dumps(i), file=output)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_file(cls, filename):
|
def from_file(cls, filename):
|
||||||
@ -134,7 +136,7 @@ def run_pylint():
|
|||||||
|
|
||||||
|
|
||||||
def generate_error_keys(msg=None):
|
def generate_error_keys(msg=None):
|
||||||
print "Generating", KNOWN_PYLINT_EXCEPTIONS_FILE
|
print("Generating", KNOWN_PYLINT_EXCEPTIONS_FILE)
|
||||||
if msg is None:
|
if msg is None:
|
||||||
msg = run_pylint()
|
msg = run_pylint()
|
||||||
errors = LintOutput.from_msg_to_dict(msg)
|
errors = LintOutput.from_msg_to_dict(msg)
|
||||||
@ -143,10 +145,10 @@ def generate_error_keys(msg=None):
|
|||||||
|
|
||||||
|
|
||||||
def validate(newmsg=None):
|
def validate(newmsg=None):
|
||||||
print "Loading", KNOWN_PYLINT_EXCEPTIONS_FILE
|
print("Loading", KNOWN_PYLINT_EXCEPTIONS_FILE)
|
||||||
known = ErrorKeys.from_file(KNOWN_PYLINT_EXCEPTIONS_FILE)
|
known = ErrorKeys.from_file(KNOWN_PYLINT_EXCEPTIONS_FILE)
|
||||||
if newmsg is None:
|
if newmsg is None:
|
||||||
print "Running pylint. Be patient..."
|
print("Running pylint. Be patient...")
|
||||||
newmsg = run_pylint()
|
newmsg = run_pylint()
|
||||||
errors = LintOutput.from_msg_to_dict(newmsg)
|
errors = LintOutput.from_msg_to_dict(newmsg)
|
||||||
|
|
||||||
@ -156,17 +158,17 @@ def validate(newmsg=None):
|
|||||||
for err_key, err_list in errors.items():
|
for err_key, err_list in errors.items():
|
||||||
for err in err_list:
|
for err in err_list:
|
||||||
if err_key not in known:
|
if err_key not in known:
|
||||||
print err.lintoutput
|
print(err.lintoutput)
|
||||||
print
|
print()
|
||||||
passed = False
|
passed = False
|
||||||
if passed:
|
if passed:
|
||||||
print "Congrats! pylint check passed."
|
print("Congrats! pylint check passed.")
|
||||||
redundant = known - set(errors.keys())
|
redundant = known - set(errors.keys())
|
||||||
if redundant:
|
if redundant:
|
||||||
print "Extra credit: some known pylint exceptions disappeared."
|
print("Extra credit: some known pylint exceptions disappeared.")
|
||||||
for i in sorted(redundant):
|
for i in sorted(redundant):
|
||||||
print json.dumps(i)
|
print(json.dumps(i))
|
||||||
print "Consider regenerating the exception file if you will."
|
print("Consider regenerating the exception file if you will.")
|
||||||
else:
|
else:
|
||||||
print("Please fix the errors above. If you believe they are false"
|
print("Please fix the errors above. If you believe they are false"
|
||||||
" positives, run 'tools/lintstack.py generate' to overwrite.")
|
" positives, run 'tools/lintstack.py generate' to overwrite.")
|
||||||
@ -174,10 +176,10 @@ def validate(newmsg=None):
|
|||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print """Usage: tools/lintstack.py [generate|validate]
|
print("""Usage: tools/lintstack.py [generate|validate]
|
||||||
To generate pylint_exceptions file: tools/lintstack.py generate
|
To generate pylint_exceptions file: tools/lintstack.py generate
|
||||||
To validate the current commit: tools/lintstack.py
|
To validate the current commit: tools/lintstack.py
|
||||||
"""
|
""")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -56,7 +56,6 @@ def make_test_data(conn, name, meter_type, unit, volume, random_min,
|
|||||||
|
|
||||||
increment = datetime.timedelta(minutes=interval)
|
increment = datetime.timedelta(minutes=interval)
|
||||||
|
|
||||||
|
|
||||||
print('Adding new events for meter %s.' % (name))
|
print('Adding new events for meter %s.' % (name))
|
||||||
# Generate events
|
# Generate events
|
||||||
n = 0
|
n = 0
|
||||||
@ -70,7 +69,6 @@ def make_test_data(conn, name, meter_type, unit, volume, random_min,
|
|||||||
else:
|
else:
|
||||||
total_volume += random.uniform(random_min, random_max)
|
total_volume += random.uniform(random_min, random_max)
|
||||||
|
|
||||||
|
|
||||||
c = sample.Sample(name=name,
|
c = sample.Sample(name=name,
|
||||||
type=meter_type,
|
type=meter_type,
|
||||||
unit=unit,
|
unit=unit,
|
||||||
|
@ -121,8 +121,7 @@ def main():
|
|||||||
start=start,
|
start=start,
|
||||||
end=end,
|
end=end,
|
||||||
interval=args.interval,
|
interval=args.interval,
|
||||||
event_types=args.event_types
|
event_types=args.event_types)
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -53,9 +53,8 @@ def show_resources(db, args):
|
|||||||
value = totals[0]['max']
|
value = totals[0]['max']
|
||||||
else:
|
else:
|
||||||
value = totals[0]['sum']
|
value = totals[0]['sum']
|
||||||
print(' %s (%s): %s' % \
|
print(' %s (%s): %s' %
|
||||||
(meter['counter_name'], meter['counter_type'],
|
(meter['counter_name'], meter['counter_type'], value))
|
||||||
value))
|
|
||||||
|
|
||||||
|
|
||||||
def show_total_resources(db, args):
|
def show_total_resources(db, args):
|
||||||
|
@ -17,6 +17,7 @@ from oslo.config import cfg
|
|||||||
|
|
||||||
from ceilometer import storage
|
from ceilometer import storage
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
cfg.CONF([], project='ceilometer')
|
cfg.CONF([], project='ceilometer')
|
||||||
if os.getenv("CEILOMETER_TEST_HBASE_URL"):
|
if os.getenv("CEILOMETER_TEST_HBASE_URL"):
|
||||||
|
2
tox.ini
2
tox.ini
@ -70,7 +70,7 @@ commands =
|
|||||||
[flake8]
|
[flake8]
|
||||||
ignore =
|
ignore =
|
||||||
builtins = _
|
builtins = _
|
||||||
exclude=.venv,.git,.tox,dist,doc,./ceilometer/openstack/common,*lib/python*,*egg,tools,nova_tests,build
|
exclude=.venv,.git,.tox,dist,doc,./ceilometer/openstack/common,*lib/python*,*egg,nova_tests,build
|
||||||
show-source = True
|
show-source = True
|
||||||
|
|
||||||
[hacking]
|
[hacking]
|
||||||
|
Loading…
Reference in New Issue
Block a user