Fetch MacroServer Environment Variables (P10)

 
#!/usr/bin/env python
import os, sys
import PyTango
from taurus.core.util.codecs import CodecFactory
import HasyUtils

msLst = HasyUtils.getLocalMacroServerNames()
#
# msLst: ['p99/macroserver/hostname.01']
# speak to the first, probaly the only server
#
ms=PyTango.DeviceProxy( msLst[0])

#
# Read the environment
#
value = ms.Environment
value = CodecFactory().getCodec('pickle').decode(value)
dct = value[1]['new']

if len( sys.argv) > 2:
    sys.exit(0)

#
# if no argument is supplied, print the whole environment (except ScanHistory)
#
if len( sys.argv) == 1:
    print( "The environment of %" % msLst[0])
    for key in list( dct.keys()):
        #
        # ScanHistory produces much output
        #
        if key == 'ScanHistory':
            continue
        print "---- " + key, dct[key]
    print( "\nUsage, e.g.:")
    print( "  ./msEnv.py ")
    print( "  ./msEnv.py ScanDir")
    print( "  ./msEnv.py ScanPrefix")
    print( "  ./msEnv.py DetectorName")
    sys.exit(0)

if not dct.has_key( sys.argv[1]):
    print( "%s not in the environment" % sys.argv[1])
    sys.exit(0)

print( dct[sys.argv[1]])