예제 #1
0
def main(argv):
    usage = """Usage: python %prog [options] [<root_dir>]
  root_dir  specifies the topmost directory to traverse looking for OWNERS
            files, defaults to two levels up from this file's directory.
            i.e. where src/ is expected to be.

Examples:
  python %prog
  python %prog /b/build/src
  python %prog -v /b/build/src
  python %prog -w /b/build/src
  python %prog -o ~/components.json /b/build/src
  """
    parser = optparse.OptionParser(usage=usage)
    parser.add_option('-w',
                      '--write',
                      action='store_true',
                      help='If no errors occur, write the mappings to disk.')
    parser.add_option('-v',
                      '--verbose',
                      action='store_true',
                      help='Print warnings.')
    parser.add_option('-f',
                      '--force_print',
                      action='store_true',
                      help='Print the mappings despite errors.')
    parser.add_option('-o',
                      '--output_file',
                      help='Specify file to write the '
                      'mappings to instead of the default: <CWD>/'
                      'component_map.json (implies -w)')
    options, args = parser.parse_args(argv[1:])
    if args:
        root = args[0]
    else:
        root = _DEFAULT_SRC_LOCATION

    mappings, warnings, errors = aggregate_components_from_owners(root)
    if options.verbose:
        for w in warnings:
            print w

    for e in errors:
        print e

    mappings['AAA-README'] = _README
    mapping_file_contents = json.dumps(mappings, sort_keys=True, indent=2)
    if options.write or options.output_file:
        if errors:
            print 'Not writing to file due to errors'
            if options.force_print:
                print mapping_file_contents
        else:
            write_results(options.output_file, mapping_file_contents)
    else:
        print mapping_file_contents

    return len(errors)
예제 #2
0
def main(argv):
    usage = """Usage: python %prog [options] [<root_dir>]
  root_dir  specifies the topmost directory to traverse looking for OWNERS
            files, defaults to two levels up from this file's directory.
            i.e. where src/ is expected to be.

Examples:
  python %prog
  python %prog /b/build/src
  python %prog -v /b/build/src
  python %prog -w /b/build/src
  python %prog -o ~/components.json /b/build/src
  python %prog -c /b/build/src
  python %prog -s 3 /b/build/src
  python %prog -m 2 /b/build/src
  """
    parser = optparse.OptionParser(usage=usage)
    parser.add_option('-w',
                      '--write',
                      action='store_true',
                      help='If no errors occur, write the mappings to disk.')
    parser.add_option('-v',
                      '--verbose',
                      action='store_true',
                      help='Print warnings.')
    parser.add_option('-f',
                      '--force_print',
                      action='store_true',
                      help='Print the mappings despite errors.')
    parser.add_option('-o',
                      '--output_file',
                      help='Specify file to write the '
                      'mappings to instead of the default: <CWD>/'
                      'component_map.json (implies -w)')
    parser.add_option('-c',
                      '--complete_coverage',
                      action='store_true',
                      help='Print complete coverage statistic')
    parser.add_option('-s',
                      '--stat_coverage',
                      type="int",
                      help='Specify directory depth to display coverage stats')
    parser.add_option(
        '--include-subdirs',
        action='store_true',
        default=False,
        help='List subdirectories without OWNERS file or component '
        'tag as having same component as parent')
    parser.add_option('-m',
                      '--list_missing_info_by_depth',
                      type="int",
                      help='List OWNERS files that have missing team and '
                      'component information by depth')
    options, args = parser.parse_args(argv[1:])
    if args:
        root = args[0]
    else:
        root = _DEFAULT_SRC_LOCATION

    mappings, warnings, errors, stats = aggregate_components_from_owners(
        root, include_subdirs=options.include_subdirs)
    if options.verbose:
        for w in warnings:
            print w

    for e in errors:
        print e

    if options.stat_coverage or options.complete_coverage:
        display_stat(stats, root, options)

    if options.list_missing_info_by_depth:
        display_missing_info_OWNERS_files(stats,
                                          options.list_missing_info_by_depth)

    mappings['AAA-README'] = _README
    mapping_file_contents = json.dumps(mappings, sort_keys=True, indent=2)
    if options.write or options.output_file:
        if errors:
            print 'Not writing to file due to errors'
            if options.force_print:
                print mapping_file_contents
        else:
            write_results(options.output_file, mapping_file_contents)
    else:
        print mapping_file_contents

    return len(errors)