simple_hdfhelp.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2008, 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 
00036 import string, os
00037 import neo_util
00038 
00039 def loopHDF(hdf, name=None):
00040   results = []
00041   if name: o = hdf.getObj(name)
00042   else: o = hdf
00043   if o:
00044     o = o.child()
00045     while o:
00046       results.append(o)
00047       o = o.next()
00048   return results
00049 
00050 
00051 def loopKVHDF(hdf, name=None):
00052   results = []
00053   if name: o = hdf.getObj(name)
00054   else: o = hdf
00055   if o:
00056     o = o.child()
00057     while o:
00058       results.append((o.name(), o.value()))
00059       o = o.next()
00060   return results
00061 
00062 
00063 class hdf_iterator:
00064   def __init__(self, hdf):
00065     self.hdf = hdf
00066     self.node = None
00067     if self.hdf:
00068       self.node = self.hdf.child()
00069 
00070   def __iter__(self): return self
00071 
00072   def next(self):
00073     if not self.node:
00074       raise StopIteration
00075 
00076     ret = self.node
00077     self.node = self.node.next()
00078       
00079     return ret
00080 
00081 class hdf_kv_iterator(hdf_iterator):
00082   def next(self):
00083     if not self.node: raise StopIteration
00084 
00085     ret = (self.node.name(), self.node.value())
00086     self.node = self.node.next()
00087       
00088     return ret
00089 
00090 class hdf_key_iterator(hdf_iterator):
00091   def next(self):
00092     if not self.node: raise StopIteration
00093 
00094     ret = self.node.name()
00095     self.node = self.node.next()
00096       
00097     return ret
00098 
00099 class hdf_ko_iterator(hdf_iterator):
00100   def next(self):
00101     if not self.node: raise StopIteration
00102 
00103     ret = (self.node.name(), self.node)
00104     self.node = self.node.next()
00105       
00106     return ret
00107   
00108 
00109 def hdfExportDict(prefix, hdf, dict):
00110   for k,v in dict.items():
00111     hdf.setValue(prefix + "." + str(k), str(v))
00112 
00113 
00114 def hdfExportList(prefix, hdf, list):
00115   n = 0
00116   for item in list:
00117     n = n + 1
00118     hdf.setValue(prefix + "." + str(n), str(item))
00119 
00120 
00121 
00122 
00123 
00124 
00125 


wg_invent_client
Author(s): Scott Hassan, Kevin Watts
autogenerated on Sat Dec 28 2013 17:55:42