1 import os
2 import roslib
3 import rospy
4
5 from master_discovery_fkie.common import resolve_url
6
7
9 '''
10 Tries to determine the path of the included file. The statement of
11 C{$(find 'package')} will be resolved.
12 @param path: the sting which contains the included path
13 @type path: C{str}
14 @return: C{$(find 'package')} will be resolved. The prefixes `file:///`, `package://` or `pkg://` are also resolved.
15 Otherwise the parameter itself normalized by `os.path.normpath` will be returned.
16 @rtype: C{str}
17 '''
18 path = path.strip()
19 index = path.find('$')
20 if index > -1:
21 startIndex = path.find('(', index)
22 if startIndex > -1:
23 endIndex = path.find(')', startIndex + 1)
24 script = path[startIndex + 1:endIndex].split()
25 if len(script) == 2 and (script[0] == 'find'):
26 try:
27 pkg = roslib.packages.get_pkg_dir(script[1])
28 return os.path.normpath('%s/%s' % (pkg, path[endIndex + 1:]))
29 except Exception as e:
30 rospy.logwarn(str(e))
31 else:
32 try:
33 return resolve_url(path)
34 except ValueError, e:
35 pass
36 return os.path.normpath(path)
37