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

Source Code for Module roslib.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  import roslib.packages 
 48   
 49  MANIFEST_FILE = 'manifest.xml' 
 50   
 51  import roslib.manifestlib 
 52  # re-export symbols for backwards compatibility 
 53  from roslib.manifestlib import ManifestException, Depend, Export, ROSDep, VersionControl 
 54   
55 -class Manifest(roslib.manifestlib._Manifest):
56 """ 57 Object representation of a ROS manifest file 58 """ 59 __slots__ = []
60 - def __init__(self):
61 """ 62 Initialize new empty manifest. 63 """ 64 super(Manifest, self).__init__('package')
65
66 - def get_export(self, tag, attr):
67 """ 68 @return: exports that match the specified tag and attribute, e.g. 'python', 'path' 69 @rtype: [L{Export}] 70 """ 71 return [e.get(attr) for e in self.exports if e.tag == tag if e.get(attr) is not None]
72
73 -def _manifest_file_by_dir(package_dir, required=True, env=None):
74 """ 75 @param package_dir: path to package directory 76 @type package_dir: str 77 @param env: environment dictionary 78 @type env: dict 79 @param required: require that the directory exist 80 @type required: bool 81 @return: path to manifest file of package 82 @rtype: str 83 @raise InvalidROSPkgException: if required is True and manifest file cannot be located 84 """ 85 if env is None: 86 env = os.environ 87 try: 88 p = os.path.join(package_dir, MANIFEST_FILE) 89 if not required and not os.path.exists(p): 90 return p 91 if not os.path.isfile(p): 92 raise roslib.packages.InvalidROSPkgException(""" 93 Package '%(package_dir)s' is improperly configured: no manifest file is present. 94 """%locals()) 95 return p 96 except roslib.packages.InvalidROSPkgException as e: 97 if required: 98 raise
99
100 -def manifest_file(package, required=True, env=None):
101 """ 102 @param package str: package name 103 @type package: str 104 @param env: override os.environ dictionary 105 @type env: dict 106 @param required: require that the directory exist 107 @type required: bool 108 @return: path to manifest file of package 109 @rtype: str 110 @raise InvalidROSPkgException: if required is True and manifest file cannot be located 111 """ 112 # ros_root needs to be determined from the environment or else 113 # everything breaks when trying to launch nodes via ssh where the 114 # path isn't setup correctly. 115 if env is None: 116 env = os.environ 117 d = roslib.packages.get_pkg_dir(package, required, ros_root=env['ROS_ROOT']) 118 return _manifest_file_by_dir(d, required=required, env=env)
119
120 -def load_manifest(package):
121 """ 122 Load manifest for specified package. 123 @param pacakge: package name 124 @type package: str 125 @return: Manifest instance 126 @rtype: L{Manifest} 127 @raise InvalidROSPkgException: if package is unknown 128 """ 129 return parse_file(manifest_file(package))
130
131 -def parse_file(file):
132 """ 133 Parse manifest.xml file 134 @param file: manifest.xml file path 135 @type file: str 136 @return: Manifest instance 137 @rtype: L{Manifest} 138 """ 139 return roslib.manifestlib.parse_file(Manifest(), file)
140
141 -def parse(string, filename='string'):
142 """ 143 Parse manifest.xml string contents 144 @param string: manifest.xml contents 145 @type string: str 146 @return: Manifest instance 147 @rtype: L{Manifest} 148 """ 149 v = roslib.manifestlib.parse(Manifest(), string, filename) 150 if v.version: 151 raise ManifestException("<version> tag is not valid in a package manifest.xml file") 152 return v
153