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

Module packages

source code

Python utilities for manipulating ROS packages. See: http://ros.org/wiki/Packages

Warning: while most of this API is stable, some parts are still fairly experimental and incomplete. In particular, the ROSPackages class in very experimental.

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.
  ROSPackages
UNSTABLE/EXPERIMENTAL
Functions
bool
is_pkg_dir(d)
Returns: True if d is the root directory of a ROS Package
source code
 
get_package_paths(ros_root_required=True, env=None)
Get the paths to search for packages
source code
(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(cache=None, env=None)
List packages in ROS_ROOT and ROS_PACKAGE_PATH.
source code
[str]
list_pkgs_by_path(path, packages=None, cache=None, env=None)
List ROS packages within the specified path.
source code
str
find_node(pkg, node_type, ros_root=None, ros_package_path=None)
Locate the executable that implements the node
source code
[str]
find_resource(pkg, resource_name, filter_fn=None, ros_root=None, ros_package_path=None)
Locate the file named resource_name in package, optionally matching specified filter
source code
{str: [str]}
rosdeps_of(packages)
Collect all rosdeps of specified packages into a dictionary.
source code
 
platform_supported(pkg, os, version)
Return whether the platform defined by os and version is marked as supported in the package @param pkg The package to test for support @param os The os name to test for support @param version The os version to test for support
source code
 
current_platform_supported(pkg)
Return whether the current running platform is marked as supported in the package @param pkg The package to test for support
source code
Variables
  MSG_DIR = 'msg'
  SRV_DIR = 'srv'
  SRC_DIR = 'src'
  ROS_PACKAGE_PATH = 'ROS_PACKAGE_PATH'
  ROS_ROOT = 'ROS_ROOT'
  MANIFEST_FILE = 'manifest.xml'
  __package__ = 'roslib'
Function Details

is_pkg_dir(d)

source code 
Parameters:
  • d (str) - directory location
Returns: bool
True if d is the root directory of a ROS Package

get_package_paths(ros_root_required=True, env=None)

source code 

Get the paths to search for packages

Parameters:
  • ros_root_required (bool) - if True, raise exception if environment is invalid (i.e. ROS_ROOT is not set properly)
  • env (dict) - override os.environ dictionary
Raises:

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 full 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(cache=None, env=None)

source code 

List packages in ROS_ROOT and ROS_PACKAGE_PATH.

If no cache and pkg_dirs arguments are provided, list_pkgs() will use internal _pkg_dir_cache and will return cached answers if available.

Parameters:
  • cache ({str: str, str, str}) - Empty dictionary to store package list in. The format of the cache is {package_name: dir_path, ros_root, ros_package_path}.
Returns: [str]
complete list of package names in ROS environment

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, ros_root=None, ros_package_path=None)

source code 

Locate the executable that implements the node

Parameters:
  • node_type (str) - type of node
  • ros_root (str) - if specified, override ROS_ROOT
  • ros_package_path (str) - if specified, override ROS_PACKAGE_PATH
Returns: str
path to node or None if node is not in the package
Raises:

find_resource(pkg, resource_name, filter_fn=None, ros_root=None, ros_package_path=None)

source code 

Locate the file named resource_name in package, optionally matching specified filter

Parameters:
  • filter (fn(str)) - function that takes in a path argument and returns True if the it matches the desired resource
  • ros_root (str) - if specified, override ROS_ROOT
  • ros_package_path (str) - if specified, override ROS_PACKAGE_PATH
Returns: [str]
lists of matching paths for resource
Raises:

rosdeps_of(packages)

source code 

Collect all rosdeps of specified packages into a dictionary.

Parameters:
  • packages ([str]) - package names
Returns: {str: [str]}
dictionary mapping package names to list of rosdep names.