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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
#!/bin/sh
##
## add_docs.sh
## Login : <speedblue@morpheus>
## Started on Fri Dec 12 15:18:49 2003 Julien Lemoine
## $Id: orgadoc_init_readmes.src,v 1.1 2004/03/25 21:34:03 speedblue Exp $
##
## Copyright (C) 2003 Julien Lemoine
## 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 2 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, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
ORGADOC_DEBUG=0
ORGADOC_SLEEP=0
help()
{
echo "OrgaDoc Init Readme (Try to generate readme.xml files for orgadoc"
echo " automaticaly from documentation files (.pdf, .ps, ...)"
echo
echo "Usage: $0 [OPTION] directory"
echo
echo "Options:"
echo -e " -d, --debug\t\tTurn Debug on"
echo -e " -v, --version\t\tOutput version information and exit"
echo -e " -h, --help\t\tDisplay this help and exit"
}
version()
{
echo "OrgaDoc Init Readmes"
echo "Version : 0.8"
echo
echo "Copyright 2002-2004 Julien Lemoine <speedblue@happycoders.org>"
echo
echo "Report bugs to <speedblue@happycoders.org>."
}
options()
{
case "$1" in
-s)
ORGADOC_SLEEP=1
;;
-d|--debug)
ORGADOC_DEBUG=1
;;
-h|--help)
help
exit 0
;;
-v|--version)
version
exit 0
;;
*)
if [ "$1" != "" ]; then
if [ "$ORGADOC_DIR" = "" ]; then
ORGADOC_DIR=$1;
else
echo "Warning: unused option [$1]"
fi
fi
;;
esac
}
options $1 $2
while shift; do
options $1 $2;
done
if [ "$ORGADOC_DIR" = "" ]; then
echo "Error: You must give a directory"
echo
help
exit 1
fi
PATTERNS='-i -e .pdf$ -e .doc$ -e .ps$ -e .ps.gz$
-e .html$ -e .htm$ -e .ps.Z$'
SUBDIRS=`find $ORGADOC_DIR -maxdepth 1 -type d`
FILES=`find $ORGADOC_DIR -maxdepth 1 -type f`
echo "Entering directory [$ORGADOC_DIR]"
if test -f $ORGADOC_DIR/readme.xml; then
tempfile=`tempfile`
cat $ORGADOC_DIR/readme.xml | (
read lineb
while read line; do
echo $lineb >> $tempfile
lineb=$line
done
)
cp $tempfile $ORGADOC_DIR/readme.xml
rm -f $tempfile
fi
for file in $FILES; do
if echo $file | grep $PATTERNS > /dev/null; then
if ! test -f $ORGADOC_DIR/readme.xml; then
echo '<?xml version="1.0" encoding="ISO-8859-1"?>' >> $ORGADOC_DIR/readme.xml;
echo "<readme>" >> $ORGADOC_DIR/readme.xml;
fi
echo "<document>" >> $ORGADOC_DIR/readme.xml;
FILE=`echo $file | sed "s:[^/]*/::g"`
case $file in
*.pdf)
if [ "$ORGADOC_DEBUG" = "1" ]; then
echo "Found $file, extract title, author, number of pages and date"
fi
TITLE=`pdfinfo $file 2> /dev/null | grep Title: | sed 's/Title:[ \t]\+//'`
AUTHOR=`pdfinfo $file 2> /dev/null | grep Author: | sed 's/Author:[ \t]\+//'`
PAGES=`pdfinfo $file 2> /dev/null | grep Pages: | sed 's/Pages:[ \t]\+//'`
DATE=`pdfinfo $file 2> /dev/null | grep CreationDate: | sed 's/CreationDate:[ \t]\+//'`
echo "<title>$TITLE</title>" >> $ORGADOC_DIR/readme.xml
echo "<file>$FILE</file>" >> $ORGADOC_DIR/readme.xml
echo "<date>$DATE</date>" >> $ORGADOC_DIR/readme.xml
echo "<type>public</public>" >> $ORGADOC_DIR/readme.xml
echo "<author>$AUTHOR</author>" >> $ORGADOC_DIR/readme.xml
echo "<nbpages>$PAGES</nbpages>" >> $ORGADOC_DIR/readme.xml
echo "<language>FIXME: LANGUAGE</language>" >> $ORGADOC_DIR/readme.xml
echo "<summary>FIXME: SUMMARY</summary>" >> $ORGADOC_DIR/readme.xml
if pdfinfo $file 2> /dev/null | grep Tagged | grep yes > /dev/null; then
SECTIONS=`strings $file | grep '/Title ' | sed 's/\/Title[ \t]\+//'`
IFS='
'
for section in $SECTIONS; do
echo "<part>$section</part>" >> $ORGADOC_DIR/readme.xml;
done
IFS='
'
else
echo "<part>FIXME: PART</part>" >> $ORGADOC_DIR/readme.xml
fi
;;
*.ps.gz | *.ps.Z)
if [ "$ORGADOC_DEBUG" = "1" ]; then
echo "Found $file, extract number of pages"
fi
PAGES=`zcat $file | grep '^%%Pages:' | head -1 | sed 's/%%Pages:[ \t]\+//'`
echo "<title>FIXME: TITLE</title>" >> $ORGADOC_DIR/readme.xml
echo "<file>$FILE</file>" >> $ORGADOC_DIR/readme.xml
echo "<date>FIXME: DATE</date>" >> $ORGADOC_DIR/readme.xml
echo "<type>public</public>" >> $ORGADOC_DIR/readme.xml
echo "<author>FIXME: AUTHOR</author>" >> $ORGADOC_DIR/readme.xml
echo "<nbpages>$PAGES</nbpages>" >> $ORGADOC_DIR/readme.xml
echo "<language>FIXME: LANGUAGE</language>" >> $ORGADOC_DIR/readme.xml
echo "<summary>FIXME: SUMMARY</summary>" >> $ORGADOC_DIR/readme.xml
echo "<part>FIXME: PART</part>" >> $ORGADOC_DIR/readme.xml
;;
*.ps)
if [ "$ORGADOC_DEBUG" = "1" ]; then
echo "Found $file, extract number of pages"
fi
PAGES=`cat $file | grep '^%%Pages:' | head -1 | sed 's/%%Pages:[ \t]\+//'`
echo "<title>FIXME: TITLE</title>" >> $ORGADOC_DIR/readme.xml
echo "<file>$FILE</file>" >> $ORGADOC_DIR/readme.xml
echo "<date>FIXME: DATE</date>" >> $ORGADOC_DIR/readme.xml
echo "<type>public</public>" >> $ORGADOC_DIR/readme.xml
echo "<author>FIXME: AUTHOR</author>" >> $ORGADOC_DIR/readme.xml
echo "<nbpages>$PAGES</nbpages>" >> $ORGADOC_DIR/readme.xml
echo "<language>FIXME: LANGUAGE</language>" >> $ORGADOC_DIR/readme.xml
echo "<summary>FIXME: SUMMARY</summary>" >> $ORGADOC_DIR/readme.xml
echo "<part>FIXME: PART</part>" >> $ORGADOC_DIR/readme.xml
;;
*)
if [ "$ORGADOC_DEBUG" = "1" ]; then
echo "Found $file, could not extract any informations from file"
fi
echo "<title>FIXME: TITLE</title>" >> $ORGADOC_DIR/readme.xml
echo "<file>$FILE</file>" >> $ORGADOC_DIR/readme.xml
echo "<date>FIXME: DATE</date>" >> $ORGADOC_DIR/readme.xml
echo "<type>public</public>" >> $ORGADOC_DIR/readme.xml
echo "<author>FIXME: AUTHOR</author>" >> $ORGADOC_DIR/readme.xml
echo "<language>FIXME: LANGUAGE</language>" >> $ORGADOC_DIR/readme.xml
echo "<summary>FIXME: SUMMARY</summary>" >> $ORGADOC_DIR/readme.xml
echo "<part>FIXME: PART</part>" >> $ORGADOC_DIR/readme.xml
;;
esac
echo "</document>" >> $ORGADOC_DIR/readme.xml;
fi
done
if test -f $ORGADOC_DIR/readme.xml; then
echo "</readme>" >> $ORGADOC_DIR/readme.xml;
fi
echo "Leaving directory [$ORGADOC_DIR]"
for dir in $SUBDIRS; do
if [ "$dir" != "." ]; then
if [ "$dir" != "$ORGADOC_DIR" ]; then
if [ "$ORGADOC_DEBUG" = "1" ]; then
$0 $dir -s -d
else
$0 $dir -s
fi
fi
fi
done
if [ "$ORGADOC_SLEEP" = "0" ]; then
echo
echo "readme.xml files are now created, please edit the FIXME lines"
fi
|