def save(self): self.backend_manager.saveConfig(self, self.config, 'General') #TODO: integrate with personnalinfo if self.view is not None and self.view.email is not None: root_section = Element("aMSNAccount") #email emailElmt = SubElement(root_section, "email") emailElmt.text = self.view.email #nick nick = str(self.view.nick) nickElmt = SubElement(root_section, "nick") nickElmt.text = nick #presence presenceElmt = SubElement(root_section, "presence") presenceElmt.text = self.view.presence #password passwordElmt = self.backend_manager.setPassword(self.view.password, root_section) passwordElmt.text = self.view.password #dp #TODO ask the backend dpElmt = SubElement(root_section, "dp", backend='DefaultBackend') #TODO #TODO: save or not, preferred_ui #TODO: backend for config/logs/... if not os.path.isdir(self.account_dir): os.makedirs(self.account_dir, 0700) accpath = os.path.join(self.account_dir, "account.xml") xml_tree = ElementTree(root_section) xml_tree.write(accpath, encoding='utf-8')
def test_simple(self): div = Element('DIV') el = Element('P') div.append(el) el.text = u"Some contents" tree = ElementTree(div) tree.write(open('test.xml', 'w'))
def writeFile(self): #write file try: util.indentXml(self.tree) treeToWrite = ElementTree(self.tree) treeToWrite.write(self.configFile) return True, "" except Exception, (exc): print("Error: Cannot write config.xml: " +str(exc)) return False, util.localize(35008) +": " +str(exc)
def saveConfig(self, account, config): #TODO: improve root_section = Element("aMSNConfig") for e in config._config: val = config._config[e] elmt = SubElement(root_section, "entry", type=type(val).__name__, name=str(e)) elmt.text = str(val) accpath = os.path.join(self.getAccountDir(account.view.email), "config.xml") xml_tree = ElementTree(root_section) xml_tree.write(accpath, encoding='utf-8')
def saveConfig(account, config, name): #TODO: improve if name == 'General': root_section = Element("aMSNConfig") for e in config._config: val = config._config[e] elmt = SubElement(root_section, "entry", type=type(val).__name__, name=str(e)) elmt.text = str(val) accpath = os.path.join(account.account_dir, "config.xml") xml_tree = ElementTree(root_section) xml_tree.write(accpath, encoding='utf-8')
def writeFile(self): #write file try: configFile = util.getConfigXmlPath() util.indentXml(self.tree) treeToWrite = ElementTree(self.tree) treeToWrite.write(configFile) return True, "" except Exception, (exc): print("Error: Cannot write config.xml: " +str(exc)) return False, "Error: Cannot write config.xml: " +str(exc)
def writeFile(self): Logutil.log('writeFile', util.LOG_LEVEL_INFO) #write file try: configFile = util.getConfigXmlPath() util.indentXml(self.tree) treeToWrite = ElementTree(self.tree) treeToWrite.write(configFile) return True, "" except Exception, (exc): print("Error: Cannot write config.xml: " + str(exc)) return False, util.localize(35008) + ": " + str(exc)
def saveConfig(self, account, config): #TODO: improve root_section = Element("aMSNConfig") for e in config._config: val = config._config[e] elmt = SubElement(root_section, "entry", type=type(val).__name__, name=str(e)) elmt.text = str(val) accpath = os.path.join(self.accounts_dir, self._getDir(account.view.email), "config.xml") xml_tree = ElementTree(root_section) xml_tree.write(accpath, encoding='utf-8')
def writeFile(self): Logutil.log('writeFile', util.LOG_LEVEL_INFO) #write file try: configFile = util.getConfigXmlPath() util.indentXml(self.tree) treeToWrite = ElementTree(self.tree) treeToWrite.write(configFile) return True, "" except Exception, (exc): print("Error: Cannot write config.xml: " +str(exc)) return False, util.localize(35008) +": " +str(exc)
def save_account(self, amsn_account): """ @type amsn_account: L{amsn2.core.account_manager.aMSNAccount} """ if amsn_account.view is None or amsn_account.view.email is None: return false self.create_account_file_tree(amsn_account.view.email) amsn_account.backend_manager.save_config(amsn_account, amsn_account.config) #TODO: integrate with personnalinfo root_section = Element("aMSNAccount") #email emailElmt = SubElement(root_section, "email") emailElmt.text = amsn_account.view.email #nick nick = str(amsn_account.view.nick) nickElmt = SubElement(root_section, "nick") nickElmt.text = nick #psm psm = str(amsn_account.view.psm) psmElmt = SubElement(root_section, "psm") psmElmt.text = psm #presence presenceElmt = SubElement(root_section, "presence") presenceElmt.text = amsn_account.view.presence #password if amsn_account.view.save_password: passwdElmt = SubElement(root_section, "password") passwdElmt.text = amsn_account.view.password #dp #TODO ask the backend dpElmt = SubElement(root_section, "dp") #TODO #TODO: save or not, preferred_ui # #save password savePassElmt = SubElement(root_section, "save_password") savePassElmt.text = str(amsn_account.view.save_password) #autologin autologinElmt = SubElement(root_section, "autoconnect") autologinElmt.text = str(amsn_account.view.autologin) #TODO: backend for config/logs/... accpath = os.path.join(self.account_dir, "account.xml") xml_tree = ElementTree(root_section) xml_tree.write(accpath, encoding='utf-8')
def save_config(self, account, config): """ @type account: L{amsn2.core.account_manager.aMSNAccount} @type config: L{amsn2.core.config.aMSNConfig} """ #TODO: improve root_section = Element("aMSNConfig") for e in config._config: val = config._config[e] elmt = SubElement(root_section, "entry", type=type(val).__name__, name=str(e)) elmt.text = str(val) accpath = os.path.join(self.accounts_dir, self._get_dir(account.view.email), "config.xml") xml_tree = ElementTree(root_section) xml_tree.write(accpath, encoding='utf-8')
def saveAccount(self, amsn_account): accdir = self.getAccountDir(amsn_account.view.email) if not os.path.isdir(accdir): os.makedirs(accdir, 0700) amsn_account.backend_manager.saveConfig(amsn_account, amsn_account.config) #TODO: integrate with personnalinfo if amsn_account.view is not None and amsn_account.view.email is not None: root_section = Element("aMSNAccount") #email emailElmt = SubElement(root_section, "email") emailElmt.text = amsn_account.view.email #nick nick = str(amsn_account.view.nick) nickElmt = SubElement(root_section, "nick") nickElmt.text = nick #psm psm = str(amsn_account.view.psm) psmElmt = SubElement(root_section, "psm") psmElmt.text = psm #presence presenceElmt = SubElement(root_section, "presence") presenceElmt.text = amsn_account.view.presence #password if amsn_account.view.save_password: passwdElmt = SubElement(root_section, "password") passwdElmt.text = amsn_account.view.password #dp #TODO ask the backend dpElmt = SubElement(root_section, "dp") #TODO #TODO: save or not, preferred_ui # #save password savePassElmt = SubElement(root_section, "save_password") savePassElmt.text = str(amsn_account.view.save_password) #autologin autologinElmt = SubElement(root_section, "autoconnect") autologinElmt.text = str(amsn_account.view.autologin) #TODO: backend for config/logs/... accpath = os.path.join(accdir, "account.xml") xml_tree = ElementTree(root_section) xml_tree.write(accpath, encoding='utf-8')
def write(self): if self.__path: tree = ElementTree(self.to_xml_element()) tree.write(self.__path, encoding='utf-8')
def write(self): if self.__path: tree = ElementTree(self.to_xml_element()) tree.write(self.__path, encoding="utf-8")