1 |
commit: f87c07fff29036a13bbae97f8b08943dac292ae2 |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Dec 5 09:02:40 2016 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Dec 5 09:02:40 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/qa-scripts.git/commit/?id=f87c07ff |
7 |
|
8 |
get-git-file: Generate gentoo-ci (+PR) HTML locally |
9 |
|
10 |
cgi-bin/get-git-file.sh | 33 ++++++++++++++++++++++++++------- |
11 |
1 file changed, 26 insertions(+), 7 deletions(-) |
12 |
|
13 |
diff --git a/cgi-bin/get-git-file.sh b/cgi-bin/get-git-file.sh |
14 |
index 8b48b08..56eecaa 100755 |
15 |
--- a/cgi-bin/get-git-file.sh |
16 |
+++ b/cgi-bin/get-git-file.sh |
17 |
@@ -18,31 +18,50 @@ main() { |
18 |
exit 1 |
19 |
fi |
20 |
|
21 |
- if ! cd "$(dirname "${0}")/../htdocs/output/${repo}" 2>/dev/null; then |
22 |
+ local topdir=$(dirname "${0}")/.. |
23 |
+ |
24 |
+ if ! cd "${topdir}/htdocs/output/${repo}" 2>/dev/null; then |
25 |
echo "Status: 404 Not Found" |
26 |
echo |
27 |
echo "404 Not Found" |
28 |
exit 0 |
29 |
fi |
30 |
|
31 |
- local tree=( $(git ls-tree "${commit}" "${file}" 2>/dev/null) ) |
32 |
+ # generate HTML from XML |
33 |
+ local lfile=${file} |
34 |
+ [[ ${file} == *.html ]] && lfile=${file%.html}.xml |
35 |
+ |
36 |
+ local tree=( $(git ls-tree "${commit}" "${lfile}" 2>/dev/null) ) |
37 |
if [[ ! ${tree[*]} ]]; then |
38 |
- echo "Status: 404 Not Found" |
39 |
- echo |
40 |
- echo "404 Not Found" |
41 |
- exit 0 |
42 |
+ # fallback for stuff without .xml |
43 |
+ lfile=${file} |
44 |
+ tree=( $(git ls-tree "${commit}" "${lfile}" 2>/dev/null) ) |
45 |
+ if [[ ! ${tree[*]} ]]; then |
46 |
+ echo "Status: 404 Not Found" |
47 |
+ echo |
48 |
+ echo "404 Not Found" |
49 |
+ exit 0 |
50 |
+ fi |
51 |
fi |
52 |
|
53 |
local ct |
54 |
case "${file}" in |
55 |
*.css) ct=text/css;; |
56 |
*.html) ct=text/html;; |
57 |
+ *.xml) ct=application/xml;; |
58 |
*) ct=text/plain;; |
59 |
esac |
60 |
|
61 |
echo "Content-Type: ${ct}" |
62 |
echo |
63 |
- git cat-file -p "${tree[2]}" |
64 |
+ if [[ ${file} == *.html && ${lfile} == *.xml ]]; then |
65 |
+ local ts=$(TZ=UTC git log --format='%cd' --date=iso-local -1 | cut -d' ' -f1-2) |
66 |
+ |
67 |
+ git cat-file -p "${tree[2]}" \ |
68 |
+ | PYTHONIOENCODING=utf8 python "${topdir}"/pkgcheck2html/pkgcheck2html.py -t "${ts}" - |
69 |
+ else |
70 |
+ git cat-file -p "${tree[2]}" |
71 |
+ fi |
72 |
} |
73 |
|
74 |
main |