-
-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathstats.sh
executable file
·209 lines (190 loc) · 5.91 KB
/
stats.sh
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env bash
#
# TODO: stop expanding this bash script and move it to the publishing process
# so that the information is on an HTML page that is updated with each
# publish
#
#### SETUP ####################################################################
set -o errexit
set -o errtrace
set -o nounset
# shellcheck disable=SC2154
trap '_es=${?};
printf "${0}: line ${LINENO}: \"${BASH_COMMAND}\"";
printf " exited with a status of ${_es}\n";
exit ${_es}' ERR
DIR_REPO="$(cd -P -- "${0%/*}/.." && pwd -P)"
DIR_PUB_LICENSES="$(cd -P -- \
"${DIR_REPO}/../cc-legal-tools-data/docs/licenses" && pwd -P)"
DIR_PUB_PUBLICDOMAIN="$(cd -P -- \
"${DIR_REPO}/../cc-legal-tools-data/docs/publicdomain" && pwd -P)"
# https://en.wikipedia.org/wiki/ANSI_escape_code
E0="$(printf "\e[0m")" # reset
E1="$(printf "\e[1m")" # bold
E4="$(printf "\e[4m")" # underline
E30="$(printf "\e[30m")" # black foreground
E31="$(printf "\e[31m")" # red foreground
E33="$(printf "\e[33m")" # yellow foreground
E97="$(printf "\e[97m")" # bright white foreground
E100="$(printf "\e[100m")" # bright black (gray) background
E107="$(printf "\e[107m")" # bright white background
PORTED_NOTE="\
Prior to the international 4.0 version, the licenses were adapted to specific
legal jurisdictions (\"ported\"). This means there are more legal tools for
these earlier versions than there are licenses."
#### FUNCTIONS ################################################################
check_prerequisites() {
if ! command -v scc &>/dev/null
then
# shellcheck disable=SC2016
error_exit 'The `scc` command is unavailable.'
fi
}
error_exit() {
# Echo error message and exit with error
echo -e "${E31}ERROR:${E0} ${*}" 1>&2
exit 1
}
print_header() {
# Print 80 character wide black on white heading with time
printf "${E30}${E107}# %-69s$(date '+%T') ${E0}\n" "${@}"
}
print_key_val() {
local _sep
if (( ${#1} > 10 ))
then
_sep="\n "
else
_sep=' '
fi
printf "${E97}${E100}%21s${E0}${_sep}%s\n" "${1}:" "${2}"
}
print_var() {
print_key_val "${1}" "${!1}"
}
published_documents() {
local _count _subtotal _ver
print_header 'Published'
print_var DIR_PUB_LICENSES
print_var DIR_PUB_PUBLICDOMAIN
echo
echo "${E1}Licenses per license version${E0}"
printf " %-7s %-4s %s\n" 'Version' 'Count' 'Licenses'
for _ver in '1.0' '2.0' '2.1' '2.5' '3.0' '4.0'
do
_count=$(find "${DIR_PUB_LICENSES}"/*/"${_ver}" \
-maxdepth 0 -type d \
| wc -l \
| sed -e's/[[:space:]]*//g')
_list=$(find "${DIR_PUB_LICENSES}"/*/"${_ver}" \
-maxdepth 0 -type d \
| awk -F'/' '{print $9}' \
| sort \
| tr '\n' ' ')
printf " %-7s %'5d " "${_ver}" "${_count}"
_chars=0
for _license in ${_list}
do
_len=${#_license}
[[ -z "${_license}" ]] && continue
if (( _chars + _len < 61 ))
then
printf "%s " "${_license}"
else
_chars=0
echo
printf "%18s%s " ' ' "${_license}"
fi
_chars=$(( _chars + _len + 2 ))
done
echo
done
echo
echo "${E1}Legal tools per license version${E0}"
echo "${PORTED_NOTE}"
# per version
for _ver in '1.0' '2.0' '2.1' '2.5' '3.0' '4.0'
do
_count=$(find "${DIR_PUB_LICENSES}"/*/"${_ver}" \
-type f -name 'deed.en.html' \
| wc -l \
| sed -e's/[[:space:]]*//g')
if [[ "${_ver}" != '4.0' ]]
then
printf " %-5s%'4d\n" "${_ver}" "${_count}"
else
printf " ${E4}%-5s%'4d${E0}\n" "${_ver}" "${_count}"
fi
done
# total
_count=$(find "${DIR_PUB_LICENSES}" \
-type f -name 'deed.en.html' \
| wc -l \
| sed -e's/[[:space:]]*//g')
printf " %-5s%'4d\n" "Total" "${_count}"
echo
echo "${E1}Legal tools${E0}"
# licenses
_count=$(find "${DIR_PUB_LICENSES}" \
-type f -name 'deed.en.html' \
| wc -l \
| sed -e's/[[:space:]]*//g')
printf " %-13s%'4d\n" "Licenses" "${_count}"
# public domain
_count=$(find "${DIR_PUB_PUBLICDOMAIN}" \
-type f -name 'deed.en.html' \
| wc -l \
| sed -e's/[[:space:]]*//g')
printf " ${E4}%-13s%'4d${E0}\n" "Public domain" "${_count}"
# total
_count=$(find "${DIR_PUB_LICENSES}" "${DIR_PUB_PUBLICDOMAIN}" \
-type f -name 'deed.en.html' \
| wc -l \
| sed -e's/[[:space:]]*//g')
printf " %-13s%'4d\n" "Total" "${_count}"
echo
echo "${E1}Documents${E0}"
# licenses
_count=$(find "${DIR_PUB_LICENSES}" \
-type f \( -name '*.html' -o -name 'rdf' \) \
| wc -l \
| sed -e's/[[:space:]]*//g')
printf " %-13s% '7d\n" "Licenses" "${_count}"
# public domain
_count=$(find "${DIR_PUB_PUBLICDOMAIN}" \
-type f \( -name '*.html' -o -name 'rdf' \) \
| wc -l \
| sed -e's/[[:space:]]*//g')
printf " ${E4}%-13s% '7d${E0}\n" "Public domain" "${_count}"
# total
_count=$(find "${DIR_PUB_LICENSES}" "${DIR_PUB_PUBLICDOMAIN}" \
-type f \( -name '*.html' -o -name 'rdf' \) \
| wc -l \
| sed -e's/[[:space:]]*//g')
printf " %-13s% '7d\n" "Total" "${_count}"
echo
}
source_code() {
print_header 'Source code'
print_var DIR_REPO
cd "${DIR_REPO}"
scc \
--exclude-dir .git,wp-content \
--no-duplicates \
--dryness
echo
}
todo() {
print_header 'Deeds & UX translation'
echo "${E33}TODO${E0}"
echo
print_header 'Legal Code translation'
echo "${E33}TODO${E0}"
echo
}
#### MAIN #####################################################################
cd "${DIR_REPO}"
check_prerequisites
source_code
published_documents
todo