Environment Variables

#!/bin/env python
# 
# file name: /home/pXXuser/sardanaMacros/environment_class.py
"""this module contains some demo code"""

__all__ = ["environment_class"]

from sardana.macroserver.macro import *
from sardana.macroserver.macro import macro

class environment_class(Macro):
    """reads/write environment variables"""
    def run(self):
        #
        # spock> senv scalarVar 12
        #
        scalarVar = self.getEnv( 'scalarVar')
        self.output( "the value of scalarVar is %s " % scalarVar)
        #
        # spock> senv dictVar "{ 'key1': 'val1', 'key2': 'val2'}"
        #
        dictVar = self.getEnv( 'dictVar')
        self.output( "--- %s" % dictVar)
        for key in dictVar.keys():
            self.output( "key %s -> %s" % (key, dictVar[key]))
        dictVar['key3'] = "val3"
        self.setEnv( 'dictVar', dictVar)                    
        self.setEnv( 'var_out', 'test')
        self.output( "defined var_out")



2019-11-13