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