MCPcopy Create free account
hub / github.com/BVLC/caffe / ProcessFile

Function ProcessFile

scripts/cpp_lint.py:4693–4758  ·  view source on GitHub ↗

Does google-lint on a single file. Args: filename: The name of the file to parse. vlevel: The level of errors to report. Every error of confidence >= verbose_level will be reported. 0 is a good default. extra_check_functions: An array of additional check functions that will be

(filename, vlevel, extra_check_functions=[])

Source from the content-addressed store, hash-verified

4691 CheckForNewlineAtEOF(filename, lines, error)
4692
4693def ProcessFile(filename, vlevel, extra_check_functions=[]):
4694 """Does google-lint on a single file.
4695
4696 Args:
4697 filename: The name of the file to parse.
4698
4699 vlevel: The level of errors to report. Every error of confidence
4700 >= verbose_level will be reported. 0 is a good default.
4701
4702 extra_check_functions: An array of additional check functions that will be
4703 run on each source line. Each function takes 4
4704 arguments: filename, clean_lines, line, error
4705 """
4706
4707 _SetVerboseLevel(vlevel)
4708
4709 try:
4710 # Support the UNIX convention of using "-" for stdin. Note that
4711 # we are not opening the file with universal newline support
4712 # (which codecs doesn't support anyway), so the resulting lines do
4713 # contain trailing '\r' characters if we are reading a file that
4714 # has CRLF endings.
4715 # If after the split a trailing '\r' is present, it is removed
4716 # below. If it is not expected to be present (i.e. os.linesep !=
4717 # '\r\n' as in Windows), a warning is issued below if this file
4718 # is processed.
4719
4720 if filename == '-':
4721 lines = codecs.StreamReaderWriter(sys.stdin,
4722 codecs.getreader('utf8'),
4723 codecs.getwriter('utf8'),
4724 'replace').read().split('\n')
4725 else:
4726 lines = codecs.open(filename, 'r', 'utf8', 'replace').read().split('\n')
4727
4728 carriage_return_found = False
4729 # Remove trailing '\r'.
4730 for linenum in range(len(lines)):
4731 if lines[linenum].endswith('\r'):
4732 lines[linenum] = lines[linenum].rstrip('\r')
4733 carriage_return_found = True
4734
4735 except IOError:
4736 sys.stderr.write(
4737 "Skipping input '%s': Can't open for reading\n" % filename)
4738 return
4739
4740 # Note, if no dot is found, this will give the entire filename as the ext.
4741 file_extension = filename[filename.rfind('.') + 1:]
4742
4743 # When reading from stdin, the extension is unknown, so no cpplint tests
4744 # should rely on the extension.
4745 if filename != '-' and file_extension not in _valid_extensions:
4746 sys.stderr.write('Ignoring %s; not a valid file name '
4747 '(%s)\n' % (filename, ', '.join(_valid_extensions)))
4748 else:
4749 ProcessFileData(filename, file_extension, lines, Error,
4750 extra_check_functions)

Callers 1

mainFunction · 0.85

Calls 5

_SetVerboseLevelFunction · 0.85
ProcessFileDataFunction · 0.85
ErrorFunction · 0.85
writeMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected