Minor code cleanup on development helper scripts

This commit is contained in:
htgoebel 2011-06-12 12:01:03 +00:00
parent 0f95357e8b
commit c0ee498c5c
4 changed files with 96 additions and 88 deletions

View File

@ -1,10 +1,10 @@
#!/bin/sh #!/bin/sh
# #
# set some environmental variables for pylint and run it # Set some environmental variables for pylint and run it.
# #
# you may specify single files or modules as parameters # You may specify single files or modules as parameters.
# #
# no parameters: check all python files # If no parameters are given, all python files are checked.
# #
set -eu set -eu
@ -18,47 +18,49 @@ BASIC_PYTHONPATH=$PROJ_DIR/src
# check for the pylint program # check for the pylint program
[ ! -x /usr/bin/pylint ] && echo >&2 "please run \"apt-get install pylint\" first" && exit 1 if [ ! -x /usr/bin/pylint ] ; then
echo >&2 "/usr/bin/pylint not found"
echo >&2 "please run \"apt-get install pylint\" first"
exit 1
fi
is_filename() { is_filename() {
echo "$1" | grep -q "\.py$" && test -e "$1" && return 0 [ "${1%.py}" != "$1" -a -e "$1" ]
return 1
} }
get_pythonpath() { get_pythonpath() {
# maybe the argument is a file instead of a module name # maybe the argument is a file instead of a module name
is_filename "$1" && echo -n ":$(dirname "$1")" is_filename "$1" && echo -n ":$(dirname "$1")"
} }
get_module() { get_module() {
if is_filename "$1"; then if is_filename "$1"; then
echo -n "$(basename "${1%.py}")" echo -n "$(basename "$1" .py)"
else else
echo -n "$1" echo -n "$1"
fi fi
} }
run_pylint() { run_pylint() {
local new_pythonpath="${BASIC_PYTHONPATH}$(get_pythonpath "$1")" local new_pythonpath="${BASIC_PYTHONPATH}$(get_pythonpath "$1")"
local arg="$(get_module "$1")" local arg="$(get_module "$1")"
PYTHONPATH="$new_pythonpath" pylint "$arg" PYTHONPATH="$new_pythonpath" pylint "$arg"
} }
# check the complete (basic) package and the plugins, if no arguments were given
if test $# -eq 0; then # If no arguments were given, check the complete (basic) package and
run_pylint cryptobox # the plugin.
find "$PROJ_DIR/plugins" -type f -name \*.py | while read fname; do if [ $# -eq 0 ] ; then
run_pylint "$fname" run_pylint cryptobox
done find "$PROJ_DIR/plugins" -type f -name \*.py -print0 | xargs -0 run_pylint
else else
while test $# -gt 0; do for name in "$@" ; do
run_pylint "$1" run_pylint "$name"
shift done
done
fi fi

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
#do_unittests.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.
# #
# preparations: # preparations:
# - add the following lines to /etc/super.tab: # - add the following lines to /etc/super.tab:
@ -16,12 +16,12 @@ export PYTHONPATH=$BASE_DIR/src
disable_filecheck() disable_filecheck()
{ {
sed -i "s/^OVERRIDE_FILECHECK = .*$/OVERRIDE_FILECHECK = True/" "$BASE_DIR/bin/CryptoBoxRootActions" sed -i "s/^OVERRIDE_FILECHECK = .*$/OVERRIDE_FILECHECK = True/" "$BASE_DIR/bin/CryptoBoxRootActions"
} }
enable_filecheck() 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"
} }
@ -32,19 +32,18 @@ run_tests()
disable_filecheck disable_filecheck
if test -n "$files" if [ -n "$files" ] ; then # run only the specified tests
then # do the specified tests ## The use of "eval", plus not using double quotes for $a
##The use of "eval", plus not using double quotes for ## below are required because getopt already puts argument
##$a below are ## names in single-quotes, and the script will not work with
##required because getopt already puts argument names in ## both sets of quotes.
##single-quotes, and the script will not work with both sets for a in $files ; do
##of quotes. eval testoob -v $a
for a in $files
do eval testoob -v $a
done done
else # do all tests else
for a in ${BASE_DIR}/src/cryptobox/tests/test.*.py # run all tests
do testoob -v "$a" for a in ${BASE_DIR}/src/cryptobox/tests/test.*.py ; do
testoob -v "$a"
done done
fi fi
@ -69,31 +68,30 @@ usage()
##### main() section ##### ##### main() section #####
##Declare global variables with empty contents ## Declare global variables with empty contents
CNAS_UTEST_CLOBBER="" CNAS_UTEST_CLOBBER=""
files="" files=""
clobber_dev_arg="" clobber_dev_arg=""
##Use the getopt command line utility to simplify parsing ## Use the getopt command line utility to simplify parsing
getopt_str=`${GETOPT} -o c: --long clobber: \ getopt_str=$(${GETOPT} -o c: --long clobber: -n do_unittests.sh -- "$@")
-n do_unittests.sh -- "$@"`
#echo $getopt_str #echo $getopt_str
##Assign the tokens to an array ## Assign the tokens to an array
getopt_arr=($getopt_str) getopt_arr=($getopt_str)
##Note: Output of getopt in this script should look like: ## Note: Output of getopt in this script should look like:
## --clobber 'sdX' -- file1 file2 file3 ... ## --clobber 'sdX' -- file1 file2 file3 ...
##Read the following code with that in mind. ## Read the following code with that in mind.
##If there is exactly one option, and it has an argument ## If there is exactly one option, and it has an argument
if [ "${getopt_arr[0]}" == "--clobber" ] \ if [ "${getopt_arr[0]}" == "--clobber" ] \
&& [ "${getopt_arr[2]}" == "--" ]; then && [ "${getopt_arr[2]}" == "--" ]; then
clobber_dev_arg="${getopt_arr[1]}" clobber_dev_arg="${getopt_arr[1]}"
##Strip any single quotes from the device name ## Strip any single quotes from the device name
clobber_dev_arg="${clobber_dev_arg//\'/}" clobber_dev_arg="${clobber_dev_arg//\'/}"
#echo ${clobber_dev_arg} #echo ${clobber_dev_arg}
##Grab the part of $getopt_str that follows "--" ## Grab the part of $getopt_str that follows "--"
files="`expr match \"${getopt_str}\" '.*--\(.*\)'`" files="`expr match \"${getopt_str}\" '.*--\(.*\)'`"
#echo $files #echo $files
if [ -b "/dev/${clobber_dev_arg}" ]; then if [ -b "/dev/${clobber_dev_arg}" ]; then

