def run(self):
     sys.stderr.write("Generating Python code {} for XML file {}".format(
         self.output_path, self.input_path) + "\n")
     self.output_file = open(self.output_path, "w")
     self.make_header()
     self.parser = xmlparser.XMLParser(self.input_path)
     for node in self.parser:
         if node.nodetype == 'UAObject':
             self.make_object_code(node)
         elif node.nodetype == 'UAObjectType':
             self.make_object_type_code(node)
         elif node.nodetype == 'UAVariable':
             self.make_variable_code(node)
         elif node.nodetype == 'UAVariableType':
             self.make_variable_type_code(node)
         elif node.nodetype == 'UAReferenceType':
             self.make_reference_code(node)
         elif node.nodetype == 'UADataType':
             self.make_datatype_code(node)
         elif node.nodetype == 'UAMethod':
             self.make_method_code(node)
         else:
             sys.stderr.write("Not implemented node type: " +
                              node.nodetype + "\n")
     self.output_file.close()
示例#2
0
    def update(self, catkin_ws=DEF_CATKIN_WS):
        """Main function.

        :param catkin_ws: Path to catkin workspace
        :type catkin_ws: str
        """
        print_('\nGenerating source code...')

        self._create_generated_package(catkin_ws)

        # paths for xmls (project and library)
        xmls = [self._paths['config']['proj'], self._paths['config']['lib']]

        self._source = xmlparser.XMLParser(
            self._types_map, self._templates).get_src_from_xml(xmls)

        # writes source files. updates CMakeLists.txt and package.xml files
        self._rewrite_source()

        if 'DEV' in globals() and DEV:
            raise SystemExit  #DEV

        # recompiles robin pkg
        self._recompile_robin(catkin_ws)
        self._restart_robin(DEF_NODE_NAME, catkin_ws)

        print_('\nUpdate finished.')
示例#3
0
    def __init__(self, xmlsettings_file=None):
        super(PowerAware, self).__init__()
        self._stop = threading.Event()

        self.power_data = {}
        self.snmp_settings = {}
        self.oids = {}
        self.module_names = []
        self.xmlparser = xmlparser.XMLParser()

        if xmlsettings_file is not None:
            self.load_snmp_settings(xmlsettings_file)
            self.blade_snmp = snmp.SNMP(**self.snmp_settings)
示例#4
0
 def load_from_stream(self, data, ftype):
     # Does NOT control any error !!!!
     # Error control is performed in the calling code
     self.reset()
     if ftype == "gpe":
         import xmlparser
         p = xmlparser.XMLParser()
         p.parse(data.read())
         for cell in p.xworksheet[0].xcell:
             if int(cell.pvalue) != 0:
                 self.set(idx=int(cell.pidx), value=int(cell.pvalue))
     else:
         for row, line in enumerate(data):
             for col, value in enumerate(line.strip()):
                 if value != "0":
                     self.set((row, col), int(value))
示例#5
0
import xmlparser
import html_generator
import os

books_dir = 'books'
books = os.listdir(books_dir)
for book in books:
    #Create XMLParser and HTMLGenerator instances
    xmlp = xmlparser.XMLParser(f'{books_dir}/{book}')
    htmlgen = html_generator.HTMLGenerator()

    #Get description and texts from book
    xml_description = xmlp.get_description()
    xml_texts = xmlp.get_text()
    sections = []
    titles = []
    count = 0
    #Generate description block
    description = htmlgen.generate_description(xml_description['author'],
                                               xml_description['annotation'],
                                               xml_description['book-title'])
    for xml_text in xml_texts:
        count += 1
        section_text = ''
        titles.append(htmlgen.wrap_title(xml_text['section-title'], count))
        if xml_text['section-texts']:
            #Wrap text into <p></p> tags
            section_text = htmlgen.wrap_paragraph(xml_text['section-texts'])
        #Generate section block
        section = htmlgen.generate_section(xml_text['section-title'],
                                           section_text, count)