How to use the rospkg.expand_to_packages function in rospkg

To help you get started, we’ve selected a few rospkg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ros / ros / tools / rosmake / src / rosmake / engine.py View on Github external
self.log_dir = os.path.abspath(options.output_dir)
            else:
                self.log_dir = os.path.join(rospkg.get_ros_home(), 'rosmake', date_time_stamp)

            self.printer.print_all('Logging to directory %s' % self.log_dir)
            if os.path.exists(self.log_dir) and not os.path.isdir(self.log_dir):
                self.printer.print_all('Log destination %s is a file; please remove it or choose a new destination' % self.log_dir)
                sys.exit(1)
            if not os.path.exists(self.log_dir):
                self.printer.print_verbose("%s doesn't exist: creating" % self.log_dir)
                makedirs_with_parent_perms(self.log_dir)

            self.printer.print_verbose('Finished setting up logging')

        stacks_arguments = [s for s in packages if s in rosstack.list()]
        (self.specified_packages, self.rejected_packages) = rospkg.expand_to_packages(packages, rospack, rosstack)

        self.printer.print_all('Expanded args %s to:\n%s' % (packages, self.specified_packages))
        if self.rejected_packages:
            self.printer.print_all('WARNING: The following args could not be parsed as stacks or packages: %s' % self.rejected_packages)
        if len(self.specified_packages) + len(stacks_arguments) == 0:
            self.printer.print_all('ERROR: No arguments could be parsed into valid package or stack names.')
            self.printer.running = False
            return False

        if options.unmark_installed:
            for p in self.specified_packages:
                if self.flag_tracker.remove_nobuild(p):
                    self.printer.print_all('Removed ROS_NOBUILD from %s' % p)
            self.printer.running = False
            return True
github ros-infrastructure / rosdep / src / rosdep2 / main.py View on Github external
if 'ROS_PACKAGE_PATH' not in os.environ:
                os.environ['ROS_PACKAGE_PATH'] = '{0}'.format(path)
            else:
                os.environ['ROS_PACKAGE_PATH'] = '{0}{1}{2}'.format(
                    path,
                    os.pathsep,
                    os.environ['ROS_PACKAGE_PATH']
                )
            pkgs = find_catkin_packages_in(path, options.verbose)
            packages.extend(pkgs)
        # Make packages list unique
        packages = list(set(packages))
    else:
        rospack = rospkg.RosPack()
        rosstack = rospkg.RosStack()
        val = rospkg.expand_to_packages(args, rospack, rosstack)
        packages = val[0]
        not_found = val[1]
    if not_found:
        raise rospkg.ResourceNotFound(not_found[0], rospack.get_ros_paths())

    # Handle the --ignore-src option
    if command in ['install', 'check', 'keys'] and options.ignore_src:
        if options.verbose:
            print('Searching ROS_PACKAGE_PATH for '
                  'sources: ' + str(os.environ['ROS_PACKAGE_PATH'].split(':')))
        ws_pkgs = get_workspace_packages()
        for path in os.environ['ROS_PACKAGE_PATH'].split(':'):
            path = os.path.abspath(path.strip())
            if os.path.exists(path):
                pkgs = find_catkin_packages_in(path, options.verbose)
                ws_pkgs.extend(pkgs)
github ros / ros / core / roslib / src / roslib / stacks.py View on Github external
"""
    Expand names into a list of packages. Names can either be of packages or stacks.

    @param names: names of stacks or packages
    @type  names: [str]
    @return: ([packages], [not_found]). expand_packages() returns two
    lists. The first is of packages names. The second is a list of
    names for which no matching stack or package was found. Lists may have duplicates.
    @rtype: ([str], [str])
    """
    if env is None:
        env = os.environ
    ros_paths = rospkg.get_ros_paths(env)
    rospack = rospkg.RosPack(ros_paths)
    rosstack = rospkg.RosStack(ros_paths)
    return rospkg.expand_to_packages(names, rospack, rosstack)