1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
48 from roslib.manifestlib import Depend
49 from roslib.manifestlib import Export
50 from roslib.manifestlib import ManifestException
51 from roslib.manifestlib import ROSDep
52 from roslib.manifestlib import VersionControl
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
64 """
65 Initialize new empty manifest.
66 """
67 super(Manifest, self).__init__('package')
68
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
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
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
118
119
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
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
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