summaryrefslogtreecommitdiff
path: root/sandbox/davidg/infrastructure/docutils-update
blob: f5ebbd231abcd1856197a3e757506a8e7e76b2d1 (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
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
#! /bin/sh
# $Id$
#
# This script is installed as a cron job to automatically update the
# Docutils web site whenever the CVS files change.  Any .html document
# with a corresponding .txt file is regenerated whenever the .txt
# changes.
#
# Options:
#   -e    Access CVS as current user ("ext" instead of "pserver"; requires
#         authentication).
#   -f    Provide feedback at start and end of program run.
#   -p    Run from the project directory.
#   -t    Run the script in trace mode ("set -o xtrace").
#   -u    Regenerate .html unconditionally.
#   -v    Run verbosely.

# exit on error
set -e

# make all newly created files group writeable
umask 002

projdir=/home/groups/d/do/docutils
project=docutils
dest=$projdir/htdocs
snapshotdir=$projdir/snapshots
pylib=$projdir/lib/python
lib=$pylib/$project
root=

export CVS_RSH=ssh
export CVSROOT=:pserver:anonymous@cvs1:/cvsroot/$project

feedback=0
trace=0
unconditional=0
verbose=0

while getopts efptuv opt
do
    case $opt in
        e)  root="-d:ext:${USER}@cvs1:/cvsroot/docutils" ;;
        f)  feedback=1;;
        p)  export PYTHONPATH=$pylib:$lib:$lib/extras;;
        t)  trace=1;;
        u)  unconditional=1;;
        v)  verbose=1;;
        \?) exit 2;;
    esac
done
shift `expr $OPTIND - 1`

if [ $feedback -eq 1 ] ; then
    echo 'Starting docutils-update run...'
fi

if [ $trace -eq 1 -o $verbose -eq 1 ] ; then
    set -o xtrace
fi

# update library area
cd $lib
cvs -Q -z3 $root update -d -P 2>&1 > /dev/null

# gather the materials
cd $snapshotdir
cvs -Q -z3 $root update -d -P -rHEAD $project sandbox web

# ensure proper permissions are set
find . -type f -print0 | xargs -0 chmod ug+rw 2> /dev/null || true
find . -type d -print0 | xargs -0 chmod ug+rwxs 2> /dev/null || true

# ensure executable bits are set
chmod +x $project/*.py 2> /dev/null || true
chmod +x $project/tools/*.py 2> /dev/null || true
chmod +x $project/test/alltests.py 2> /dev/null || true
find $project/test -name 'test_*.py' -print0 | xargs -0 chmod +x 2> /dev/null || true

# create the snapshots
exclude='--exclude=CVS --exclude=.cvsignore'
tar -cz $exclude -f $project-snapshot.tgz $project
tar -cz $exclude -f $project-sandbox-snapshot.tgz sandbox
tar -cz $exclude -f $project-web-snapshot.tgz web
( cd sandbox/gschwant ;
  tar -cz $exclude -f ../../docfactory-snapshot.tgz docfactory )

# plant the snapshots
mv -f *snapshot.tgz $dest

# update htdocs
cp -ruf $project/* $dest
cp -ruf sandbox $dest
cp -ruf web/* web/.[^.]* $dest

# remove CVS crud
cd $dest
find -name CVS -type d -exec rm -rf {} \; -prune
find -name .cvsignore -type f -exec rm -f {} \; -prune

# ensure proper permissions are set
cd $dest
find . -type f -print0 | xargs -0 chmod ug+rw 2> /dev/null || true
find . -type d -print0 | xargs -0 chmod ug+rwxs 2> /dev/null || true

# update HTML docs
cd $dest/tools

if [ $trace -eq 0 ] ; then
    set +o xtrace
fi

for htmlfile in `find .. -name '*.html'` ; do
    dir=`dirname $htmlfile`
    base=`basename $htmlfile .html`
    txtfile=$dir/$base.txt
    if [ -e $txtfile ] ; then
        if [ $unconditional -eq 1 -o $txtfile -nt $htmlfile ] ; then
            if [ "${base:0:4}" == "pep-" ] ; then
                echo "$txtfile (PEP)"
                # pep2html.py fails on SourceForge; can't import cgi
                # (cgi imports urllib which imports socket which imports 
                # _socket; libssl.so.2 doesn't exist on SF):
                ~/bin/python $lib/tools/pep.py --config=$dir/docutils.conf $txtfile $htmlfile
            else
                echo $txtfile
                ~/bin/python $lib/tools/rst2html.py --config=$dir/docutils.conf $txtfile $htmlfile
            fi
        fi
    fi
done

if [ $feedback -eq 1 ] ; then
    echo '...docutils-update done.'
fi

# Local Variables:
# indent-tabs-mode: nil
# End: