Merge "Enable pep8 on ./tools directory"

This commit is contained in:
Jenkins 2014-12-01 16:50:04 +00:00 committed by Gerrit Code Review
commit e8b085293c
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") 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()" msg = "N310: timeutils.utcnow() must be used instead of datetime.%s()"
datetime_funcs = ['now', 'utcnow'] datetime_funcs = ['now', 'utcnow']
@ -361,6 +365,10 @@ def use_jsonutils(logical_line, filename):
if "plugins/xenserver" in filename: if "plugins/xenserver" in filename:
return 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" msg = "N324: jsonutils.%(fun)s must be used instead of json.%(fun)s"
if "json." in logical_line: if "json." in logical_line:

View File

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

View File

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

View File

@ -24,7 +24,6 @@ import re
import sys import sys
from pylint import lint from pylint import lint
from pylint.reporters import text
# Note(maoy): E1103 is error code related to partial type inference # Note(maoy): E1103 is error code related to partial type inference
ignore_codes = ["E1103"] ignore_codes = ["E1103"]
@ -130,7 +129,9 @@ class ErrorKeys(object):
def run_pylint(): def run_pylint():
buff = StringIO.StringIO() 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) lint.Run(args, exit=False)
val = buff.getvalue() val = buff.getvalue()
buff.close() buff.close()

View File

@ -72,7 +72,7 @@ commands = python setup.py build_sphinx
# E251 Skipped due to https://github.com/jcrocholl/pep8/issues/301 # 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 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 get a list of functions that are more complex than 25, set max-complexity
# to 25 and run 'tox -epep8'. # to 25 and run 'tox -epep8'.
# 46 is currently the most complex thing we have # 46 is currently the most complex thing we have