-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathpackage2category.py
executable file
·59 lines (48 loc) · 1.46 KB
/
package2category.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
import sys
from argparse import ArgumentParser
from collections import defaultdict
from categories_map import CMSSW_CATEGORIES
def package2category(filename):
if not filename:
return
file_pack = "/".join(filename.split("/")[:2])
cat = "unknown"
if file_pack in pack2cat:
cat = "-".join(sorted(pack2cat[file_pack]))
if cat in ["alca", "db"]:
cat = "alca-db"
files[cat].add(filename)
cats[cat].add(file_pack)
parser = ArgumentParser()
parser.add_argument("-i", "--stdin", action="store_true", help="Also read file name(s) from stdin")
parser.add_argument("files", nargs="*", help="File name(s)")
args = parser.parse_args()
pack2cat = defaultdict(list)
for cat in CMSSW_CATEGORIES:
for pack in CMSSW_CATEGORIES[cat]:
pack2cat[pack].append(cat)
cats = defaultdict(set)
files = defaultdict(set)
for line in args.files:
package2category(line.strip())
if args.stdin:
for line in sys.stdin:
package2category(line.strip())
add_misc = False
if add_misc:
num = 1
misc = "misc%s" % num
misc_files = 0
for cat in files:
if len(files[cat]) <= 5:
misc_files += len(files[cat])
for pkg in cats[cat]:
cats[misc].add(pkg)
if misc_files > 10:
num += 1
misc = "misc%s" % num
misc_files = 0
del cats[cat]
for cat in cats:
print("%s %s" % (cat, " ".join(cats[cat])))