Exemple #1
0
def output(code, parameters):

    if len(code.xpath('/node')) < 1:
        Utilities.logging.warning(
            'No `node` element found. ROS C++ will not generate code!')
        return

    # get the node name
    node_name = Utilities.optionalArgument(code.xpath('/node')[0], 'name').text

    # save the name for the templates
    parameters['node']['name'] = node_name
    # @NOTE why is dpath not working?
    # dpath.util.set(parameters,'/node/name',node_name)

    # use the node name on the file patterns
    node_name_underscore = Utilities.underscore(node_name)
    filepatterns = {'nodename': node_name_underscore}

    # run template engine to generate node code
    if not Utilities.templateEngine(code, parameters, filepatterns,
                                    os.path.dirname(__file__) + '/templates',
                                    parameters['globals']['deploy']):
        sys.exit(1)

    # if the flag compile is set then run catkin
    if parameters['globals']['compile']:
        Utilities.logger.debug("Compiling with: `catkin build " +
                               node_name_underscore + "` in folder " +
                               parameters['globals']['deploy'])
        process = subprocess.Popen(['catkin', 'build', node_name_underscore],
                                   cwd=parameters['globals']['deploy'])
        process.wait()
        if process.returncode > 0:
            Utilities.logger.error("Compilation failed!!!")

    # if the flag launch is set then launch the node
    if parameters['globals']['launch']:
        Utilities.logger.debug("launching: `roslaunch " +
                               node_name_underscore + " " +
                               node_name_underscore + '.launch`')
        process = subprocess.Popen([
            'roslaunch', node_name_underscore, node_name_underscore + '.launch'
        ])

    return 0
Exemple #2
0
def output(xml, parameters):

  # get node name
  node_name_underscore = Utilities.underscore(parameters['node']['name'])

  # make a copy of the xml tree
  xml_copy = copy.deepcopy(xml)

  # delete all atributes
  for element in xml_copy.iter():
    element.attrib.clear()

  # save the tree into a file
  with open(parameters['globals']['deploy'] + '/' + node_name_underscore + '.xml', 'w') as xml_file:
    xml_file.write('<?xml version="1.0"?>\n' + etree.tostring(xml_copy, pretty_print = True))

    Utilities.logging.debug('Wrote file '+parameters['globals']['deploy'] + '/' + node_name_underscore + '.xml...')

  return 0
Exemple #3
0
 def test_underscore(self):
     self.assertEqual(Utilities.underscore('/Here Is A.Phrase'),
                      '_here_is_a_phrase')