View File

@ -2,42 +2,45 @@
# #
# example start script to run a local cryptobox webserver # example start script to run a local cryptobox webserver
# #
# we set some parameters to make it possible to run it without an # We set some parameters to make it possible to run it without an
# existing cryptobox installation # existing cryptobox installation.
# #
# change your local settings in "cryptobox-local.conf" - if this file # Change your local settings in "cryptobox-local.conf" - if this file
# does not exist, then "cryptobox.conf" is used # does not exist, then "cryptobox.conf" is used.
# #
# the environment variable PORT may override the default (8080) # Use the environment variable PORT to override the default port
# (8080).
# #
# BEWARE: the super.tab entry must be named "CryptoBoxRootActionsLocal" instead of # BEWARE: the super.tab entry must be named "CryptoBoxRootActionsLocal"
# "CryptoBoxRootActions" (useful for development) # instead of "CryptoBoxRootActions" (useful for development)
# #
BIN_DIR=$(dirname "$0") BIN_DIR=$(dirname "$0")
BIN_DIR=$(cd "$BIN_DIR"; pwd) BIN_DIR=$(cd "$BIN_DIR"; pwd)
PREFERRED_CONF_FILE=$BIN_DIR/cryptobox-local.conf
FALLBACK_CONF_FILE=$BIN_DIR/cryptobox-unittests.conf
## disable ssl detection
#export HTTPS=1
disable_filecheck() disable_filecheck()
{ {
sed -i "s/^OVERRIDE_FILECHECK = .*$/OVERRIDE_FILECHECK = True/" "$BIN_DIR/CryptoBoxRootActions" sed -i "s/^OVERRIDE_FILECHECK = .*$/OVERRIDE_FILECHECK = True/" "$BIN_DIR/CryptoBoxRootActions"
} }
enable_filecheck() enable_filecheck()
{ {
sed -i "s/^OVERRIDE_FILECHECK = .*$/OVERRIDE_FILECHECK = False/" "$BIN_DIR/CryptoBoxRootActions" sed -i "s/^OVERRIDE_FILECHECK = .*$/OVERRIDE_FILECHECK = False/" "$BIN_DIR/CryptoBoxRootActions"
} }
## add the local python directory to the search path ## add the local python directory to the search path
export PYTHONPATH="$BIN_DIR/../src" export PYTHONPATH="$BIN_DIR/../src"
## disable ssl detection
#export HTTPS=1
PREFERRED_CONF_FILE=$BIN_DIR/cryptobox-local.conf
FALLBACK_CONF_FILE=$BIN_DIR/cryptobox-unittests.conf
## determine the configuration file ## determine the configuration file
CONFIG_FILE=$FALLBACK_CONF_FILE CONFIG_FILE=$FALLBACK_CONF_FILE
test -r "$PREFERRED_CONF_FILE" && CONFIG_FILE=$PREFERRED_CONF_FILE if [ -r "$PREFERRED_CONF_FILE" ] ; then
CONFIG_FILE=$PREFERRED_CONF_FILE
fi
echo "used config: $CONFIG_FILE" echo "used config: $CONFIG_FILE"
## create necessary directories ## create necessary directories
@ -46,12 +49,15 @@ mkdir -p "$BIN_DIR/../ttt/settings"
cd "$BIN_DIR" cd "$BIN_DIR"
# disable strict security checks of CryptoBoxRootActions # disable strict security checks of CryptoBoxRootActions
disable_filecheck disable_filecheck
## run the webserver ## run the webserver
"$BIN_DIR/CryptoBoxWebserver" --config="$CONFIG_FILE" --pidfile=/tmp/cryptoboxwebserver.pid --logfile=/tmp/cryptoboxwebserver.log --port=${PORT:-8080} --datadir="$BIN_DIR/../www-data" "$@" "$BIN_DIR/CryptoBoxWebserver" --config="$CONFIG_FILE" \
--port=${PORT:-8080} \
--pidfile=/tmp/cryptoboxwebserver.pid \
--logfile=/tmp/cryptoboxwebserver.log \
--datadir="$BIN_DIR/../www-data" "$@"
# enable strict security checks of CryptoBoxRootActions again # enable strict security checks of CryptoBoxRootActions again
enable_filecheck enable_filecheck

