From 05e0ce60611c332fde26aef5271c6c90dc9256b9 Mon Sep 17 00:00:00 2001 From: Ken Conley Date: Wed, 25 May 2011 00:14:00 +0000 Subject: [PATCH] unary stacks support for rosstack and roslib --- test/test_roslib/test/test_roslib_packages.py | 7 +++++ test/test_roslib/test/test_roslib_stacks.py | 26 +++++++++++++++++++ tools/rospack/rosstack.cpp | 6 ++--- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/test/test_roslib/test/test_roslib_packages.py b/test/test_roslib/test/test_roslib_packages.py index 16c95df5..4814e9b6 100644 --- a/test/test_roslib/test/test_roslib_packages.py +++ b/test/test_roslib/test/test_roslib_packages.py @@ -98,6 +98,13 @@ class RoslibPackagesTest(unittest.TestCase): self.assertEquals(foo_p, cache['foo'][0]) self.assertEquals(bar_p, cache['bar'][0]) + def test_list_pkgs_unary(self): + d = roslib.packages.get_pkg_dir('test_roslib') + d = os.path.join(d, 'test', 'stack_tests_unary') + cache = {} + packages = roslib.packages.list_pkgs(pkg_dirs=[d], cache=cache) + self.assertEquals(set(['foo', 'bar']), set(packages)) + def test_find_node(self): import roslib.packages d = roslib.packages.get_pkg_dir('test_roslib') diff --git a/test/test_roslib/test/test_roslib_stacks.py b/test/test_roslib/test/test_roslib_stacks.py index 0ca3dedf..477f0fd8 100644 --- a/test/test_roslib/test/test_roslib_stacks.py +++ b/test/test_roslib/test/test_roslib_stacks.py @@ -113,6 +113,32 @@ class RoslibStacksTest(unittest.TestCase): test_dir = os.path.join(roslib.packages.get_pkg_dir('test_roslib'), 'test', 'stack_tests2') self.assertEquals(set(['foo', 'bar']), set(list_stacks_by_path(test_dir))) + def test_list_stacks_by_path_unary(self): + from roslib.stacks import list_stacks_by_path + # test with synthetic stacks + test_dir = os.path.join(roslib.packages.get_pkg_dir('test_roslib'), 'test', 'stack_tests_unary') + self.assertEquals(set(['bar', 'foo', 'baz']), set(list_stacks_by_path(test_dir))) + + def test_get_stack_dir_unary(self): + # now manipulate the environment to test precedence + # - save original RPP as we popen rosstack in other tests + d = roslib.packages.get_pkg_dir('test_roslib') + d = os.path.join(d, 'test', 'stack_tests_unary') + s1_d = os.path.join(d, 's1') + rpp = os.environ.get(roslib.rosenv.ROS_PACKAGE_PATH, None) + try: + paths = [d] + os.environ[roslib.rosenv.ROS_PACKAGE_PATH] = os.pathsep.join(paths) + self.assertEquals(os.path.join(s1_d, 'foo'), roslib.stacks.get_stack_dir('foo')) + self.assertEquals(os.path.join(s1_d, 'bar'), roslib.stacks.get_stack_dir('bar')) + self.assertEquals(os.path.join(s1_d, 'baz'), roslib.stacks.get_stack_dir('baz')) + finally: + #restore rpp + if rpp is not None: + os.environ[roslib.rosenv.ROS_PACKAGE_PATH] = rpp + else: + del os.environ[roslib.rosenv.ROS_PACKAGE_PATH] + def test_get_stack_dir(self): import roslib.rosenv import roslib.packages diff --git a/tools/rospack/rosstack.cpp b/tools/rospack/rosstack.cpp index 1d9609b7..ce9c0884 100644 --- a/tools/rospack/rosstack.cpp +++ b/tools/rospack/rosstack.cpp @@ -1152,9 +1152,7 @@ void ROSStack::crawl_for_stacks(bool force_crawl) continue; if (ent->d_name[0] == '.') continue; // ignore hidden dirs - else if (Stack::is_package(child_path)) - continue; // ignore this guy, he's a leaf. - if (Stack::is_stack(child_path)) + else if (Stack::is_stack(child_path)) { add_stack(child_path); /* @@ -1179,6 +1177,8 @@ void ROSStack::crawl_for_stacks(bool force_crawl) Stack::stacks.push_back(newp); */ } + else if (Stack::is_package(child_path)) + continue; // ignore this guy, he's a leaf. //check to make sure we're allowed to descend else if (!Stack::is_no_subdirs(child_path)) q.push_front(CrawlQueueEntry(child_path));