def roslaunch_parse(filename, verbose=False): """ Take advantage of the roslaunch python package to parse the given file. """ logger.info("Parsing {}".format(filename)) config = ROSLaunchConfig() loader = XmlLoader() loader.load(filename, config, verbose=verbose) return config
def test_ROSLaunchParentNode(self): from roslaunch.server import ROSLaunchParentNode from roslaunch.server import ChildROSLaunchProcess from roslaunch.config import ROSLaunchConfig from roslaunch.pmon import ProcessListener rosconfig = ROSLaunchConfig() try: ROSLaunchParentNode(rosconfig, None) self.fail("should not allow pm as None") except: pass pmon = self.pmon n = ROSLaunchParentNode(rosconfig, pmon) self.assertEquals(rosconfig, n.rosconfig) self.assertEquals([], n.listeners) self.assertEquals({}, n.child_processes) self.assertEquals(n.handler.listeners, n.listeners) self.assertEquals(n.handler.child_processes, n.child_processes) # test add listener self.assertEquals(n.handler.listeners, n.listeners) l = ProcessListener() n.add_process_listener(l) self.assertEquals([l], n.listeners) self.assertEquals(n.handler.listeners, n.listeners) # now, lets make some xmlrpc calls against it import roslaunch.config server = roslaunch.server.ROSLaunchParentNode( roslaunch.config.ROSLaunchConfig(), self.pmon) # it's really dangerous for logging when both a parent and a # child are in the same process, so out of paranoia, clear the # logging handlers roslaunch.core.clear_printlog_handlers() roslaunch.core.clear_printerrlog_handlers() # - register a fake child with the server so that it accepts registration from ROSLaunchChild child_name = 'child-%s' % time.time() child_proc = ChildROSLaunchProcess('foo', [], {}) server.add_child(child_name, child_proc) try: server.start() self.assert_(server.uri, "server URI did not initialize") s = ServerProxy(server.uri) child_uri = 'http://fake-unroutable:1324' # - list children should be empty val = self._succeed(s.list_children()) self.assertEquals([], val) # - register val = self._succeed(s.register(child_name, child_uri)) self.assertEquals(1, val) # - list children val = self._succeed(s.list_children()) self.assertEquals([child_uri], val) finally: server.shutdown('test done')
def test_resolve_duplicate_anon(): from roslaunch.config import ROSLaunchConfig from roslaunch.core import RLException from roslaunch.xmlloader import XmlLoader loader = XmlLoader() config = ROSLaunchConfig() test_path = os.path.abspath( os.path.join(os.path.dirname(__file__), '..', 'xml')) try: loader.load( os.path.join(test_path, 'test-substitution-duplicate-anon-names.xml'), config) assert False, 'loading a launch file with duplicate anon node names should have raised an exception' except RLException: pass
def launch(self): config = ROSLaunchConfig() loader = XmlLoader() path = app.getPackagePath(self.app.package) print "pkgpath", path print "launchfile", self.app.launch_file #os.chdir(pkgpath) fn = os.path.join(path, self.app.launch_file) try: loader.load(fn, config) except: self.task.status = "error" #self.manager.app_update.publish(self.task) self.manager._send_status() return self.runner = ROSLaunchRunner(rospy.get_param("/run_id"), config, is_core=False) self.runner.pm.add_process_listener(self) self.runner.launch()