Browse Source

Major updates to scripts for unit tests and pydoc

master
frisco 13 years ago
parent
commit
2e8609b0d2
  1. 118
      bin/do_unittests.sh
  2. 62
      scripts/mk_pydoc.sh

118
bin/do_unittests.sh

@ -1,5 +1,5 @@
#!/bin/sh
#do_unittests.sh
#
# run this script _before_ you do a commit and fix errors before uploading
#
@ -24,51 +24,89 @@ enable_filecheck()
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)
####################################################################3
##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=""
run_tests()
{
# chdir to 'bin' - all config settings depend on this
cd "${BASE_DIR}/bin"
disable_filecheck
if test -n "$files"
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
do eval testoob -v $a
done
else # do all tests
for a in ${BASE_DIR}/src/cryptobox/tests/test.*.py
do testoob -v "$a"
done
fi
enable_filecheck
return 0
}
export CNAS_UTEST_CLOBBER
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
}
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"
##### main() section #####
disable_filecheck
##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
if test -n "$files"
then # do the specified tests
for a in $files
do testoob -v "$a"
done
else # do all tests
for a in ${BASE_DIR}/src/cryptobox/tests/test.*.py
do testoob -v "$a"
done
fi
enable_filecheck

62
scripts/mk_pydoc.sh

@ -5,57 +5,75 @@
#docstrings in CryptoNAS. It must be run from the "trunk" directory.
#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).
#
#epydoc 3.0.1 or later is required for proper operation.
set -e
##?? which version of epydoc is REALLY required?
PYTHONPATH="src"
##Define variables which name programs
EPYDOC=epydoc
EPYDOC="epydoc"
RM="rm"
MV="mv"
MKDIR="mkdir"
LFTP="/usr/bin/lftp" ##must provide complete pathname here
TAR="tar"
PYDOC_ACTIONS="--html"
SVN="svn"
##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:]]+'`"
##Version string for html doc output
DOC_VSTRING="cnas-html_r${REVISION}"
##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
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
##Type(s) of documentation to create
PYDOC_ACTIONS="--html"
PYDOC_PROJNAME=CryptoNAS
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
## (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
$MKDIR -p "${TEMP_HTML_PATH}"
##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
$RM -rf "${HTML_PATH}"
@ -66,12 +84,16 @@ $MV "${TEMP_HTML_PATH}" "${HTML_PATH}"
$RM -f ${DOCTREE}*.tgz
##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=
#LFTP_OPTIONS=
#LFTP_HOST=
#LFTP_DIR=
#LFTP_OPTIONS=""
LFTP_HOST="sftp://systemausfall.org"
LFTP_DIR="/home/frisco/public_html/pydoc"
##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

Loading…
Cancel
Save