@@ 6312-6411 (lines=100) @@ | ||
6309 | sys.exit(0) |
|
6310 | ||
6311 | ||
6312 | def ParseArguments(args): |
|
6313 | """Parses the command line arguments. |
|
6314 | ||
6315 | This may set the output format and verbosity level as side-effects. |
|
6316 | ||
6317 | Args: |
|
6318 | args: The command line arguments: |
|
6319 | ||
6320 | Returns: |
|
6321 | The list of filenames to lint. |
|
6322 | """ |
|
6323 | try: |
|
6324 | (opts, filenames) = getopt.getopt(args, '', ['help', 'output=', 'verbose=', |
|
6325 | 'counting=', |
|
6326 | 'filter=', |
|
6327 | 'root=', |
|
6328 | 'repository=', |
|
6329 | 'linelength=', |
|
6330 | 'extensions=', |
|
6331 | 'exclude=', |
|
6332 | 'headers=', |
|
6333 | 'quiet', |
|
6334 | 'recursive']) |
|
6335 | except getopt.GetoptError: |
|
6336 | PrintUsage('Invalid arguments.') |
|
6337 | ||
6338 | verbosity = _VerboseLevel() |
|
6339 | output_format = _OutputFormat() |
|
6340 | filters = '' |
|
6341 | counting_style = '' |
|
6342 | recursive = False |
|
6343 | ||
6344 | for (opt, val) in opts: |
|
6345 | if opt == '--help': |
|
6346 | PrintUsage(None) |
|
6347 | elif opt == '--output': |
|
6348 | if val not in ('emacs', 'vs7', 'eclipse', 'junit'): |
|
6349 | PrintUsage('The only allowed output formats are emacs, vs7, eclipse ' |
|
6350 | 'and junit.') |
|
6351 | output_format = val |
|
6352 | elif opt == '--verbose': |
|
6353 | verbosity = int(val) |
|
6354 | elif opt == '--filter': |
|
6355 | filters = val |
|
6356 | if not filters: |
|
6357 | PrintCategories() |
|
6358 | elif opt == '--counting': |
|
6359 | if val not in ('total', 'toplevel', 'detailed'): |
|
6360 | PrintUsage('Valid counting options are total, toplevel, and detailed') |
|
6361 | counting_style = val |
|
6362 | elif opt == '--root': |
|
6363 | global _root |
|
6364 | _root = val |
|
6365 | elif opt == '--repository': |
|
6366 | global _repository |
|
6367 | _repository = val |
|
6368 | elif opt == '--linelength': |
|
6369 | global _line_length |
|
6370 | try: |
|
6371 | _line_length = int(val) |
|
6372 | except ValueError: |
|
6373 | PrintUsage('Line length must be digits.') |
|
6374 | elif opt == '--exclude': |
|
6375 | global _excludes |
|
6376 | if not _excludes: |
|
6377 | _excludes = set() |
|
6378 | _excludes.update(glob.glob(val)) |
|
6379 | elif opt == '--extensions': |
|
6380 | global _valid_extensions |
|
6381 | try: |
|
6382 | _valid_extensions = set(val.split(',')) |
|
6383 | except ValueError: |
|
6384 | PrintUsage('Extensions must be comma separated list.') |
|
6385 | elif opt == '--headers': |
|
6386 | global _header_extensions |
|
6387 | try: |
|
6388 | _header_extensions = set(val.split(',')) |
|
6389 | except ValueError: |
|
6390 | PrintUsage('Extensions must be comma separated list.') |
|
6391 | elif opt == '--recursive': |
|
6392 | recursive = True |
|
6393 | elif opt == '--quiet': |
|
6394 | global _quiet |
|
6395 | _quiet = True |
|
6396 | ||
6397 | if not filenames: |
|
6398 | PrintUsage('No files were specified.') |
|
6399 | ||
6400 | if recursive: |
|
6401 | filenames = _ExpandDirectories(filenames) |
|
6402 | ||
6403 | if _excludes: |
|
6404 | filenames = _FilterExcludedFiles(filenames) |
|
6405 | ||
6406 | _SetOutputFormat(output_format) |
|
6407 | _SetVerboseLevel(verbosity) |
|
6408 | _SetFilters(filters) |
|
6409 | _SetCountingStyle(counting_style) |
|
6410 | ||
6411 | return filenames |
|
6412 | ||
6413 | def _ExpandDirectories(filenames): |
|
6414 | """Searches a list of filenames and replaces directories in the list with |
@@ 6312-6411 (lines=100) @@ | ||
6309 | sys.exit(0) |
|
6310 | ||
6311 | ||
6312 | def ParseArguments(args): |
|
6313 | """Parses the command line arguments. |
|
6314 | ||
6315 | This may set the output format and verbosity level as side-effects. |
|
6316 | ||
6317 | Args: |
|
6318 | args: The command line arguments: |
|
6319 | ||
6320 | Returns: |
|
6321 | The list of filenames to lint. |
|
6322 | """ |
|
6323 | try: |
|
6324 | (opts, filenames) = getopt.getopt(args, '', ['help', 'output=', 'verbose=', |
|
6325 | 'counting=', |
|
6326 | 'filter=', |
|
6327 | 'root=', |
|
6328 | 'repository=', |
|
6329 | 'linelength=', |
|
6330 | 'extensions=', |
|
6331 | 'exclude=', |
|
6332 | 'headers=', |
|
6333 | 'quiet', |
|
6334 | 'recursive']) |
|
6335 | except getopt.GetoptError: |
|
6336 | PrintUsage('Invalid arguments.') |
|
6337 | ||
6338 | verbosity = _VerboseLevel() |
|
6339 | output_format = _OutputFormat() |
|
6340 | filters = '' |
|
6341 | counting_style = '' |
|
6342 | recursive = False |
|
6343 | ||
6344 | for (opt, val) in opts: |
|
6345 | if opt == '--help': |
|
6346 | PrintUsage(None) |
|
6347 | elif opt == '--output': |
|
6348 | if val not in ('emacs', 'vs7', 'eclipse', 'junit'): |
|
6349 | PrintUsage('The only allowed output formats are emacs, vs7, eclipse ' |
|
6350 | 'and junit.') |
|
6351 | output_format = val |
|
6352 | elif opt == '--verbose': |
|
6353 | verbosity = int(val) |
|
6354 | elif opt == '--filter': |
|
6355 | filters = val |
|
6356 | if not filters: |
|
6357 | PrintCategories() |
|
6358 | elif opt == '--counting': |
|
6359 | if val not in ('total', 'toplevel', 'detailed'): |
|
6360 | PrintUsage('Valid counting options are total, toplevel, and detailed') |
|
6361 | counting_style = val |
|
6362 | elif opt == '--root': |
|
6363 | global _root |
|
6364 | _root = val |
|
6365 | elif opt == '--repository': |
|
6366 | global _repository |
|
6367 | _repository = val |
|
6368 | elif opt == '--linelength': |
|
6369 | global _line_length |
|
6370 | try: |
|
6371 | _line_length = int(val) |
|
6372 | except ValueError: |
|
6373 | PrintUsage('Line length must be digits.') |
|
6374 | elif opt == '--exclude': |
|
6375 | global _excludes |
|
6376 | if not _excludes: |
|
6377 | _excludes = set() |
|
6378 | _excludes.update(glob.glob(val)) |
|
6379 | elif opt == '--extensions': |
|
6380 | global _valid_extensions |
|
6381 | try: |
|
6382 | _valid_extensions = set(val.split(',')) |
|
6383 | except ValueError: |
|
6384 | PrintUsage('Extensions must be comma separated list.') |
|
6385 | elif opt == '--headers': |
|
6386 | global _header_extensions |
|
6387 | try: |
|
6388 | _header_extensions = set(val.split(',')) |
|
6389 | except ValueError: |
|
6390 | PrintUsage('Extensions must be comma separated list.') |
|
6391 | elif opt == '--recursive': |
|
6392 | recursive = True |
|
6393 | elif opt == '--quiet': |
|
6394 | global _quiet |
|
6395 | _quiet = True |
|
6396 | ||
6397 | if not filenames: |
|
6398 | PrintUsage('No files were specified.') |
|
6399 | ||
6400 | if recursive: |
|
6401 | filenames = _ExpandDirectories(filenames) |
|
6402 | ||
6403 | if _excludes: |
|
6404 | filenames = _FilterExcludedFiles(filenames) |
|
6405 | ||
6406 | _SetOutputFormat(output_format) |
|
6407 | _SetVerboseLevel(verbosity) |
|
6408 | _SetFilters(filters) |
|
6409 | _SetCountingStyle(counting_style) |
|
6410 | ||
6411 | return filenames |
|
6412 | ||
6413 | def _ExpandDirectories(filenames): |
|
6414 | """Searches a list of filenames and replaces directories in the list with |