Major updates to scripts for unit tests and pydoc

This commit is contained in:
frisco 2009-06-06 23:24:26 +00:00
parent 9cd3d7dd42
commit 2e8609b0d2
2 changed files with 124 additions and 64 deletions

View file

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
#do_unittests.sh
# #
# run this script _before_ you do a commit and fix errors before uploading # run this script _before_ you do a commit and fix errors before uploading
# #
@ -24,45 +24,23 @@ enable_filecheck()
sed -i "s/^OVERRIDE_FILECHECK = .*$/OVERRIDE_FILECHECK = False/" "$BASE_DIR/bin/CryptoBoxRootActions" sed -i "s/^OVERRIDE_FILECHECK = .*$/OVERRIDE_FILECHECK = False/" "$BASE_DIR/bin/CryptoBoxRootActions"
} }
#Using getopt(1) would be the super-thorough way to do this; use the
#quick-and-dirty method instead
# case $1 in
# --clobber=*)
# TEST_DISK=`echo $1 | sed 's/[-a-zA-Z0-9]*=//'`
# ;;
# *)
# ;;
#
#esac
#parse out the remaining command line arguments
## now check that TEST_DISK is not empty and is a block device (more flexibility could possibly be added) run_tests()
{
# chdir to 'bin' - all config settings depend on this
cd "${BASE_DIR}/bin"
####################################################################3 disable_filecheck
##Attention!!! Don't check this in with the following variable set!
##
## the "/dev/" prefix is already assumed by the test classes
#CNAS_UTEST_CLOBBER="sdb"
CNAS_UTEST_CLOBBER=""
export CNAS_UTEST_CLOBBER if test -n "$files"
dest_files=""
while test $# -gt 0
do files="${files} $(cd $(dirname $1); pwd)/$(basename $1)"
shift
done
# chdir to 'bin' - all config settings depend on this
cd "${BASE_DIR}/bin"
disable_filecheck
if test -n "$files"
then # do the specified tests then # do the specified tests
##The use of "eval", plus not using double quotes for
##$a below are
##required because getopt already puts argument names in
##single-quotes, and the script will not work with both sets
##of quotes.
for a in $files for a in $files
do testoob -v "$a" do eval testoob -v $a
done done
else # do all tests else # do all tests
for a in ${BASE_DIR}/src/cryptobox/tests/test.*.py for a in ${BASE_DIR}/src/cryptobox/tests/test.*.py
@ -70,5 +48,65 @@ if test -n "$files"
done done
fi fi
enable_filecheck enable_filecheck
return 0
}
usage()
{
echo -e "Usage:"
echo -e "\tbin/do_unittests.sh --clobber=foo [ files... ]"
echo -e "\t"
echo -e "\t(Where \"files\", if given, are absolute pathnames)"
echo -e "\t(Example: bin/do_unittests.sh --clobber=sdX)"
echo -e "***Warning: All data on /dev/foo will be DESTROYED!"
echo -e "\t"
exit 1
}
##### main() section #####
##Declare global variables with empty contents
CNAS_UTEST_CLOBBER=""
files=""
clobber_dev_arg=""
##Use the getopt command line utility to simplify parsing
getopt_str=`${GETOPT} -o c: --long clobber: \
-n do_unittests.sh -- "$@"`
#echo $getopt_str
##Assign the tokens to an array
getopt_arr=($getopt_str)
##Note: Output of getopt in this script should look like:
## --clobber 'sdX' -- file1 file2 file3 ...
##Read the following code with that in mind.
##If there is exactly one option, and it has an argument
if [ "${getopt_arr[0]}" == "--clobber" ] \
&& [ "${getopt_arr[2]}" == "--" ]; then
clobber_dev_arg="${getopt_arr[1]}"
##Strip any single quotes from the device name
clobber_dev_arg="${clobber_dev_arg//\'/}"
#echo ${clobber_dev_arg}
##Grab the part of $getopt_str that follows "--"
files="`expr match \"${getopt_str}\" '.*--\(.*\)'`"
#echo $files
if [ -b "/dev/${clobber_dev_arg}" ]; then
export CNAS_UTEST_CLOBBER="${clobber_dev_arg}"
##Run the tests using testoob...
run_tests
else
echo "Error: /dev/${clobber_dev_arg} is not a valid block device"
exit 2
fi
else
usage
fi

View file

