Spock startup file: 00-start.py

.

The script ~/.ipython/profile_spockdoor/startup/00-start.py is executed at startup of each spock session. This is an example:

#!/usr/bin/env python
#
# file name ~/.config/ipython/profile_spockdoor/startup/00-start.py
#
import os, time, atexit
import HasyUtils
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')
#
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'])
#
# register exit handler
#
atexit.register( _spockExitHandler)
#
# get the ipython shell
#
ip = get_ipython()
#
ip.magic( '%logstart -o -r -t')
#
# -o log  include output
# -r raw  log 'wm exp_dmy01' instead of get_ipython().magic(u'wm exp_dmy01')
# -t with timestamp
#
#
# store the current motor attributes in a new version of /online_dir/MotorLogs/motorLog.lis
#
os.system('MotorLogger.py -x -q -c spock') 
os.system( "ln -sf %s/ipython_log.py /online_dir/ipython_log.py" % os.environ['PWD'])
#
# -x execute
# -q quiet
# -c the name of the calling program is written to the log file
#
#
#
door = PyTango.DeviceProxy( HasyUtils.getDoorNames()[0])
for cmd in [ "setvo ShowDial False",
             "setvo ShowCtrlAxis True",
             "gh_enable",
#             "gc_enable",
         ]:
    door.RunMacro( cmd.split())
    count = 0
    print "00-start.py, executing:", cmd
    while str( door.state()) == "RUNNING":
        time.sleep(0.1)
        count += 1
        if count > 10:
            print "00-start: DOOR stays RUNNING for command %s " %cmd
            break
#
#
# write some text to the log file
#
# ip.logger.log_write( unicode( "# some text \n"))
#
# prepare aliases for SardanaMonitor and SardanaMessageWindow
#
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"

# ip.magic( 'sm')



2019-11-13