4 # This script updates the Docutils web site.
6 # The web-root contains
8 # * files and directories from ``trunk/web``:
10 # * files and directories from ``trunk/docutils``:
11 # All files for easy referencing in mails.
13 # * and ``trunk/sandbox``.
17 # * sourceforge does not offer cron, but shell or web instead:
18 # maybe use cgi-bin script to rebuild the website now and then,
19 # e.g. if accessed and more than one day old and svn is newer.
20 # * use htmlfiles.lst to know which html-files have to be generated.
21 # not exclusively but for directory docs at least.
22 # * maybe skip sandbox .txt files, as they might be input
23 # for tests for example.
27 # Any .html document with a corresponding .txt file is regenerated
28 # if the .txt has changed, but no new .html files will be generated.
32 # Directories might contain Makefile.docutils-update files with
33 # special instructions. only used in docs/user to call rst2s5.
34 # Maybe add special treatment and remove this general solution.
37 # -f Do not give feedback.
38 # -t Run the script in trace mode ("set -o xtrace").
39 # -u Regenerate .html unconditionally.
48 # make all newly created files group writeable
51 # URL for SVN project checkout:
52 svnurl
=https
://docutils.svn.sourceforge.net
/svnroot
/docutils
/trunk
54 basedir
=`pwd`/update-dir
55 if [ ! -e $basedir ] ; then
56 test -d $basedir || mkdir
$basedir
59 # $auxdir is non-public.
61 test -d $auxdir || mkdir
$auxdir
62 # $htdocsdest is the destination for htdocs and will be moved to
63 # another server later; so we keep it non-public (under $auxdir).
64 htdocsdest
=$auxdir/htdocs
65 test -d $htdocsdest || mkdir
$htdocsdest
66 # Where to create the snapshots (non-public).
67 snapshotdir
=$auxdir/snapshots
68 test -d $snapshotdir || mkdir
$snapshotdir
69 # # Where to publish the snapshots (public).
70 # snapshotdest=/home/groups/ftp/pub/docutils
72 test -d $bindir || mkdir
$bindir
74 # htdocs directory on SF.net
75 remoteproject
=/home
/groups
/d
/do
/docutils
76 remotehtdocs
=$remoteproject/htdocs
78 pylib
=$auxdir/lib
/python
84 sshhost
=docutilsupdate
,docutils@web.sourceforge.net
85 sshcommand
="ssh -i $lockdir/id_dsa
86 -o UserKnownHostsFile=$sshdir/known_hosts $sshhost"
87 # Project base URL (for sitemap) without trailing slash.
88 baseurl
="http://docutils.sourceforge.net"
90 export PYTHONPATH
=$pylib:$lib:$lib/extras
91 export PATH
=$lib/tools
:$PATH
98 while getopts ftuv opt
108 shift `expr $OPTIND - 1`
110 test $feedback && echo 'Starting docutils-update run...' || true
112 if [ $trace -eq 1 -o $verbose -eq 1 ] ; then
117 if ! mkdir
$lockdir; then
119 echo Could not create lock directory
at
122 echo Please ensure no other user is running this
script
123 echo and delete the directory.
126 # Always clean up on exit.
127 trap "rm -rf $lockdir; trap - 0; exit 1" 0 1 2 3 15
128 # Make sure the lock directory is deletable (i.e. rwx) by other group
129 # members (in case this script crashes after copying files into the
130 # directory) and un-readable by world (because we'll be storing the
135 # update library area
136 if [ -e $lib ] ; then
140 test -d $pylib || mkdir
-p $pylib
142 svn checkout
$svnurl/docutils
145 # -------------------- Snapshots: --------------------
147 # gather the materials
149 for DIR
in docutils sandbox web
; do
150 test -d $DIR || svn checkout
$svnurl/$DIR
152 svn
-q revert
$project/$project/__init__.py
153 haschanges
="`svn up docutils sandbox web | grep -v '^At revision '; true`"
155 # update __version_details__ string
156 version_details
="snapshot `date -u +%Y-%m-%d`, r`svn info docutils | grep ^Revision: | sed 's/^Revision: //'`"
157 (echo ",s/^__version_details__ = .*\$/__version_details__ = '$version_details'/";
158 echo wq
) | ed
$project/$project/__init__.py
2> /dev
/null
160 # Ensure proper directory permissions are set so that the files can be
161 # modified by several users. Changing permissions of files is
162 # probably not necessary because files can be deleted and re-created.
163 # Do not change permissions of aux directory to keep it non-public
164 # (but change permissions for all subdirectories).
165 #find $basedir -type f -print0 | xargs -0 chmod ug+rw 2> /dev/null || true
166 find $basedir -name aux
-o -type d
-print0 |
xargs -0 chmod ug
+rwxs
2> /dev
/null || true
168 # revert and touch (to avoid updating the web site only because of the
170 svn
-q revert
$project/$project/__init__.py
171 touch $project/$project/__init__.py
--date \
172 "`svn info $project/$project/__init__.py | \
173 grep 'Last Changed Date:' | sed 's/[^:]*: //'`"
175 # -------------------- htdocs: --------------------
179 function copy_to_htdocsdest
() {
180 find "$@" -type d
-name .svn
-prune -o \
( -type f
-o -type l \
) -print0 | \
181 xargs -0 cp --no-dereference --update --parents \
182 --target-directory=$htdocsdest
186 copy_to_htdocsdest sandbox
187 (cd $project; copy_to_htdocsdest
*)
188 (cd web
; copy_to_htdocsdest
* .
[^.
]*)
193 if [ $trace -eq 0 ] ; then
197 for makefile
in `find .. -name Makefile.docutils-update` ; do
198 dir
=`dirname $makefile`
199 ( cd $dir ; make -f Makefile.docutils-update
-s )
202 for htmlfile
in `find .. -name '*.html'` ; do
203 dir
=`dirname $htmlfile`
204 base
=`basename $htmlfile .html`
205 txtfile
=$dir/$base.txt
206 if [ "$base" == "standalone_rst_html4strict" ] ; then
208 echo "skipped: $dir $base"
209 elif [ -e $txtfile ] ; then
210 if [ $unconditional -eq 1 -o $txtfile -nt $htmlfile ] ; then
211 if [ "${base:0:4}" == "pep-" ] ; then
212 test $feedback && echo "$txtfile (PEP)" || true
213 python
$lib/tools
/rstpep2html.py
--config=$dir/docutils.conf
$txtfile $htmlfile
216 test $feedback && echo $txtfile || true
217 python
$lib/tools
/rst2html.py
--config=$dir/docutils.conf
$txtfile $htmlfile
224 if [ $trace -eq 1 -o $verbose -eq 1 ] ; then
228 # -------------------- XML sitemap for search engines: --------------------
232 # Update the sitemap only if something has changed because it takes
233 # very much CPU time.
234 if test -n "$haschanges"; then
236 echo '<?xml version="1.0" encoding="UTF-8"?>'
237 echo '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'
238 if [ $trace -eq 0 ] ; then
241 find .
-name '.[^.]*' -prune -o -type d
-printf '%p/\n' \
242 -o \
( -type f
-o -type l \
) -print | \
244 # i is the file name.
245 if test "$i" == .
/; then
249 elif test "$i" == .
/sitemap
-o "${i: -1}" == / -a -f "${i}index.html"; then
250 # This is a directory and it has an index.html, so we
251 # don't need to include it.
257 lastmod
="`date --iso-8601=seconds -u -r "$i"`"
258 # Google wants a colon in front of the last two digits.
259 lastmod
="${lastmod::22}:00"
260 if test "${i: -5}" == .html
; then
261 # HTML files (including the home page) have highest priority.
263 elif test "${i: -4}" == .txt
; then
264 # Text files have medium priority.
267 # Everything else (source files etc.) has low priority.
270 echo "<url><loc>$url</loc><lastmod>$lastmod</lastmod><priority>$priority</priority></url>"
272 if [ $trace -eq 1 -o $verbose -eq 1 ] ; then
280 # -------------------- Push changes to remote server. --------------------
282 # sourceforge no longer allows shell access, use rsync via ssh
283 # specify your user in your .ssh/config
286 # do not use -a to avoid "failed to set permissions"
287 # -t preserve modification times. But a new svn checkout has new modtime.
288 rsync
-e ssh -r -t .
/ web.sourceforge.net
:$remotehtdocs
292 test $feedback && echo '...docutils-update done.' || true
295 # indent-tabs-mode: nil