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