summaryrefslogtreecommitdiff
path: root/gsv-eval-local.sh
blob: 30b01db4887ec2cc881cb3527a48c41da9981dff (plain)
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
#!/bin/sh

# Copyright (C) 2014 Assaf Gordon (assafgordon@gmail.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

##
## Runs the gnu-savannah-eval perl script
## on a given directory, then generates an HTML report for it.
##

die()
{
    BASE=$(basename "$0")
    echo "$BASE: error: $@" >&2
    exit 1
}

usage()
{
    BASE=$(basename "$0")
    echo "GNU-Savannah Evaluation - helper script
Copyright (C) 2014 A. Gordon (assafgordon@gmail.com)
License: GPLv3-or-later

Usage: $BASE [OPTIONS] PROJECT-NAME DIRECTORY

Will scan DIRECTORY with the gnu-sv-evaluation script,
and produce a Markdown and an HTML file, named based on PROJECT.

Options:

   -h              = show this help screen.
   --no-file-limit = Pass --no-file-limit to the perl evaluation script.
                     By default, evaluation stops after 4,000 files
                     (with a warning added to the output report).
Example:

    \$ $BASE my-project-0.1 \$HOME/projects/mycode

Will generate 'my-project-0.1.md' and 'my-project-0.1.html' .
"
    exit 0
}

NOLIMIT=
if [ "x$1" = "x--no-file-limit" ] ; then
  NOLIMIT=$1
  shift 1
fi
test "x$1" = "x-h" && usage

PROJECT=$1
DIRECTORY=$2

# Verify input parameters
test -z "$PROJECT" \
    && die "missing PROJECT parameter. Use -h for help."
test -z "$DIRECTORY" \
    && die "missing DIRECTORY parameter. Use -h for help."
echo "$PROJECT" | grep -qE '^[A-Za-z0-9\_ \-]+$' \
    || die "invalid PROJECT name '$PROJECT' (only alphanumeric chars allowed)"
test -d "$DIRECTORY" \
    || die "invalid directory '$DIRECTORY'"

# Verify required files
SCRIPTPATH=$(dirname $(readlink -f "$0")) \
    || die "failed to get script's directory"
EVAL_SCRIPT="$SCRIPTPATH/gsv-eval.pl"
test -x "$EVAL_SCRIPT" \
    || die "Perl script ($EVAL_SCRIPT) not found/not executable"
CSS_FILE="$SCRIPTPATH/gsv-eval.css"
test -e "$CSS_FILE" \
     || die "CSS file ($CSS_FILE) not found"

TIMESTAMP=$(date +%F-%H%M%S) || die "failed to get timestamp"

OUTPUT="$PROJECT.$TIMESTAMP"

"$EVAL_SCRIPT" $NOLIMIT --project "$PROJECT" "$DIRECTORY" > "$OUTPUT.md" \
    || die "evaluation script failed"

pandoc --from markdown \
       --to html \
       --table-of-contents \
       --include-in-header "$CSS_FILE" < "$OUTPUT.md" > "$OUTPUT.html" \
    || die "pandoc failed"

echo "$OUTPUT.html"