Skip to content

Commit 8b55eb8

Browse files
cfriedtnashif
authored andcommitted
scripts: get_maintainer: add count function
For looking at statistics over time, it is helpful to be able to quickly query the number of unique maintainers, collaborators, areas, and the number of orphaned areas (without a maintainer). This change adds the `count` subcommand to `scripts/get_maintainer.py`. ``` % python3 ./scripts/get_maintainer.py count -h usage: get_maintainer.py count [-h] [-a] [-c] [-n] [-o] optional arguments: -h, --help show this help message and exit -a, --count-areas Count the number of areas -c, --count-collaborators Count the number of unique collaborators -n, --count-maintainers Count the number of unique maintainers -o, --count-orphaned Count the number of orphaned areas % python3 ./scripts/get_maintainer.py count areas: 113 maintainers: 49 collaborators: 81 orphaned: 21 % python3 ./scripts/get_maintainer.py count -o orphaned: 21 ``` Signed-off-by: Christopher Friedt <[email protected]>
1 parent e9d4b8f commit 8b55eb8

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

scripts/get_maintainer.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,31 @@ def _parse_args():
120120
help="Limit to files under PATH")
121121
orphaned_parser.set_defaults(cmd_fn=Maintainers._orphaned_cmd)
122122

123+
count_parser = subparsers.add_parser(
124+
"count",
125+
help="Count areas, unique maintainers, and / or unique collaborators")
126+
count_parser.add_argument(
127+
"-a",
128+
"--count-areas",
129+
action="store_true",
130+
help="Count the number of areas")
131+
count_parser.add_argument(
132+
"-c",
133+
"--count-collaborators",
134+
action="store_true",
135+
help="Count the number of unique collaborators")
136+
count_parser.add_argument(
137+
"-n",
138+
"--count-maintainers",
139+
action="store_true",
140+
help="Count the number of unique maintainers")
141+
count_parser.add_argument(
142+
"-o",
143+
"--count-orphaned",
144+
action="store_true",
145+
help="Count the number of orphaned areas")
146+
count_parser.set_defaults(cmd_fn=Maintainers._count_cmd)
147+
123148
args = parser.parse_args()
124149
if not hasattr(args, "cmd_fn"):
125150
# Called without a subcommand
@@ -261,6 +286,36 @@ def _areas_cmd(self, args):
261286
else:
262287
print("{:25}\t{}".format(area.name, ",".join(area.maintainers)))
263288

289+
def _count_cmd(self, args):
290+
# 'count' subcommand implementation
291+
292+
if not (args.count_areas or args.count_collaborators or args.count_maintainers or args.count_orphaned):
293+
# if no specific count is provided, print them all
294+
args.count_areas = True
295+
args.count_collaborators = True
296+
args.count_maintainers = True
297+
args.count_orphaned = True
298+
299+
orphaned = 0
300+
collaborators = set()
301+
maintainers = set()
302+
303+
for area in self.areas.values():
304+
if area.status == 'maintained':
305+
maintainers = maintainers.union(set(area.maintainers))
306+
elif area.status == 'orphaned':
307+
orphaned += 1
308+
collaborators = collaborators.union(set(area.collaborators))
309+
310+
if args.count_areas:
311+
print('{:14}\t{}'.format('areas:', len(self.areas)))
312+
if args.count_maintainers:
313+
print('{:14}\t{}'.format('maintainers:', len(maintainers)))
314+
if args.count_collaborators:
315+
print('{:14}\t{}'.format('collaborators:', len(collaborators)))
316+
if args.count_orphaned:
317+
print('{:14}\t{}'.format('orphaned:', orphaned))
318+
264319
def _list_cmd(self, args):
265320
# 'list' subcommand implementation
266321

0 commit comments

Comments
 (0)