Configuration

The IPython configuration is stored in $HOME/.config/ipython. This can be changed by setting IPYTHONDIR or by the command line option -ipythondir.

The %edit command uses the EDITOR environment variable to select an editor.

The directory ~/.ipython/profile_spockdoor/startup contains Python scripts that are executed during the start of Spock. They are executed in lexical order. For Spock sessions using the secondDoor profile, the startup directory is ~/.ipython/profile_secondDoor/startup.

The following file, 00-start.py, is a typical startup file.

 
#!/usr/bin/env python
#
# file name ~/.ipython/profile_spockdoor/startup/00-start.py
#
import os, time, atexit
import PyTango
#
# make sure ipython_log.py is in PWD and /online_dir
#
def _spockExitHandler():
    if os.path.exists( '/online_dir/ipython_log.py'):
        os.system( 'vrsn -nolog -s /online_dir/ipython_log.py')

if os.path.exists( "%s/ipython_log.py" % os.environ['PWD']):
    os.system( "vrsn -nolog -s %s/ipython_log.py" % os.environ['PWD'])
    os.system( "/bin/rm %s/ipython_log.py" % os.environ['PWD'])

#
# get the ipython shell
#
ip = get_ipython()
#
# -o log  include output
# -r raw  log 'wm exp_dmy01' instead of get_ipython().magic(u'wm exp_dmy01')
# -t with timestamp
#
ip.magic( '%logstart -o -r -t')
#
# store the current motor attributes in a new version of /online_dir/MotorLogs/motorLog.lis
#
# -x execute
# -q quiet
# -c the name of the calling program is written to the log file
#
os.system('MotorLogger.py -x -q -c spock') 
os.system( "ln -sf %s/ipython_log.py /online_dir/ipython_log.py" % os.environ['PWD'])
#
# write some text to the log file
#
# ip.logger.log_write( unicode( "# some text \n"))
#
# execute some commands in a Door, make sure 
# that the Door is in ON state before the next
# command is submitted.
#
door = PyTango.DeviceProxy("haspp14:10000/p14/door/haspp14.01")
for cmd in ["gh_enable", "gs_enable"]:
    print( "00-start: executing", cmd)
    door.RunMacro(cmd.split())
    count = 0
    while str( door.state()) == "RUNNING" and count < 5:
        time.sleep(0.1)
        count += 1
#
# prepare aliases for SardanaMonitor, SardanaInfoViewer and SardanaMotorMonitor
#
ip.magic( '%alias sm ! SardanaMonitor.py &')
print( "use 'sm' to launch the SardanaMonitor")
ip.magic( '%alias iv ! SardanaInfoViewer.py &')
print( "use 'iv' to launch the SardanaInfoViewer")
ip.magic( '%alias smm ! SardanaMotorMonitor.py &')
print( "use 'smm' to launch the SardanaMotorMonitor")
#
# to launch the SardanaMonitor automatically at spock startup uncomment the next line
#
# ip.magic('sm')
#
# register exit handler
#
atexit.register( _spockExitHandler)