annotate extra/soundsoftware/extract-docs.sh @ 218:292cde42265a feature_20

* Enable Embedded on projects that have new documentation
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Fri, 11 Feb 2011 16:21:55 +0000
parents 1e55195bca45
children c3544e9fd588
rev   line source
chris@203 1 #!/bin/bash
chris@203 2
chris@203 3 # Run this script from anywhere
chris@203 4
chris@203 5 # Enumerate Hg repos; make sure they're up to date; extract docs for
chris@203 6 # each
chris@203 7
chris@203 8 hgdir="/var/hg"
chris@203 9 docdir="/var/doc"
chris@203 10
chris@218 11 apikey=""
chris@218 12 apihost=""
chris@218 13 apiuser=""
chris@218 14 apipass=""
chris@218 15
chris@203 16 progdir=$(dirname $0)
chris@203 17 case "$progdir" in
chris@203 18 /*) ;;
chris@203 19 *) progdir="$(pwd)/$progdir" ;;
chris@203 20 esac
chris@203 21
chris@203 22 types="javadoc doxygen"
chris@203 23
chris@203 24 for x in $types; do
chris@203 25 if [ ! -x "$progdir/extract-$x.sh" ]; then
chris@203 26 echo "Helper script not available: $progdir/extract-$x.sh"
chris@203 27 exit 1
chris@203 28 fi
chris@203 29 done
chris@203 30
chris@218 31 enable_embedded()
chris@218 32 {
chris@218 33 p="$1"
chris@218 34 if [ -n "$apiuser" ]; then
chris@218 35 curl -u "$apiuser":"$apipass" "http://$apihost/sys/projects/$p/embedded.xml?enable=1&key=$apikey" -d ""
chris@218 36 else
chris@218 37 curl "http://$apihost/sys/projects/$p/embedded.xml?enable=1&key=$apikey" -d ""
chris@218 38 fi
chris@218 39 }
chris@218 40
chris@203 41 for projectdir in "$hgdir"/* ; do
chris@203 42
chris@203 43 if [ -d "$projectdir" ] && [ -d "$projectdir/.hg" ]; then
chris@203 44
chris@203 45 project=$(basename "$projectdir")
chris@203 46 echo "Found Hg repo: $projectdir for project $project"
chris@203 47
chris@203 48 ##!!! do as www-data:
chris@203 49 ( cd "$projectdir" ; sudo -u www-data hg -q update ) || exit 1
chris@203 50
chris@203 51 tmpdir=$(mktemp -d "$docdir/tmp_XXXXXX")
chris@203 52
chris@203 53 case "$tmpdir" in
chris@203 54 /*) ;;
chris@203 55 *) echo "Temporary directory creation failed"; exit 1;;
chris@203 56 esac
chris@203 57
chris@203 58 targetdir="$docdir/$project"
chris@203 59
chris@203 60 echo "Temporary dir is $tmpdir, eventual target is $targetdir"
chris@203 61
chris@203 62 ##!!! do as docs user:
chris@203 63 for x in $types; do
chris@203 64 if "$progdir/extract-$x.sh" "$project" "$tmpdir"; then
chris@203 65 break
chris@203 66 else
chris@203 67 echo "Failed to extract via type $x"
chris@203 68 fi
chris@203 69 done
chris@203 70
chris@203 71 if [ -f "$tmpdir/index.html" ]; then
chris@203 72 echo "Processing resulted in an index.html being created, looks good!"
chris@203 73 if [ ! -d "$targetdir" ] || [ ! -f "$targetdir/index.html" ]; then
chris@203 74 # # If we have just written something to a doc directory that was
chris@203 75 # # previously empty, we should switch on Embedded for this project
chris@203 76 echo "This project hasn't had doc extracted before -- I should switch on Embedded for it at this point"
chris@218 77 enable_embedded "$project"
chris@203 78 fi
chris@203 79
chris@203 80 if [ -d "$targetdir" ]; then
chris@203 81 mv "$targetdir" "$targetdir"_"$$" && \
chris@203 82 mv "$tmpdir" "$targetdir" && \
chris@203 83 rm -rf "$targetdir"_"$$"
chris@203 84 else
chris@203 85 echo "Processing resulted in no index.html, skipping"
chris@203 86 mv "$tmpdir" "$targetdir"
chris@203 87 fi
chris@203 88
chris@203 89 else
chris@203 90 # generated nothing (useful)
chris@203 91 rm -rf "$tmpdir"
chris@203 92 fi
chris@203 93 fi
chris@203 94 done
chris@203 95