Package roslib :: Module packages
[frames] | no frames]

Module packages

source code

Warning: do not use this library. It is unstable and most of the routines here have been superceded by other libraries (e.g. rospkg). These routines will likely be *deleted* in future releases.

Classes
  ROSPkgException
Base class of package-related errors.
  InvalidROSPkgException
Exception that indicates that a ROS package does not exist
  MultipleNodesException
Exception that indicates that multiple ROS nodes by the same name are in the same package.
Functions
(str, str)
get_dir_pkg(d)
Get the package that the directory is contained within.
source code
str
get_pkg_dir(package, required=True, ros_root=None, ros_package_path=None)
Locate directory package is stored in.
source code
str
get_pkg_subdir(package, subdir, required=True, env=None)
Returns: Package subdirectory if package exist, otherwise None.
source code
str
resource_file(package, subdir, resource_name)
Returns: path to resource in the specified subdirectory of the package, or None if the package does not exists
source code
[str]
list_pkgs_by_path(path, packages=None, cache=None, env=None)
List ROS packages within the specified path.
source code
 
find_node(pkg, node_type, rospack=None)
Warning: unstable API due to catkin.
source code
 
find_resource(pkg, resource_name, filter_fn=None, rospack=None)
Warning: unstable API due to catkin.
source code
Variables
  SRC_DIR = 'src'
  ROS_PACKAGE_PATH = 'ROS_PACKAGE_PATH'
  ROS_ROOT = 'ROS_ROOT'
  MANIFEST_FILE = 'manifest.xml'
  PACKAGE_FILE = 'package.xml'
  __package__ = 'roslib'
Function Details

get_dir_pkg(d)

source code 

Get the package that the directory is contained within. This is determined by finding the nearest parent manifest.xml file. This isn't 100% reliable, but symlinks can fool any heuristic that relies on ROS_ROOT.

Parameters:
  • d (str) - directory path
Returns: (str, str)
(package_directory, package) of the specified directory, or None,None if not in a package

get_pkg_dir(package, required=True, ros_root=None, ros_package_path=None)

source code 

Locate directory package is stored in. This routine uses an internal cache.

NOTE: cache does *not* rebuild if packages are relocated after this process is initiated.

Parameters:
  • package (str) - package name
  • required (bool) - if True, an exception will be raised if the package directory cannot be located.
  • ros_root (str) - if specified, override ROS_ROOT
  • ros_package_path (str) - if specified, override ROS_PACKAGE_PATH
Returns: str
directory containing package or None if package cannot be found and required is False.
Raises:

get_pkg_subdir(package, subdir, required=True, env=None)

source code 
Parameters:
  • required (bool) - if True, will attempt to create the subdirectory if it does not exist. An exception will be raised if this fails.
  • package (str) - name of package
  • env (dict) - override os.environ dictionary
  • required (bool) - if True, directory must exist
Returns: str
Package subdirectory if package exist, otherwise None.
Raises:

resource_file(package, subdir, resource_name)

source code 
Parameters:
  • subdir (str) - name of subdir -- these should be one of the string constants, e.g. MSG_DIR
Returns: str
path to resource in the specified subdirectory of the package, or None if the package does not exists
Raises:

list_pkgs_by_path(path, packages=None, cache=None, env=None)

source code 

List ROS packages within the specified path.

Optionally, a cache dictionary can be provided, which will be updated with the package->path mappings. list_pkgs_by_path() does NOT returned cached results -- it only updates the cache.

Parameters:
  • path (str) - path to list packages in
  • packages ([str]) - list of packages to append to. If package is already present in packages, it will be ignored.
  • cache ({str: str}) - (optional) package path cache to update. Maps package name to directory path.
Returns: [str]
complete list of package names in ROS environment. Same as packages parameter.

find_node(pkg, node_type, rospack=None)

source code 

Warning: unstable API due to catkin.

Locate the executable that implements the node

:param node_type: type of node, ``str`` :returns: path to node or None if node is not in the package ``str`` :raises: :exc:rospkg.ResourceNotFound` If package does not exist

find_resource(pkg, resource_name, filter_fn=None, rospack=None)

source code 

Warning: unstable API due to catkin.

Locate the file named resource_name in package, optionally
matching specified filter.  find_resource() will return a list of
matches, but only for a given scope.  If the resource is found in
the binary build directory, it will only return matches in that
directory; it will not return matches from the ROS_PACKAGE_PATH as
well in this case.

:param filter: function that takes in a path argument and
    returns True if the it matches the desired resource, ``fn(str)``
:param rospack: `rospkg.RosPack` instance to use
:returns: lists of matching paths for resource within a given scope, ``[str]``
:raises: :exc:`rospkg.ResourceNotFound` If package does not exist