def __init__(self, xmlfile, struct_name, node_name):    
        logger=logging.getLogger('StructXml.__init__')
        # Build the field list from the xml file
        if os.path.isfile(xmlfile):
            if 0:
                logger.debug("xml file     : %s" % xmlfile)
                logger.debug("struct name  : %s" % struct_name)
                logger.debug("node name    : %s" % node_name)
            
            # Retrieve the lists of fields
            field_l = []    

            try:
                tree    = parse(xmlfile)
                section = tree.find(node_name)
            except:
                logger.error("Failed parsing XML file : %s" % xmlfile)
                sys.exit(CfgError.ERRCODE_SYS_FILE_IO)
            if section is None:
                logger.warning("XML node '%s' not found" % node_name)
            else:
                for node in section.iter('field'):
                    field = (node.attrib.get('name'), str(node.text))
                    field_l.append(field)
                    if 0: logger.debug("field=%s,  value=%s" % (node.attrib.get('name'),  node.text))
        else:
            logger.error("File not found: %s" % xmlfile)
            sys.exit(CfgError.ERRCODE_SYS_FILE_IO)
        
        # Initialize the structure 
        Struct.__init__(self, field_l=field_l, struct_name=struct_name)
示例#2
0
文件: pkg.py 项目: Estwald/PSDK3v2
	def __init__(self):
		Struct.__init__(self)
		self.fileName = ""
示例#3
0
	def __init__(self):
		Struct.__init__(self)
		self.fileName = ""