def load(self): bRet = True try: parser = etree.XMLParser(remove_blank_text=True) self.__xml = etree.parse(CONFIG_XML_FILE, parser) root = self.__xml.getroot() xml_node = root.xpath("configuration//log") self.__log = int(xml_node[0].text) xml_node = root.xpath("configuration//localized") self.__localized = int(xml_node[0].text) xml_node = root.xpath("configuration//pin") self.__pin = int(xml_node[0].text) xml_node = root.xpath("configuration//adm") self.__adm = int(xml_node[0].text) xml_node = root.xpath("configuration//autoexec") self.__autoexec = int(xml_node[0].text) xml_node = root.xpath("configuration//admhex") self.__admhex = int(xml_node[0].text) except Exception as e: print(e) log.critical(self.__class__.__name__, "load usim_modifier.xml file fail.") bRet = False return bRet
def save(self): bRet = True try: self.__xml.write(CONFIG_XML_FILE, pretty_print=True, xml_declaration=True, encoding='utf-8') except: log.critical(self.__class__.__name__, "save usim_modifier.xml file fail.") bRet = False return bRet
def __update_configurations(self, arg_key, arg_value): root = self.__xml.getroot() node = root.xpath('configuration//' + arg_key) if len(node) > 0: node[0].text = str(arg_value) else: log.critical( self.__class__.__name__, "Can't update " + arg_key + " configuration, re-initial ...") self.__default() self.save()