|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Prints the number of bytes per file type in a package. |
| 4 | +# |
| 5 | +# <package_path> <percentage> <total_bytes> <number_of_files> <average> <file_type> |
| 6 | +# |
| 7 | +# Notes: |
| 8 | +# |
| 9 | +# * `README.md` files are included in Markdown statistics. |
| 10 | + |
| 11 | +# Determine root directory: |
| 12 | +root="$(git rev-parse --show-toplevel)" |
| 13 | + |
| 14 | +# Define the path to a utility to list packages: |
| 15 | +find_pkgs="${root}/tools/scripts/find_packages" |
| 16 | + |
| 17 | +# Define the path to a utility to list files: |
| 18 | +find_files="${root}/tools/scripts/find_files" |
| 19 | + |
| 20 | +# Define the path to a utility to annotate a file statistic stream: |
| 21 | +annotate_file_type="${root}/tools/git/scripts/annotate_file_type.awk" |
| 22 | + |
| 23 | +# Get a list of packages: |
| 24 | +pkgs="$(PACKAGES_FILTER=${PACKAGES_FILTER} ${find_pkgs})" |
| 25 | + |
| 26 | +# For each package, determine the number of bytes... |
| 27 | +for pkg in ${pkgs}; do |
| 28 | + # * `find_files` |
| 29 | + # - Find package files. |
| 30 | + # * `ls -l` |
| 31 | + # - Print file info, which includes number of bytes. |
| 32 | + # * `awk '{}'` |
| 33 | + # - Extract `bytes` and `filename` columns. |
| 34 | + # * `annotate_file_type` |
| 35 | + # - Prefix each result with a file type. |
| 36 | + # * `awk '{}'` |
| 37 | + # - Compute statistics. |
| 38 | + # * `sort -k2nr` |
| 39 | + # - Sort in reverse numeric order based on the computed percentage. |
| 40 | + FILES_PATTERN="${FILES_PATTERN}" FILES_FILTER="$pkg/.*" "${find_files}" | xargs ls -l | awk '{print $5 OFS $9}' | awk -f "${annotate_file_type}" | awk -v pkg="$pkg" ' |
| 41 | +$3 ~ /README\.md$/ { |
| 42 | + bytes["README"] += $2 |
| 43 | + N["README"] += 1 |
| 44 | +} |
| 45 | +
|
| 46 | +{ |
| 47 | + bytes[$1] += $2 |
| 48 | + N[$1] += 1 |
| 49 | +
|
| 50 | + bytes["total"] += $2 |
| 51 | + N["total"] += 1 |
| 52 | +} |
| 53 | +
|
| 54 | +END { |
| 55 | + total = bytes["total"] |
| 56 | + for (k in bytes) { |
| 57 | + len = bytes[k]; |
| 58 | + n = N[k] |
| 59 | + pct = int(len/total*10000)/10000 |
| 60 | + mu = int(len/n*10000)/10000 |
| 61 | + print pkg OFS pct OFS len OFS n OFS mu OFS k |
| 62 | + } |
| 63 | +} |
| 64 | +' | sort -k2nr |
| 65 | +done |
0 commit comments