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 sys 
 44  import os 
 45  import getopt 
 46   
 47  STACK_FILE = 'stack.xml' 
 48   
 49  import roslib.manifestlib 
 50  # re-export symbols so that external code does not have to import manifestlib as well 
 51  from roslib.manifestlib import ManifestException, StackDepend 
 52   
53 -class StackManifest(roslib.manifestlib._Manifest):
54 """ 55 Object representation of a ROS manifest file 56 """ 57 __slots__ = []
58 - def __init__(self):
59 """ 60 Create an empty stack manifest instance. 61 """ 62 super(StackManifest, self).__init__('stack')
63
64 -def _stack_file_by_dir(stack_dir, required=True):
65 """ 66 @param stack_dir: path to stack directory 67 @type stack_dir: str 68 @param required: require that the directory exist 69 @type required: bool 70 @return: path to manifest file of stack 71 @rtype: str 72 @raise InvalidROSPkgException: if required is True and manifest file cannot be located 73 """ 74 try: 75 p = os.path.join(stack_dir, STACK_FILE) 76 if not required and not os.path.exists(p): 77 return p 78 if not os.path.isfile(p): 79 raise roslib.stacks.InvalidROSStackException(""" 80 Stack '%(stack_dir)s' is improperly configured: no manifest file is present. 81 """%locals()) 82 return p 83 except roslib.stacks.InvalidROSStackException as e: 84 if required: 85 raise
86
87 -def stack_file(stack, required=True):
88 """ 89 @param stack: stack name 90 @type stack: str 91 @param required: require that the directory exist 92 @type required: bool 93 @return: path to manifest file of stack 94 @rtype: str 95 @raise InvalidROSPkgException: if required is True and manifest file cannot be located 96 """ 97 d = roslib.stacks.get_stack_dir(stack) 98 return _stack_file_by_dir(d, required)
99
100 -def parse_file(file):
101 """ 102 Parse stack.xml file 103 @param file: stack.xml file path 104 @param file: str 105 @return: StackManifest instance 106 @rtype: L{StackManifest} 107 """ 108 return roslib.manifestlib.parse_file(StackManifest(), file)
109
110 -def parse(string, filename='string'):
111 """ 112 Parse stack.xml string contents 113 @param string: stack.xml contents 114 @type string: str 115 @return: StackManifest instance 116 @rtype: L{StackManifest} 117 """ 118 s = roslib.manifestlib.parse(StackManifest(), string, filename) 119 #TODO: validate 120 return s
121