|
Lines 30-35
a/WebKitTools/Scripts/webkitpy/style/checker.py_sec1
|
| 30 |
"""Front end of some style-checker modules.""" |
30 |
"""Front end of some style-checker modules.""" |
| 31 |
|
31 |
|
| 32 |
import codecs |
32 |
import codecs |
|
|
33 |
import logging |
| 33 |
import os.path |
34 |
import os.path |
| 34 |
import sys |
35 |
import sys |
| 35 |
|
36 |
|
|
Lines 44-49
from processors.common import categories as CommonCategories
a/WebKitTools/Scripts/webkitpy/style/checker.py_sec2
|
| 44 |
from processors.cpp import CppProcessor |
45 |
from processors.cpp import CppProcessor |
| 45 |
from processors.text import TextProcessor |
46 |
from processors.text import TextProcessor |
| 46 |
|
47 |
|
|
|
48 |
_log = logging.getLogger("webkitpy.style.checker") |
| 47 |
|
49 |
|
| 48 |
# These are default option values for the command-line option parser. |
50 |
# These are default option values for the command-line option parser. |
| 49 |
_DEFAULT_VERBOSITY = 1 |
51 |
_DEFAULT_VERBOSITY = 1 |
|
Lines 224-229
def check_webkit_style_configuration(options):
a/WebKitTools/Scripts/webkitpy/style/checker.py_sec3
|
| 224 |
verbosity=options.verbosity) |
226 |
verbosity=options.verbosity) |
| 225 |
|
227 |
|
| 226 |
|
228 |
|
|
|
229 |
# FIXME: Add support for more verbose logging for debug purposes. |
| 230 |
# This can use a formatter like the following, for example-- |
| 231 |
# |
| 232 |
# formatter = logging.Formatter("%(name)s: [%(levelname)s] %(message)s") |
| 233 |
def configure_logging(stream): |
| 234 |
"""Configure logging, and return the list of handlers added. |
| 235 |
|
| 236 |
Configures the root logger to log INFO messages and higher. |
| 237 |
Formats WARNING messages and above to display the logging level |
| 238 |
and messages strictly below WARNING not to display it. |
| 239 |
|
| 240 |
Returns: |
| 241 |
A list of references to the logging handlers added to the root |
| 242 |
logger. This allows the caller to later remove the handlers |
| 243 |
using logger.removeHandler. This is useful primarily during unit |
| 244 |
testing where the caller may want to configure logging temporarily |
| 245 |
and then undo the configuring. |
| 246 |
|
| 247 |
Args: |
| 248 |
stream: A file-like object to which to log. The stream must |
| 249 |
define an "encoding" data attribute, or else logging |
| 250 |
raises an error. |
| 251 |
|
| 252 |
""" |
| 253 |
# If the stream does not define an "encoding" data attribute, the |
| 254 |
# logging module can throw an error like the following: |
| 255 |
# |
| 256 |
# Traceback (most recent call last): |
| 257 |
# File "/System/Library/Frameworks/Python.framework/Versions/2.6/... |
| 258 |
# lib/python2.6/logging/__init__.py", line 761, in emit |
| 259 |
# self.stream.write(fs % msg.encode(self.stream.encoding)) |
| 260 |
# LookupError: unknown encoding: unknown |
| 261 |
|
| 262 |
# Handles logging.WARNING and above. |
| 263 |
error_handler = logging.StreamHandler(stream) |
| 264 |
error_handler.setLevel(logging.WARNING) |
| 265 |
formatter = logging.Formatter("%(levelname)s: %(message)s") |
| 266 |
error_handler.setFormatter(formatter) |
| 267 |
|
| 268 |
# Handles records strictly below logging.WARNING. |
| 269 |
non_error_handler = logging.StreamHandler(stream) |
| 270 |
non_error_filter = _LevelLoggingFilter(logging.WARNING) |
| 271 |
non_error_handler.addFilter(non_error_filter) |
| 272 |
formatter = logging.Formatter("%(message)s") |
| 273 |
non_error_handler.setFormatter(formatter) |
| 274 |
|
| 275 |
logger = logging.getLogger() |
| 276 |
logger.setLevel(logging.INFO) |
| 277 |
|
| 278 |
handlers = [error_handler, non_error_handler] |
| 279 |
|
| 280 |
for handler in handlers: |
| 281 |
logger.addHandler(handler) |
| 282 |
|
| 283 |
return handlers |
| 284 |
|
| 285 |
|
| 286 |
# FIXME: Consider moving this class into a module in webkitpy.init after |
| 287 |
# getting more experience with its use. We want to make sure |
| 288 |
# we have the right API before doing so. For example, we may |
| 289 |
# want to provide a constructor that has both upper and lower |
| 290 |
# bounds, and not just an upper bound. |
| 291 |
class _LevelLoggingFilter(object): |
| 292 |
|
| 293 |
"""A logging filter for blocking records at or above a certain level.""" |
| 294 |
|
| 295 |
def __init__(self, logging_level): |
| 296 |
"""Create a _LevelLoggingFilter. |
| 297 |
|
| 298 |
Args: |
| 299 |
logging_level: The logging level cut-off. Logging levels at |
| 300 |
or above this level will not be logged. |
| 301 |
|
| 302 |
""" |
| 303 |
self._logging_level = logging_level |
| 304 |
|
| 305 |
# The logging module requires that this method be defined. |
| 306 |
def filter(self, log_record): |
| 307 |
"""Return whether given the LogRecord should be logged.""" |
| 308 |
return log_record.levelno < self._logging_level |
| 309 |
|
| 310 |
|
| 227 |
# Enum-like idiom |
311 |
# Enum-like idiom |
| 228 |
class FileType: |
312 |
class FileType: |
| 229 |
|
313 |
|
|
Lines 322-327
class ProcessorDispatcher(object):
a/WebKitTools/Scripts/webkitpy/style/checker.py_sec4
|
| 322 |
return processor |
406 |
return processor |
| 323 |
|
407 |
|
| 324 |
|
408 |
|
|
|
409 |
# FIXME: Remove the stderr_write attribute from this class and replace |
| 410 |
# its use with calls to a logging module logger. |
| 325 |
class StyleCheckerConfiguration(object): |
411 |
class StyleCheckerConfiguration(object): |
| 326 |
|
412 |
|
| 327 |
"""Stores configuration values for the StyleChecker class. |
413 |
"""Stores configuration values for the StyleChecker class. |
|
Lines 439-447
class StyleChecker(object):
a/WebKitTools/Scripts/webkitpy/style/checker.py_sec5
|
| 439 |
self.error_count = 0 |
525 |
self.error_count = 0 |
| 440 |
self.file_count = 0 |
526 |
self.file_count = 0 |
| 441 |
|
527 |
|
| 442 |
def _stderr_write(self, message): |
|
|
| 443 |
self._configuration.stderr_write(message) |
| 444 |
|
| 445 |
def _increment_error_count(self): |
528 |
def _increment_error_count(self): |
| 446 |
"""Increment the total count of reported errors.""" |
529 |
"""Increment the total count of reported errors.""" |
| 447 |
self.error_count += 1 |
530 |
self.error_count += 1 |
|
Lines 469-479
class StyleChecker(object):
a/WebKitTools/Scripts/webkitpy/style/checker.py_sec6
|
| 469 |
contents = file.read() |
552 |
contents = file.read() |
| 470 |
|
553 |
|
| 471 |
except IOError: |
554 |
except IOError: |
| 472 |
self._stderr_write("Skipping input '%s': Can't open for reading\n" % file_path) |
555 |
message = 'Could not read file. Skipping: "%s"' % file_path |
|
|
556 |
_log.warn(message) |
| 473 |
return |
557 |
return |
| 474 |
|
558 |
|
| 475 |
lines = contents.split("\n") |
559 |
lines = contents.split("\n") |
| 476 |
|
560 |
|
|
|
561 |
# FIXME: Make a CarriageReturnProcessor for this logic, and put |
| 562 |
# it in processors.common. The process() method should |
| 563 |
# return the lines with the carriage returns stripped. |
| 477 |
for line_number in range(len(lines)): |
564 |
for line_number in range(len(lines)): |
| 478 |
# FIXME: We should probably use the SVN "eol-style" property |
565 |
# FIXME: We should probably use the SVN "eol-style" property |
| 479 |
# or a white list to decide whether or not to do |
566 |
# or a white list to decide whether or not to do |
|
Lines 520-527
class StyleChecker(object):
a/WebKitTools/Scripts/webkitpy/style/checker.py_sec7
|
| 520 |
if dispatcher.should_skip_without_warning(file_path): |
607 |
if dispatcher.should_skip_without_warning(file_path): |
| 521 |
return |
608 |
return |
| 522 |
if dispatcher.should_skip_with_warning(file_path): |
609 |
if dispatcher.should_skip_with_warning(file_path): |
| 523 |
self._stderr_write('Ignoring "%s": this file is exempt from the ' |
610 |
_log.warn('File exempt from style guide. Skipping: "%s"' |
| 524 |
"style guide.\n" % file_path) |
611 |
% file_path) |
| 525 |
return |
612 |
return |
| 526 |
|
613 |
|
| 527 |
verbosity = self._configuration.verbosity |
614 |
verbosity = self._configuration.verbosity |