View File

@ -1,9 +1,9 @@
#!/bin/sh #!/bin/sh
#uml-setup.sh # uml-setup.sh
# #
#This file does some setup required for running the unit tests under # This file does some setup required for running the unit tests under
#User Mode Linux (UML). If you are using a different test setup, it # User Mode Linux (UML). If you are using a different test setup, it
#does not apply. # does not apply.
PROJ_DIR=$(dirname "$0")/.. PROJ_DIR=$(dirname "$0")/..
PROJ_DIR=$(cd "$PROJ_DIR"; pwd) PROJ_DIR=$(cd "$PROJ_DIR"; pwd)
@ -12,12 +12,12 @@ TEST_IMG=$PROJ_DIR/bin/test.img
TEST_SIZE=128 TEST_SIZE=128
MEM_SIZE=128M MEM_SIZE=128M
if test ! -e "$ROOT_IMG" if [ ! -e "$ROOT_IMG" ] ; then
then echo "Could not find the cryptobox system image ($ROOT_IMG)" echo "Could not find the cryptobox system image ($ROOT_IMG)"
echo " see stuff/uml-howto.txt for information on how to build a system image" echo " see stuff/uml-howto.txt for information on how to build a system image"
echo " store (or link) the result as '$ROOT_IMG'" echo " store (or link) the result as '$ROOT_IMG'"
exit 1 exit 1
fi fi
# Preparations: # Preparations:
# echo "tun" >>/etc/modules # echo "tun" >>/etc/modules
@ -25,17 +25,19 @@ if test ! -e "$ROOT_IMG"
# add your user to the group 'uml-net' # add your user to the group 'uml-net'
# #
/sbin/ifconfig tap0 &>/dev/null || { echo "tap0 is not configured - read /usr/share/doc/uml-utilities/README.Debian for hints"; exit 1; } if ! /sbin/ifconfig tap0 &>/dev/null ; then
echo "tap0 is not configured - read /usr/share/doc/uml-utilities/README.Debian for hints"
exit 1
fi
if [ ! -e "$TEST_IMG" ] ; then
echo "Creating testing image file ..."
dd if=/dev/zero of="$TEST_IMG" bs=1M count=$TEST_SIZE
fi
if [ ! -e "$TEST_IMG" ] if [ ! -w "$ROOT_IMG" ] ; then
then echo "Creating testing image file ..." echo "Make sure \"${ROOT_IMG}\" exists and is writeable"
dd if=/dev/zero of="$TEST_IMG" bs=1M count=$TEST_SIZE exit 1;
fi
if [ ! -w "$ROOT_IMG" ]; then
echo "Make sure \"${ROOT_IMG}\" exists and is writeable"
exit 1;
fi fi
# "aio=2.4" is necessary, as otherwise sfdiks hangs at "nanosleep({3,0})" # "aio=2.4" is necessary, as otherwise sfdiks hangs at "nanosleep({3,0})"
linux ubd0="$ROOT_IMG" ubd1="$TEST_IMG" con=xterm hostfs=$PROJ_DIR fakehd eth0=daemon mem=$MEM_SIZE aio=2.4 linux ubd0="$ROOT_IMG" ubd1="$TEST_IMG" con=xterm hostfs=$PROJ_DIR fakehd eth0=daemon mem=$MEM_SIZE aio=2.4