Skip to content

Commit 7dfe517

Browse files
committed
Add script to compute number of files per file type per package
1 parent 53c42d4 commit 7dfe517

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Prints the number of files in a package.
4+
#
5+
# <package_path> <percentage> <total> <file_type>
6+
#
7+
# Notes:
8+
#
9+
# * For files using alternative filename extensions, no attempt is made to infer the file type. Unrecognized filename extensions are categorized as "other".
10+
# * `README.md` files are included in Markdown totals.
11+
12+
# Determine root directory:
13+
root="$(git rev-parse --show-toplevel)"
14+
15+
# Define the path to a utility to list packages:
16+
find_pkgs="${root}/tools/scripts/find_packages"
17+
18+
# Define the path to a utility to list files:
19+
find_files="${root}/tools/scripts/find_files"
20+
21+
# Define the path to a utility to annotate a file statistic stream:
22+
annotate_file_type="${root}/tools/git/scripts/annotate_file_type.awk"
23+
24+
# Get a list of packages:
25+
pkgs="$(PACKAGES_FILTER=${PACKAGES_FILTER} ${find_pkgs})"
26+
27+
# For each package, determine the number of lines...
28+
for pkg in ${pkgs}; do
29+
# * `find_files`
30+
# - Find package files.
31+
# * `awk '{}'`
32+
# - Prefix each file to match annotation interface.
33+
# * `annotate_file_type`
34+
# - Prefix each result with a file type.
35+
# * `awk '{}'`
36+
# - Compute statistics.
37+
# * `sort -k2nr`
38+
# - Sort in reverse numeric order based on the computed percentage.
39+
FILES_PATTERN="${FILES_PATTERN}" FILES_FILTER="$pkg/.*" "${find_files}" | awk '{print 1 OFS $0}' | awk -f "${annotate_file_type}" | awk -v pkg="$pkg" '
40+
$3 ~ /README\.md$/ {
41+
lines["README"] += 1
42+
}
43+
{
44+
lines[$1] += 1
45+
total += 1
46+
}
47+
48+
END {
49+
print pkg OFS 1 OFS total OFS "total"
50+
for (k in lines) {
51+
n = lines[k]
52+
pct = int(n/total*10000)/10000
53+
print pkg OFS pct OFS n OFS k
54+
}
55+
}
56+
' | sort -k2nr
57+
done

0 commit comments

Comments
 (0)