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

Unified Diff: tools/checkteamtags/extract_components.py

Issue 2648883002: Add coverage statistic (Closed)
Patch Set: update Docstring Created 3 years, 10 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
index a96fa03928e77e83224ed6b3a0dba299aaaa4efb..e944894eb7d00e8584c7ec91ff7e8481ee65b5fb 100755
--- a/tools/checkteamtags/extract_components.py
+++ b/tools/checkteamtags/extract_components.py
@@ -44,6 +44,86 @@ def write_results(filename, data):
f.write(data)
+def display_stat(stats, root, options):
+ """"Display coverage statistic.
+
+ The following three values are always displayed:
+ - The total number of OWNERS files under directory root and its sub-
+ directories.
+ - The number of OWNERS files (and its percentage of the total) that have
+ component information but no team information.
+ - The number of OWNERS files (and its percentage of the total) that have
+ both component and team information.
+
+ Optionally, if options.stat_coverage or options.complete_coverage are given,
+ the same information will be shown for each depth level.
+ (up to the level given by options.stat_coverage, if any).
+
+ Args:
+ stats (dict): Tha statistics in dictionary form as produced by the
+ owners_file_tags module.
+ root (str): The root directory from which the depth level is calculated.
+ options (optparse.Values): The command line options as returned by
+ optparse.
+ """
+ file_total = stats['OWNERS-count']
+ print ("%d OWNERS files in total." % file_total)
+ file_with_component = stats['OWNERS-with-component-only-count']
+ file_pct_with_component = "N/A"
+ if file_total > 0:
+ file_pct_with_component = "{0:.2f}".format(
+ 100.0 * file_with_component / file_total)
+ print '%(file_with_component)d (%(file_pct_with_component)s%%) OWNERS '\
+ 'files have COMPONENT' % {
+ 'file_with_component': file_with_component,
+ 'file_pct_with_component': file_pct_with_component}
+ file_with_team_component = stats['OWNERS-with-team-and-component-count']
+ file_pct_with_team_component = "N/A"
+ if file_total > 0:
+ file_pct_with_team_component = "{0:.2f}".format(
+ 100.0 * file_with_team_component / file_total)
+ print '%(file_with_team_component)d (%(file_pct_with_team_component)s%%) '\
+ 'OWNERS files have TEAM and COMPONENT' % {
+ 'file_with_team_component': file_with_team_component,
+ 'file_pct_with_team_component': file_pct_with_team_component}
+
+ print ("\nUnder directory %s " % root)
+ # number of depth to display, default is max depth under root
+ num_output_depth = len(stats['OWNERS-count-by-depth'])
+ if (options.stat_coverage > 0
+ and options.stat_coverage < num_output_depth):
+ num_output_depth = options.stat_coverage
+
+ for depth in range(0, num_output_depth):
+ file_total_by_depth = stats['OWNERS-count-by-depth'][depth]
+ file_with_component_by_depth =\
+ stats['OWNERS-with-component-only-count-by-depth'][depth]
+ file_pct_with_component_by_depth = "N/A"
+ if file_total_by_depth > 0:
+ file_pct_with_component_by_depth = "{0:.2f}".format(
+ 100.0 * file_with_component_by_depth / file_total_by_depth)
+ file_with_team_component_by_depth =\
+ stats['OWNERS-with-team-and-component-count-by-depth'][depth]
+ file_pct_with_team_component_by_depth = "N/A"
+ if file_total_by_depth > 0:
+ file_pct_with_team_component_by_depth = "{0:.2f}".format(
+ 100.0 * file_with_team_component_by_depth / file_total_by_depth)
+ print '%(file_total_by_depth)d OWNERS files at depth %(depth)d'% {
+ 'file_total_by_depth': file_total_by_depth, 'depth': depth}
+ print 'have COMPONENT: %(file_with_component_by_depth)d, '\
+ 'percentage: %(file_pct_with_component_by_depth)s%%' % {
+ 'file_with_component_by_depth':
+ file_with_component_by_depth,
+ 'file_pct_with_component_by_depth':
+ file_pct_with_component_by_depth}
+ print 'have COMPONENT and TEAM: %(file_with_team_component_by_depth)d,'\
+ 'percentage: %(file_pct_with_team_component_by_depth)s%%' % {
+ 'file_with_team_component_by_depth':
+ file_with_team_component_by_depth,
+ 'file_pct_with_team_component_by_depth':
+ file_pct_with_team_component_by_depth}
+
+
def main(argv):
usage = """Usage: python %prog [options] [<root_dir>]
root_dir specifies the topmost directory to traverse looking for OWNERS
@@ -56,6 +136,8 @@ Examples:
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
"""
parser = optparse.OptionParser(usage=usage)
parser.add_option('-w', '--write', action='store_true',
@@ -67,13 +149,17 @@ Examples:
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')
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)
+ mappings, warnings, errors, stats = aggregate_components_from_owners(root)
if options.verbose:
for w in warnings:
print w
@@ -81,6 +167,9 @@ Examples:
for e in errors:
print e
+ if options.stat_coverage or options.complete_coverage:
+ display_stat(stats, root, options)
+
mappings['AAA-README']= _README
mapping_file_contents = json.dumps(mappings, sort_keys=True, indent=2)
if options.write or options.output_file:
« 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