FIXED: check for ipython in init script
[oscopy.git] / ioscopy_app.sh
blob6135540c324fd4ce36e793d1d9946db4eeb220e8
1 #!/bin/sh
2 #-*-Shell-*-
4 IPYTHON=ipython
5 IOSCOPY=ioscopy
6 PYTHON=python
7 IOCFG=--IOscopyConfig
8 REPS="'-b': '$IOCFG.b=True $IOCFG.f=',\
9 '-i': '$IOCFG.i=True',\
10 '-h': '$IOCFG.h=True',\
11 '-H': '-h',\
12 '-q': '--no-banner --IOscopyConfig.quiet=True'"
14 getprofd () {
15 tmpf=tmpfile
16 profd=`$IPYTHON --quick --profile=$IOSCOPY --no-banner --quiet --no-confirm-exit --classic --HistoryManager.hist_file=$tmpf<< EOF| grep /
17 ip=get_ipython()
18 print "\n" + ip.profile_dir.location + "\n"
19 EOF`;
20 rm $tmpf
23 which $IPYTHON
24 if [ $? -ne 0]; then
25 echo IPython not found
26 exit
29 $IPYTHON profile list --log-level=40 | grep $IOSCOPY > /dev/null
30 if [ $? -ne 0 ]; then
31 echo IPython $IOSCOPY profile not found, creating it.
32 $IPYTHON profile create $IOSCOPY
33 getprofd
34 cp @datarootdir@/oscopy/ipython_config.py $profd
35 else
36 getprofd
37 if [ ! -f "$profd/ipython_config.py" ]; then
38 echo IPython $IOSCOPY profile file not found, copying it.
39 cp @datarootdir@/oscopy/ipython_config.py $profd
40 elif [ "$profd/ipython_config.py" -ot "@datarootdir@/oscopy/ipython_config.py" ]; then
41 echo
42 upd=0
43 read -p "IPython $IOSCOPY profile file is outdated, update [N/y] ? " upd
44 echo
45 if [ "$upd" = "Y" -o "$upd" = "y" ] ; then
46 echo Updating IPython $IOSCOPY profile.
47 echo
48 cp @datarootdir@/oscopy/ipython_config.py $profd
49 else
50 echo "skipping profile update."
51 echo
56 # Replace short args with their equivalent, and delete space between = and
57 # file name when needed
58 args=`$PYTHON <<EOF
59 reps={$REPS}
60 argout=[reps.get(s, s) for s in "$*".split()]
61 print " ".join(argout).replace(".f= ", ".f=")
62 EOF`
63 #echo ///// $args +++++++++++++++++++++++
64 $IPYTHON --profile=$IOSCOPY $args