Validate IPython release before starting it
[oscopy.git] / ioscopy_app.sh
blob8b7701e340c5992bc678c47c3ba087432cacdd76
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 # Is IPython there ?
24 which $IPYTHON > /dev/null
25 if [ $? -ne 0 ]; then
26 echo IPython not found
27 exit
30 # Validate version of IPython. Option name changed between 0.10 and 0.13.
31 if [ `$IPYTHON --version | tr -d . | cut -c 1-3` -lt "013" ]; then
32 echo IPython > 0.13 needed to run IOscopy
33 exit
34 elif [ `$IPYTHON --version | tr -d . | cut -c 1-3` -lt "013" ]; then
35 echo IPython > 0.13 needed to run IOscopy
36 exit
39 # Now IPython version is validated, let's look for ioscopy profile
40 $IPYTHON profile list --log-level=40 | grep $IOSCOPY > /dev/null
41 if [ $? -ne 0 ]; then
42 echo IPython $IOSCOPY profile not found, creating it.
43 $IPYTHON profile create $IOSCOPY
44 getprofd
45 if [ ! -d $profd ]; then
46 mkdir -p $profd
48 cp @datarootdir@/oscopy/ipython_config.py $profd
49 else
50 getprofd
51 if [ ! -f "$profd/ipython_config.py" ]; then
52 echo IPython $IOSCOPY profile file not found, copying it.
53 cp @datarootdir@/oscopy/ipython_config.py $profd
54 elif [ "$profd/ipython_config.py" -ot "@datarootdir@/oscopy/ipython_config.py" ]; then
55 echo
56 upd=0
57 read -p "IPython $IOSCOPY profile file is outdated, update [N/y] ? " upd
58 echo
59 if [ "$upd" = "Y" -o "$upd" = "y" ] ; then
60 echo Updating IPython $IOSCOPY profile.
61 echo
62 cp @datarootdir@/oscopy/ipython_config.py $profd
63 else
64 echo "skipping profile update."
65 echo
70 # Replace short args with their equivalent, and delete space between = and
71 # file name when needed
72 args=`$PYTHON <<EOF
73 reps={$REPS}
74 argout=[reps.get(s, s) for s in "$*".split()]
75 print " ".join(argout).replace(".f= ", ".f=")
76 EOF`
77 #echo ///// $args +++++++++++++++++++++++
78 $IPYTHON --profile=$IOSCOPY $args