@ -5,57 +5,75 @@
#docstrings in CryptoNAS. It must be run from the "trunk" directory. #docstrings in CryptoNAS. It must be run from the "trunk" directory.
#In addition, SVN must know about the "trunk/src" directory (i.e #In addition, SVN must know about the "trunk/src" directory (i.e
#"trunk/src" or one of its parents must have been checked out previously). #"trunk/src" or one of its parents must have been checked out previously).
#
#epydoc 3.0.1 or later is required for proper operation.
set -e set -e
##?? which version of epydoc is REALLY required?
PYTHONPATH="src" PYTHONPATH="src"
##Define variables which name programs ##Define variables which name programs
EPYDOC=epydoc EPYDOC="epydoc"
RM="rm" RM="rm"
MV="mv" MV="mv"
MKDIR="mkdir" MKDIR="mkdir"
LFTP="/usr/bin/lftp" ##must provide complete pathname here
TAR="tar" TAR="tar"
SVN="svn"
PYDOC_ACTIONS="--html"
##Output directory (note that this appears to require an absolute path name) ##Output directory (note that this appears to require an absolute path name)
DOCTREE="/home/jcrofts/src/pydoc/" DOCTREE="${HOME}/src/pydoc/"
TAR_STRIP_DIRS="4"
##Location of a svn tree that it's ok to update and revert
SVN_SANDBOX="${HOME}/src/trunk"
##Top of the directory tree for Python libraries being tested
export PYTHONPATH="${HOME}/src/trunk/src"
PLUGINPATH="${HOME}/src/trunk/plugins"
##Capture the svn revision number corresponding to the pydoc docs
REVISION="`svn info src | grep -E 'Last Changed Rev: [[:digit:]]' | grep -o -E '[[:digit:]]+'`" REVISION="`svn info src | grep -E 'Last Changed Rev: [[:digit:]]' | grep -o -E '[[:digit:]]+'`"
##Version string for html doc output ##Version string for html doc output
DOC_VSTRING="cnas-html_r${REVISION}" DOC_VSTRING="cnas-html_r${REVISION}"
##Name of temporary directory used for epydoc output ##Name of temporary directory used for epydoc output
TEMP_HTML_PATH="${DOCTREE}cnas-html.temp" TEMP_HTML_PATH="${DOCTREE}cnas-html.tmp"
##Final name of epydoc output directory ##Final name of epydoc output directory
HTML_PATH="${DOCTREE}cnas-html" HTML_PATH="${DOCTREE}html"
##TODO: make sure sandbox is up-to-date
## Assume we are being run from the "trunk" directory ## Assume we are being run from the "trunk" directory
##Type(s) of documentation to create
PYDOC_ACTIONS="--html"
PYDOC_PROJNAME=CryptoNAS PYDOC_PROJNAME=CryptoNAS
PYDOC_URL="http://devel.cryptobox.org/" PYDOC_URL="http://devel.cryptobox.org/"
PYDOC_OPTIONS="--show-sourcecode --verbose" PYDOC_OPTIONS="--show-sourcecode --verbose "
# --include-log
export PYTHONPATH=/home/jcrofts/src/trunk/src ##Make sure sandbox is up-to-date
${SVN} revert ${SVN_SANDBOX}
${SVN} update ${SVN_SANDBOX}
##TODO: save build log somewhere...
#TODO: I bet there's a way to do this more cleanly using find -exec '{}' or something #TODO: I bet there's a way to do this more cleanly using find -exec '{}' or something
## (or maybe not. Bash isn't Python.) ## (or maybe not. Bash isn't Python.)
SOURCES=`find ${PYTHONPATH} -name '*.py'` ##Find source files to document. Look in src and plugin directories,
##but skip unittests and root_action files because they are not unique.
SOURCES="`find ${PYTHONPATH} -name '*.py'` \
`find ${PLUGINPATH} -name '*.py' ! -name '*unittests.py' ! -name '*root_action.py'`"
##Make a temporary directory in the doc tree ##Make a temporary directory in the doc tree
$MKDIR -p "${TEMP_HTML_PATH}" $MKDIR -p "${TEMP_HTML_PATH}"
##Generate pydocs in the temp directory ##Generate pydocs in the temp directory
$EPYDOC $PYDOC_ACTIONS $PYDOC_OPTIONS --output=${TEMP_HTML_PATH} $SOURCES $EPYDOC $PYDOC_ACTIONS $PYDOC_OPTIONS --output=${TEMP_HTML_PATH} ${SOURCES}
##Remove the old docs directory ##Remove the old docs directory
$RM -rf "${HTML_PATH}" $RM -rf "${HTML_PATH}"
@ -66,12 +84,16 @@ $MV "${TEMP_HTML_PATH}" "${HTML_PATH}"
$RM -f ${DOCTREE}*.tgz $RM -f ${DOCTREE}*.tgz
##Create compressed archive of newly-created docs ##Create compressed archive of newly-created docs
$TAR -czf "${DOCTREE}/${DOC_VSTRING}.tgz" "${HTML_PATH}" #use --strip-components to strip leading directories from paths in tar
$TAR --strip-components ${TAR_STRIP_DIRS} -czf "${DOCTREE}/${DOC_VSTRING}.tgz" "${HTML_PATH}"
##Not implemented yet (TODO) #LFTP_OPTIONS=""
#LFTP= LFTP_HOST="sftp://systemausfall.org"
#LFTP_OPTIONS= LFTP_DIR="/home/frisco/public_html/pydoc"
#LFTP_HOST=
#LFTP_DIR=
##If LFTP is enabled, perform upload to server ##If LFTP is enabled, perform upload to server
if [ -x ${LFTP} ]; then
${LFTP} -p 2222 -u frisco, ${LFTP_OPTIONS} -e "mirror -R --delete ${DOCTREE} ${LFTP_DIR}" ${LFTP_HOST}
fi