Title: msenv taurus scheme
SEP: 14
State: DRAFT
Date: 2015-09-18
Drivers: cfalcon cfalcon@cells.es
URL: https://sourceforge.net/p/sardana/wiki/SEP14
License: http://www.jclark.com/xml/copying.txt
Abstract:
Nowadays, access to the environment variables of the MacroServer is not user friendly. MacroServer exposes its environment as an event driven attribute called Environment, with a pickled dictionary as its value. We propose a taurus scheme, msenv, responsible for translating each variable of the enviroment to a taurus attribute.
This SEP describes how to create a new taurus scheme for accessing the MacroServer (from now on also refered as MS) environment variables. The goal of this scheme is to propose the read/write logic of the the environment variables as well as its change events mechanism (especially usefull for resolving inconsistency between the multiple environment clients).
The MacroServer loads the environment variables from the encoded file located in /tmp/tango/MacroServer/<macroservername>. The MS loads the variable at the startup, and it overrides the file each time the user creates/changes variables.
The environment variables can be defined at four levels (from less to more retricitive precedence) :
When someone asks for a variable and it does not exist in the scope the environment manager of the MacroServer tries to get it from the lower scope (4 -> 3 -> 2 ->1 ). TODO: confirm that
The Sardana CLI ("Spock"), connects to a door (configurable via profile) and offers a way to read/write the MacroServer environment. Using Spock a user can set or modify the whole environment (on all levels). This is done using the senv and usenv macros:
Lets see an example:
1 2 3 4 5 6 7 8 | #!/usr/bin/python senv ScanDir "/tmp" # global level # or senv DOOR_NAME.ScanDir "/tmp" # door level # or senv MACRO_NAME.ScanDir "/tmp" # macro level # or senv DOOR_NAME.MACRO_NAME.ScanDir "/tmp" # door.macro level |
A user friendly access to the environement from outside of the Spock has been a requirement for a long time. Nowadays, developers are forced to do complicated scripts for read/write environment variables or simply give up with its use in favor of the intermediate Tango device servers (responsible for configuration) in their applications.
Lets see an example:
1 2 3 4 5 6 7 8 | #!/usr/bin/python import taurus from taurus.core.util import CodecFactory attr_env = taurus.Attribute('macroserver/cfalcon/1/environment') env_value = attr_env.read().value decoded_env_value = CodecFactory().decode(env_value, 'pickle') print decoded_env_value['new']['ScanDir'] |
This SEP proposes to create a simple taurus scheme for read and write of the MS environment variables. The scheme should use the folowing URI names:
Some expected attribute URIs:
TODO
1 2 3 4 5 6 7 8 9 10 11 12 | #!/usr/bin/python import taurus, PyTango def listener(s, t, v): if isinstance(v, PyTango.DeviceAttribute): print "Event ", v.value env = taurus.Attribute("macroserver/cfalcon/1/environment") env.addListener(listener) # Fist event (get all the environment) Event ('pickle', '\x80\x02}q\x00U\x03newq\x01}q\x02(U\x06ScanIDq\x03K0U\x08ScanFileq\x04U\x0bmyscans.tx ...) # From spock change the ScanDirq Event ('pickle', '\x80\x02}q\x00U\x06changeq\x01}q\x02U\x07ScanDirq\x03U\x04/tmpq\x04ss.') |
Copyright (c) 2015 Carlos Falcon-Torres
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Changes