00-start.py

The IPython startup script

~/.config/ipython/profile_spockdoor/startup/00-start.py

is used to:

To purge versioned files:

$ vrsn       

  Usage: 

    Display all versions:              # vrsn file_name 

    Create a new version:              # vrsn -s file_name

    Purge, keeping nk (def 2):         # vrsn -p [nk] file_name 

    Rename the files, starting from 1: # vrsn -reset file_name 

    -nolog is optional, suppresses informational output

 
#!/usr/bin/env python
#
# file name ~/.config/ipython/profile_spockdoor/startup/00-start.py
#
import os, time, atexit
import PyTango
#
# make sure that 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')
#
# register exit handler
#
atexit.register( _spockExitHandler)
#
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")
door.RunMacro(["gh_enable"])
count = 0
while str( door.state()) == "RUNNING" and count < 5:
    time.sleep(0.1)
    count += 1
door.RunMacro(["gs_enable"])
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"