# -*- shell -*-

# ----------------------------------------------------------------------
#	Helpers
#

[ "$program" ] || program=${0##*/}

function die() { 
	echo "$program: Error: $*" 1>&2; 
	exit 2
}

function err() { 
	echo "$program: Error: $*" 1>&2; 
	exit 2
}

function warn() { 
	echo "$program: Warning: $*" 1>&2; 
	warnings=1
}

function note() { 
	if [ -n "$OPT_VERBOSE" ]; then say $*; fi
}

function say() { 
	echo -e "$program: $*" 1>&2; 
}

function version() {  
	echo -e "$program: v$version\n\nRunning as $(id -urn) on $(date +'%Y-%m-%d %H:%M')"
}

function filedate() {
    ls --full-time "$1"  | tr ":." "  " | awk '{printf "%sT%s:%s:%s%s:%s\n", $6, $7, $8, $9, substr($11,1,3), substr($11,4,2)}';
}

function py_module_path() {
    module=$1
    python -c "import $module, os.path; print os.path.realpath($module.__path__[0])"
}

function py_module_file() {
    module=$1
    python -c "import $module, os.path; print os.path.realpath($module.__file__)[:-4] + '.py'"
}


#trap 'echo "$program($LINENO): Command failed with error code $? ($0 $*)"; exit 1' ERR