44#
55# Mozilla Public License Version 2.0
66
7+ #! /bin/sh
8+
79# Print help message
810print_help ()
911{
@@ -23,8 +25,8 @@ print_help()
2325log_lvl=0
2426
2527# Parse options
26- while getopts " :hvb :vv:m:o:" opt; do
27- case $opt in
28+ while getopts " :hvp :vv:m:o:" opt; do
29+ case ${ opt} in
2830 h)
2931 echo " Generate custom detray Detector Metadata"
3032 echo
@@ -34,27 +36,40 @@ while getopts ":hvb:vv:m:o:" opt; do
3436 v)
3537 (( log_lvl++ ))
3638 ;;
37- b )
38- build_dir= $ OPTARG
39+ p )
40+ python_dir= ${ OPTARG}
3941 ;;
4042 m)
41- metadata_generator=$OPTARG
43+ metadata_generator=${ OPTARG}
4244 ;;
4345 o)
44- out_dir=$OPTARG
46+ out_dir=${ OPTARG}
4547 ;;
4648 \? )
4749 echo
48- echo " ERROR: Invalid option $opt ! Usage:"
50+ echo " ERROR: Invalid option ${ opt} ! Usage:"
4951 echo
5052 print_help
5153 exit ;;
5254 esac
5355done
5456
55- python_command=" python $metadata_generator "
57+ # Check how to invoke the python interpreter
58+ python_command=" python3"
59+ if [ ! type {$python_command } > /dev/null ]; then
60+ # Try again
61+ python_command=" python"
62+ if [ ! type {$python_command } > /dev/null ]; then
63+ echo
64+ echo " ERROR: No python command found: exiting"
65+ echo
66+ exit
67+ fi
68+ fi
69+
70+ generator_command=" ${python_command} ${metadata_generator} "
5671
57- if [[ -z " $metadata_generator " ] ]; then
72+ if [ -z " ${ metadata_generator} " ]; then
5873 echo
5974 echo " ERROR: No detector metadata scrip supplied! Usage:"
6075 echo
@@ -63,19 +78,19 @@ if [[ -z "$metadata_generator" ]];then
6378fi
6479
6580# Configure verbosity
66- if [[ $ log_lvl == 1 ] ]; then
67- python_command =" $python_command -v"
68- elif [[ $ log_lvl == 2 ] ]; then
69- python_command =" $python_command -vv"
81+ if [ ${ log_lvl} -eq 1 ]; then
82+ generator_command =" ${generator_command} -v"
83+ elif [ ${ log_lvl} -eq 2 ]; then
84+ generator_command =" ${generator_command} -vv"
7085fi
7186
7287# Add the option for the custom output location
73- if [[ ! -z " $out_dir " ] ]; then
74- python_command =" $python_command -o $out_dir "
88+ if [ ! -z " ${ out_dir} " ]; then
89+ generator_command =" ${generator_command} -o ${ out_dir} "
7590fi
7691
77- # Set uo the detray python package
78- source $build_dir /python/setup.sh
92+ # Set up the detray python package
93+ export PYTHONPATH= " ${python_dir} /python" : $PYTHONPATH
7994
8095# Run the generation of the requested metadata
81- eval $python_command
96+ eval ${generator_command}
0 commit comments