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 Warning: do not use this library. It is unstable and most of the routines
36 here have been superceded by other libraries (e.g. rospkg). These
37 routines will likely be *deleted* in future releases.
38 """
39
40 import os
41
42 import roslib.manifest
43 import roslib.names
44 import roslib.packages
45
47 """
48 Helper routine for loading Manifest instances
49 @param package_dir: package directory location
50 @type package_dir: str
51 @return: manifest for package
52 @rtype: Manifest
53 """
54 f = os.path.join(package_dir, roslib.manifest.MANIFEST_FILE)
55 if f:
56 return roslib.manifest.parse_file(f)
57 else:
58 return None
59
61 """
62 List resources in a package directory within a particular
63 subdirectory. This is useful for listing messages, services, etc...
64 @param package_dir: package directory location
65 @type package_dir: str
66 @param subdir: name of subdirectory
67 @type subdir: str
68 @param include_depends: if True, include resources in dependencies as well
69 @type include_depends: bool
70 @param rfilter: resource filter function that returns true if filename is the desired resource type
71 @type rfilter: fn(filename)->bool
72 """
73 package = os.path.basename(package_dir)
74 resources = []
75 dir = roslib.packages._get_pkg_subdir_by_dir(package_dir, subdir, False)
76 if os.path.isdir(dir):
77 resources = [roslib.names.resource_name(package, f, my_pkg=package) \
78 for f in os.listdir(dir) if rfilter(os.path.join(dir, f))]
79 else:
80 resources = []
81 if include_depends:
82 depends = _get_manifest_by_dir(package_dir).depends
83 dirs = [roslib.packages.get_pkg_subdir(d.package, subdir, False) for d in depends]
84 for (dep, dir_) in zip(depends, dirs):
85 if not dir_ or not os.path.isdir(dir_):
86 continue
87 resources.extend(\
88 [roslib.names.resource_name(dep.package, f, my_pkg=package) \
89 for f in os.listdir(dir_) if rfilter(os.path.join(dir_, f))])
90 return resources
91
93 """
94 List resources in a package within a particular subdirectory. This is useful for listing
95 messages, services, etc...
96 @param package: package name
97 @type package: str
98 @param subdir: name of subdirectory
99 @type subdir: str
100 @param include_depends: if True, include resources in dependencies as well
101 @type include_depends: bool
102 @param rfilter: resource filter function that returns true if filename is the desired resource type
103 @type rfilter: fn(filename)->bool
104 """
105 package_dir = roslib.packages.get_pkg_dir(package)
106 return list_package_resources_by_dir(package_dir, include_depends, subdir, rfilter)
107