Ejemplo n.º 1
0
 def testReadXMLFile001(self):
     ''' Read an xml file and make sure get right results '''
     root, trace_dict = read_xml_file('data/demo/GEAR_rule_example_001.xml')
     self.assertNotEquals(root, None)
     self.assertNotEquals(len(trace_dict), 0)
     self.assertEquals(len(trace_dict), 30)
     self.assertEquals(trace_dict[root],(4,'1'))
     
     return
Ejemplo n.º 2
0
 def _parse_file(self, file):
     '''Parse the xml metadata file
     '''
     top_elem, trace_dict = read_xml_file(file, self.number-1)
     if top_elem.tag.split('}')[-1] != 'gear_ruleset':
         self.parse_error(self.trace_id[0], 'root element must be \'gear_ruleset\'')
     # attributes
     for att_key in top_elem.attrib:
         if att_key == 'version_id':
             self.version_id = top_elem.attrib['version_id']
         elif att_key == 'schema_version':
             if top_elem.attrib['schema_version'] != '1.0':
                 self.parse_error(self.trace_id[0], 'gear_ruleset element schema_version was {0} but only 1.0 is currently supported'.format(top_elem.attrib['schema_version']))
         else:
             self.parse_error(self.trace_id[0], 'gear_ruleset element encountered an unexpected attribute: {0}'.format(att_key))
     # elements
     # Have to do the templates first
     template_list = top_elem.findall(GRSE_TEMPLATES)
     if len(template_list) > 0:
         if len(template_list) > 1:
             self.parse_error(self.trace_id[0], 'gear_ruleset element encountered multiple template sub-elements')
         self[GRSE_TEMPLATES].read_from_xml(template_list[0], trace_dict)
     # Now do the rest of the elements
     for event_entry in top_elem:
         entry_name = event_entry.tag.split('}')[-1]
         if entry_name == GRSE_EVENTS:
             if not self.event_input:
                 self.parse_error(self.trace_id[0], 'gear ruleset element \'{0}\' is not supported for this analyzer'.format(GRSE_EVENTS))
             self[GRSE_EVENTS].add_event_info_xml(event_entry, trace_dict)
             if len(self[GRSE_EVENTS].event_info) == 0:
                 self.parse_error(trace_dict[event_entry][0], 'events element specified with no \'event\' elements')
             self[GRSE_CONSTANTS].add_constants(GCON_EVENT_ID, self[GRSE_EVENTS].get_constants(GCON_EVENT_ID))
         elif entry_name == GRSE_CONSTANTS:
             self[GRSE_CONSTANTS].add_constants_xml(event_entry, trace_dict)
         elif entry_name == GRSE_GEAR_CTL:
             self[GRSE_GEAR_CTL].read_xml(event_entry, trace_dict)
         elif entry_name == GRSE_POOL_CTL:
             self[GRSE_POOL_CTL].read_xml(event_entry, trace_dict)
         elif entry_name == GRSE_ANALYZE:
             self[GRSE_ANALYZE].read_from_xml(event_entry, trace_dict)
         elif entry_name == GRSE_TEMPLATES:
             # Handled up front, so skip it
             pass 
         elif entry_name == 'description':
             self.description = event_entry.text
         else:
             # Unexpected element
             self.parse_error(self.trace_id[0], 'unexpected element {0}'.format(entry_name))
     return
Ejemplo n.º 3
0
 def testReadNoXMLFile(self):
     ''' Read with no file specified '''
     root, trace_dict = read_xml_file('')
     self.assertEquals(root, None)
     self.assertEquals(len(trace_dict), 0)
     return