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.

Two hacking rules have been modified to ignore the tool directory as both
rules are checking oslo usage which is not critical in case of tools
- N310 use timeutils instead of datetime module
- N324 use jsonutils instead of json module

The tools/xenserver directory is still excluded from pep8 as it contains
scripts that are expected to run on dom0 with python2.4 therefore the
following rules cannot be meaningfully followed
- H231  Python 3.x incompatible 'except x,y:' construct
- H233  Python 3.x incompatible use of print operator

Change-Id: Icfd9e708a2ca1e421676b410e41807b2e630718f
This commit is contained in:
Balazs Gibizer 2014-11-21 09:42:44 +01:00
parent 94aedacfd2
commit 687e8664a2
5 changed files with 31 additions and 26 deletions

View File

@ -137,7 +137,11 @@ def no_db_session_in_public_api(logical_line, filename):
yield (0, "N309: public db api methods may not accept session")
def use_timeutils_utcnow(logical_line):
def use_timeutils_utcnow(logical_line, filename):
# tools are OK to use the standard datetime module
if "/tools/" in filename:
return
msg = "N310: timeutils.utcnow() must be used instead of datetime.%s()"
datetime_funcs = ['now', 'utcnow']
@ -361,6 +365,10 @@ def use_jsonutils(logical_line, filename):
if "plugins/xenserver" in filename:
return
# tools are OK to use the standard json module
if "/tools/" in filename:
return
msg = "N324: jsonutils.%(fun)s must be used instead of json.%(fun)s"
if "json." in logical_line:

View File

@ -41,16 +41,15 @@
"""Display a subunit stream through a colorized unittest test runner."""
import heapq
import subunit
import sys
import unittest
import subunit
import testtools
class _AnsiColorizer(object):
"""
A colorizer is an object that loosely wraps around a stream, allowing
"""A colorizer is an object that loosely wraps around a stream, allowing
callers to write text to the stream in a particular color.
Colorizer classes must implement C{supported()} and C{write(text, color)}.
@ -62,8 +61,7 @@ class _AnsiColorizer(object):
self.stream = stream
def supported(cls, stream=sys.stdout):
"""
A class method that returns True if the current platform supports
"""A class method that returns True if the current platform supports
coloring terminal output using this method. Returns False otherwise.
"""
if not stream.isatty():
@ -85,8 +83,7 @@ class _AnsiColorizer(object):
supported = classmethod(supported)
def write(self, text, color):
"""
Write the given text to the stream in the given color.
"""Write the given text to the stream in the given color.
@param text: Text to be written to the stream.
@ -97,9 +94,7 @@ class _AnsiColorizer(object):
class _Win32Colorizer(object):
"""
See _AnsiColorizer docstring.
"""
"""See _AnsiColorizer docstring."""
def __init__(self, stream):
import win32console
red, green, blue, bold = (win32console.FOREGROUND_RED,
@ -147,9 +142,7 @@ class _Win32Colorizer(object):
class _NullColorizer(object):
"""
See _AnsiColorizer docstring.
"""
"""See _AnsiColorizer docstring."""
def __init__(self, stream):
self.stream = stream

View File

@ -52,7 +52,7 @@ import sys
from nova.i18n import _
### Dump
# Dump
def dump_db(db_driver, db_name, db_url, migration_version, dump_filename):
@ -69,11 +69,12 @@ def dump_db(db_driver, db_name, db_url, migration_version, dump_filename):
db_driver.drop(db_name)
### Diff
# Diff
def diff_files(filename1, filename2):
pipeline = ['diff -U 3 %(filename1)s %(filename2)s' % locals()]
pipeline = ['diff -U 3 %(filename1)s %(filename2)s'
% {'filename1': filename1, 'filename2': filename2}]
# Use colordiff if available
if subprocess.call(['which', 'colordiff']) == 0:
@ -85,7 +86,7 @@ def diff_files(filename1, filename2):
subprocess.check_call(cmd, shell=True)
### Database
# Database
class Mysql(object):
@ -97,7 +98,8 @@ class Mysql(object):
def dump(self, name, dump_filename):
subprocess.check_call(
'mysqldump -u root %(name)s > %(dump_filename)s' % locals(),
'mysqldump -u root %(name)s > %(dump_filename)s'
% {'name': name, 'dump_filename': dump_filename},
shell=True)
@ -110,7 +112,8 @@ class Postgresql(object):
def dump(self, name, dump_filename):
subprocess.check_call(
'pg_dump %(name)s > %(dump_filename)s' % locals(),
'pg_dump %(name)s > %(dump_filename)s'
% {'name': name, 'dump_filename': dump_filename},
shell=True)
@ -121,7 +124,7 @@ def _get_db_driver_class(db_url):
raise Exception(_("database %s not supported") % db_url)
### Migrate
# Migrate
MIGRATE_REPO = os.path.join(os.getcwd(), "nova/db/sqlalchemy/migrate_repo")
@ -170,7 +173,7 @@ def _migrate_get_earliest_version():
return versions[0]
### Git
# Git
def git_current_branch_name():
@ -196,7 +199,7 @@ def git_has_uncommited_changes():
return subprocess.call(['git', 'diff', '--quiet', '--exit-code']) == 1
### Command
# Command
def die(msg):

View File

@ -24,7 +24,6 @@ import re
import sys
from pylint import lint
from pylint.reporters import text
# Note(maoy): E1103 is error code related to partial type inference
ignore_codes = ["E1103"]
@ -130,7 +129,9 @@ class ErrorKeys(object):
def run_pylint():
buff = StringIO.StringIO()
args = ["--msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg}", "-E", "nova"]
args = ["--msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg}",
"-E",
"nova"]
lint.Run(args, exit=False)
val = buff.getvalue()
buff.close()

View File

@ -71,7 +71,7 @@ commands = python setup.py build_sphinx
# E251 Skipped due to https://github.com/jcrocholl/pep8/issues/301
ignore = E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E251,H405,H803,H904
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools/xenserver*
# To get a list of functions that are more complex than 25, set max-complexity
# to 25 and run 'tox -epep8'.
# 46 is currently the most complex thing we have