Package roslib :: Module stack_manifest
[frames] | no frames]

Source Code for Module roslib.stack_manifest

  1  #! /usr/bin/env python 
  2  # Software License Agreement (BSD License) 
  3  # 
  4  # Copyright (c) 2008, Willow Garage, Inc. 
  5  # All rights reserved. 
  6  # 
  7  # Redistribution and use in source and binary forms, with or without 
  8  # modification, are permitted provided that the following conditions 
  9  # are met: 
 10  # 
 11  #  * Redistributions of source code must retain the above copyright 
 12  #    notice, this list of conditions and the following disclaimer. 
 13  #  * Redistributions in binary form must reproduce the above 
 14  #    copyright notice, this list of conditions and the following 
 15  #    disclaimer in the documentation and/or other materials provided 
 16  #    with the distribution. 
 17  #  * Neither the name of Willow Garage, Inc. nor the names of its 
 18  #    contributors may be used to endorse or promote products derived 
 19  #    from this software without specific prior written permission. 
 20  # 
 21  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 22  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 23  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 24  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 25  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 26  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 27  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 28  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 29  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 30  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 31  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 32  # POSSIBILITY OF SUCH DAMAGE. 
 33  # 
 34  # Revision $Id$ 
 35  # $Author$ 
 36   
 37  """ 
 38  Warning: do not use this library.  It is unstable and most of the routines 
 39  here have been superceded by other libraries (e.g. rospkg).  These 
 40  routines will likely be *deleted* in future releases. 
 41  """ 
 42   
 43  import os 
 44   
 45  import roslib.manifestlib 
 46  # re-export symbols so that external code does not have to import manifestlib as well 
 47  from roslib.manifestlib import ManifestException  # noqa: F401 
 48  from roslib.manifestlib import StackDepend  # noqa: F401 
 49   
 50  STACK_FILE = 'stack.xml' 
 51   
 52   
53 -class StackManifest(roslib.manifestlib._Manifest):
54 """ 55 Object representation of a ROS manifest file 56 """ 57 __slots__ = [] 58
59 - def __init__(self):
60 """ 61 Create an empty stack manifest instance. 62 """ 63 super(StackManifest, self).__init__('stack')
64 65
66 -def _stack_file_by_dir(stack_dir, required=True):
67 """ 68 @param stack_dir: path to stack directory 69 @type stack_dir: str 70 @param required: require that the directory exist 71 @type required: bool 72 @return: path to manifest file of stack 73 @rtype: str 74 @raise InvalidROSPkgException: if required is True and manifest file cannot be located 75 """ 76 try: 77 p = os.path.join(stack_dir, STACK_FILE) 78 if not required and not os.path.exists(p): 79 return p 80 if not os.path.isfile(p): 81 raise roslib.stacks.InvalidROSStackException(""" 82 Stack '%(stack_dir)s' is improperly configured: no manifest file is present. 83 """ % locals()) 84 return p 85 except roslib.stacks.InvalidROSStackException: 86 if required: 87 raise
88 89
90 -def stack_file(stack, required=True):
91 """ 92 @param stack: stack name 93 @type stack: str 94 @param required: require that the directory exist 95 @type required: bool 96 @return: path to manifest file of stack 97 @rtype: str 98 @raise InvalidROSPkgException: if required is True and manifest file cannot be located 99 """ 100 d = roslib.stacks.get_stack_dir(stack) 101 return _stack_file_by_dir(d, required)
102 103
104 -def parse_file(file):
105 """ 106 Parse stack.xml file 107 @param file: stack.xml file path 108 @param file: str 109 @return: StackManifest instance 110 @rtype: L{StackManifest} 111 """ 112 return roslib.manifestlib.parse_file(StackManifest(), file)
113 114
115 -def parse(string, filename='string'):
116 """ 117 Parse stack.xml string contents 118 @param string: stack.xml contents 119 @type string: str 120 @return: StackManifest instance 121 @rtype: L{StackManifest} 122 """ 123 s = roslib.manifestlib.parse(StackManifest(), string, filename) 124 # TODO: validate 125 return s
126