Skip to content

Commit c706d04

Browse files
committed
Adding helper function for finding catkin resources
1 parent e5804b5 commit c706d04

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/prpy/util.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,3 +671,25 @@ def GeodesicDistance(t1, t2, r=1.0):
671671
error = GeodesicError(t1, t2)
672672
error[3] = r*error[3]
673673
return numpy.linalg.norm(error)
674+
675+
def FindCatkinResource(package, relative_path):
676+
'''
677+
Find a Catkin resource in the share directory or
678+
the package source directory. Raises IOError
679+
if resource is not found.
680+
681+
@param relative_path Path relative to share or package
682+
source directory
683+
@param package The package to search in
684+
@return Absolute path to resource
685+
'''
686+
from catkin.find_in_workspaces import find_in_workspaces
687+
688+
paths = find_in_workspaces(project=package, search_dirs=['share'],
689+
path=relative_path, first_match_only=True)
690+
691+
if paths and len(paths) == 1:
692+
return paths[0]
693+
else:
694+
raise IOError('Loading resource "{:s}" failed.'.format(
695+
relative_path))

0 commit comments

Comments
 (0)