Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1687)

Unified Diff: tools/checkteamtags/extract_components.py

Issue 2611803003: Script to extract components from OWNERS files throughout the repo. (Closed)
Patch Set: No longer need these permissions Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/checkteamtags/extract_components_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/checkteamtags/extract_components.py
diff --git a/tools/checkteamtags/extract_components.py b/tools/checkteamtags/extract_components.py
new file mode 100755
index 0000000000000000000000000000000000000000..a96fa03928e77e83224ed6b3a0dba299aaaa4efb
--- /dev/null
+++ b/tools/checkteamtags/extract_components.py
@@ -0,0 +1,100 @@
+#!/usr/bin/env python
+# Copyright (c) 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Parses OWNERS recursively and generates a machine readable component mapping.
+
+OWNERS files are expected to contain a well-formatted pair of tags as shown
+below. A presubmit check exists that validates this.
+
+This script finds lines in the OWNERS files such as:
+ `# TEAM: team@chromium.org` and
+ `# COMPONENT: Tools>Test>Findit`
+and dumps this information into a json file.
+
+Refer to crbug.com/667952
+"""
+
+import json
+import optparse
+import os
+import sys
+
+from owners_file_tags import aggregate_components_from_owners
+
+
+_DEFAULT_SRC_LOCATION = os.path.join(
+ os.path.dirname(__file__), os.pardir, os.pardir)
+
+_README = """
+This file is generated by src/tools/checkteamtags/extract_components.py
+by parsing the contents of OWNERS files throughout the chromium source code and
+extracting `# TEAM:` and `# COMPONENT:` tags.
+
+Manual edits of this file will be overwritten by an automated process.
+""".splitlines()
+
+
+def write_results(filename, data):
+ """Write data to the named file, or the default location."""
+ if not filename:
+ filename = 'component_map.json'
+ with open(filename, 'w') as f:
+ f.write(data)
+
+
+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)
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
« no previous file with comments | « no previous file | tools/checkteamtags/extract_components_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698