wg_station.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2010, Willow Garage, Inc.
00006 # All rights reserved.
00007 #
00008 # Redistribution and use in source and binary forms, with or without
00009 # modification, are permitted provided that the following conditions
00010 # are met:
00011 #
00012 #  * Redistributions of source code must retain the above copyright
00013 #    notice, this list of conditions and the following disclaimer.
00014 #  * Redistributions in binary form must reproduce the above
00015 #    copyright notice, this list of conditions and the following
00016 #    disclaimer in the documentation and/or other materials provided
00017 #    with the distribution.
00018 #  * Neither the name of the Willow Garage nor the names of its
00019 #    contributors may be used to endorse or promote products derived
00020 #    from this software without specific prior written permission.
00021 #
00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 # POSSIBILITY OF SUCH DAMAGE.
00034 
00035 ##\author Kevin Watts
00036 
00037 import sys, os
00038 
00039 class WGTestStation(object):
00040     """
00041     Container class for WG test station configuration to operate qual system
00042     """
00043     def __init__(self):
00044         self._power_board = None
00045         self._breaker0 = False
00046         self._breaker1 = False
00047         self._breaker2 = False
00048 
00049         self._gui_host = None
00050         self._test_host = None
00051 
00052         self._envs = {}
00053 
00054     def set_envs(self):
00055         """
00056         Set any environment variables specific to machine.
00057         """
00058         for k, v in self._envs.iteritems():
00059             os.environ[k] = v
00060 
00061     # Machine
00062     @property
00063     def gui_host(self): return self._gui_host
00064     @property
00065     def test_host(self): return self._test_host
00066 
00067     # Power system
00068     @property
00069     def powerboard(self): 
00070         if self._power_board:
00071             return self._power_board
00072         return '0000'
00073     @property
00074     def breaker0(self): return self._breaker0
00075     @property
00076     def breaker1(self): return self._breaker1
00077     @property
00078     def breaker2(self): return self._breaker2
00079 
00080     def xmlLoad(self, xmlDoc):
00081         """
00082         Load machine configuration from XML. 
00083         Required parameters: 
00084           "gui" - GUI machine. Must be full machine name
00085           "host" - Remote host name
00086         Optional:
00087           "powerboard" - SN of power board
00088           "breaker[0-2]" - Bool, to enable power breaker
00089           "env" - Tag <env name="FOO" value="bar" />
00090 
00091         @param xmlDoc XML : 
00092         """
00093         if not xmlDoc.attributes.has_key('gui'):
00094             print >> sys.stderr, "Unable to find attribute \"gui\" in XML doc for test station. XML: %s" % str(xmlDoc)
00095             return False
00096         self._gui_host = xmlDoc.attributes['gui'].value
00097 
00098         if not xmlDoc.attributes.has_key('host'):
00099             print >> sys.stderr, "Unable to find attribute \"host\" in XML doc for test station. XML: %s" % str(xmlDoc)
00100             return False
00101         self._test_host = xmlDoc.attributes['host'].value
00102 
00103         if xmlDoc.attributes.has_key('powerboard'):
00104             self._power_board = xmlDoc.attributes['powerboard'].value
00105             if not len(self._power_board) == 4 and unicode(self._power_board).isnumeric():
00106                 print >> sys.stderr, "Power board entry is invalid. Must be four digits. Ex: \"1001\""
00107                 return False
00108 
00109         if self._power_board and xmlDoc.attributes.has_key('breaker0'):
00110             self._breaker0 = xmlDoc.attributes['breaker0'].value.lower() == 'true'
00111 
00112         if self._power_board and xmlDoc.attributes.has_key('breaker1'):
00113             self._breaker1 = xmlDoc.attributes['breaker1'].value.lower() == 'true'
00114 
00115         if self._power_board and xmlDoc.attributes.has_key('breaker2'):
00116             self._breaker2 = xmlDoc.attributes['breaker2'].value.lower() == 'true'
00117 
00118         envs_xml = xmlDoc.getElementsByTagName('env')
00119         for env_xml in envs_xml:
00120             name = env_xml.attributes['name'].value
00121             value = env_xml.attributs['value'].value
00122 
00123             self._envs[name] = value
00124 
00125         return True
00126 


qualification
Author(s): Kevin Watts (watts@willowgarage.com), Josh Faust (jfaust@willowgarage.com)
autogenerated on Sat Dec 28 2013 17:57:34