Browse Source

Minor code cleanup on development helper scripts

master
htgoebel 11 years ago
parent
commit
c0ee498c5c
  1. 56
      bin/do_pylint.sh
  2. 48
      bin/do_unittests.sh
  3. 40
      bin/run_webserver.sh
  4. 40
      bin/uml-setup.sh

56
bin/do_pylint.sh

@ -1,10 +1,10 @@
#!/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
@ -18,47 +18,49 @@ BASIC_PYTHONPATH=$PROJ_DIR/src
# 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() {
echo "$1" | grep -q "\.py$" && test -e "$1" && return 0
return 1
[ "${1%.py}" != "$1" -a -e "$1" ]
}
get_pythonpath() {
# maybe the argument is a file instead of a module name
is_filename "$1" && echo -n ":$(dirname "$1")"
# maybe the argument is a file instead of a module name
is_filename "$1" && echo -n ":$(dirname "$1")"
}
get_module() {
if is_filename "$1"; then
echo -n "$(basename "${1%.py}")"
else
echo -n "$1"
fi
if is_filename "$1"; then
echo -n "$(basename "$1" .py)"
else
echo -n "$1"
fi
}
run_pylint() {
local new_pythonpath="${BASIC_PYTHONPATH}$(get_pythonpath "$1")"
local arg="$(get_module "$1")"
PYTHONPATH="$new_pythonpath" pylint "$arg"
local new_pythonpath="${BASIC_PYTHONPATH}$(get_pythonpath "$1")"
local arg="$(get_module "$1")"
PYTHONPATH="$new_pythonpath" pylint "$arg"
}
# check the complete (basic) package and the plugins, if no arguments were given
if test $# -eq 0; then
run_pylint cryptobox
find "$PROJ_DIR/plugins" -type f -name \*.py | while read fname; do
run_pylint "$fname"
done
else
while test $# -gt 0; do
run_pylint "$1"
shift
done
# If no arguments were given, check the complete (basic) package and
# the plugin.
if [ $# -eq 0 ] ; then
run_pylint cryptobox
find "$PROJ_DIR/plugins" -type f -name \*.py -print0 | xargs -0 run_pylint
else
for name in "$@" ; do
run_pylint "$name"
done
fi

48
bin/do_unittests.sh

@ -1,7 +1,7 @@
#!/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.
#
# preparations:
# - add the following lines to /etc/super.tab:
@ -16,12 +16,12 @@ export PYTHONPATH=$BASE_DIR/src
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()
{
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
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
if [ -n "$files" ] ; then # run only 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"
else
# run all tests
for a in ${BASE_DIR}/src/cryptobox/tests/test.*.py ; do
testoob -v "$a"
done
fi
@ -69,31 +68,30 @@ usage()
##### main() section #####
##Declare global variables with empty contents
## 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 -- "$@"`
## 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
## Assign the tokens to an array
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 ...
##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" ] \
&& [ "${getopt_arr[2]}" == "--" ]; then
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//\'/}"
#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}\" '.*--\(.*\)'`"
#echo $files
if [ -b "/dev/${clobber_dev_arg}" ]; then

40
bin/run_webserver.sh

@ -2,42 +2,45 @@
#
# example start script to run a local cryptobox webserver
#
# we set some parameters to make it possible to run it without an
# existing cryptobox installation
# We set some parameters to make it possible to run it without an
# existing cryptobox installation.
#
# change your local settings in "cryptobox-local.conf" - if this file
# does not exist, then "cryptobox.conf" is used
# Change your local settings in "cryptobox-local.conf" - if this file
# 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
# "CryptoBoxRootActions" (useful for development)
# BEWARE: the super.tab entry must be named "CryptoBoxRootActionsLocal"
# instead of "CryptoBoxRootActions" (useful for development)
#
BIN_DIR=$(dirname "$0")
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()
{
sed -i "s/^OVERRIDE_FILECHECK = .*$/OVERRIDE_FILECHECK = True/" "$BIN_DIR/CryptoBoxRootActions"
sed -i "s/^OVERRIDE_FILECHECK = .*$/OVERRIDE_FILECHECK = True/" "$BIN_DIR/CryptoBoxRootActions"
}
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
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
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"
## create necessary directories
@ -46,12 +49,15 @@ mkdir -p "$BIN_DIR/../ttt/settings"
cd "$BIN_DIR"
# disable strict security checks of CryptoBoxRootActions
disable_filecheck
## 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_filecheck

40
bin/uml-setup.sh

@ -1,9 +1,9 @@
#!/bin/sh
#uml-setup.sh
# uml-setup.sh
#
#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
#does not apply.
# 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
# does not apply.
PROJ_DIR=$(dirname "$0")/..
PROJ_DIR=$(cd "$PROJ_DIR"; pwd)
@ -12,12 +12,12 @@ TEST_IMG=$PROJ_DIR/bin/test.img
TEST_SIZE=128
MEM_SIZE=128M
if test ! -e "$ROOT_IMG"
then 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 " store (or link) the result as '$ROOT_IMG'"
exit 1
fi
if [ ! -e "$ROOT_IMG" ] ; then
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 " store (or link) the result as '$ROOT_IMG'"
exit 1
fi
# Preparations:
# echo "tun" >>/etc/modules
@ -25,17 +25,19 @@ if test ! -e "$ROOT_IMG"
# 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" ] ; then
echo "Creating testing image file ..."
dd if=/dev/zero of="$TEST_IMG" bs=1M count=$TEST_SIZE
fi
if [ ! -w "$ROOT_IMG" ]; then
echo "Make sure \"${ROOT_IMG}\" exists and is writeable"
exit 1;
if [ ! -w "$ROOT_IMG" ] ; then
echo "Make sure \"${ROOT_IMG}\" exists and is writeable"
exit 1;
fi
# "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

Loading…
Cancel
Save