def _importBlogPost(self, jbeXmlFileName): ravenXmlFileName = self._getRavenXmlFileName(jbeXmlFileName) jbeHtmlFileName = self._getJbeHtmlFileName(jbeXmlFileName) dom = ZDom() dom.load(jbeXmlFileName) newDom = dom.transformToXML(self.dataTransformFilename) self._attachContent(newDom, jbeHtmlFileName) removeNodeList = [] blogNodeList = [] published = False for blogNode in newDom.selectNodes(u"/zns:entry/zns:blogs/zns:blog"): #$NON-NLS-1$ # since there is atleast one blog associated with the entry, assume the post # is published published = True ravenAccountId = blogNode.getAttribute(u"account-id") #$NON-NLS-1$ joeyBlogId = blogNode.getAttribute(u"blog-id") #$NON-NLS-1$ qid = self._convertBlogId(ravenAccountId, joeyBlogId) if self._hasBlog( qid.getId() ): blogNodeList.append(blogNode) self._convertBlogPostBlogInfo(ravenAccountId, qid.getId(), qid.getServerId(), blogNode) else: removeNodeList.append(blogNode) # remove orphan blog infos for blogNode in removeNodeList: blogNode.parentNode.removeChild(blogNode) # save only if there were any blogs associated with the entry or if the post is a draft (published = false) if not published or (blogNodeList and len(blogNodeList) > 0): newDom.save(ravenXmlFileName, True) del dom del newDom
def _importAccount(self, joeyAccountDirName, accountXmlFileName): ravenAccountDirName = self._getRavenAccountDirName(joeyAccountDirName) ravenAccountXmlName = os.path.join(ravenAccountDirName, u"account.xml") #$NON-NLS-1$ os.makedirs(ravenAccountDirName) # Copy over any icons that have been downloaded (or any other resource). fileutil.copyFiles(joeyAccountDirName, ravenAccountDirName) dom = ZDom() dom.load(accountXmlFileName) newDom = dom.transformToXML(self.accountTransformFilename) newDom.setNamespaceMap(ACCOUNT_NSS_MAP) # Encrypt the account password. passwordNode = newDom.selectSingleNode(u"/zns:account/zns:attributes/zns:attribute[@name = 'password']") #$NON-NLS-1$ if passwordNode: password = crypt.encryptPlainText(passwordNode.getText(), PASSWORD_ENCRYPTION_KEY) passwordNode.setText(password) # convert host, port & path combo to a single url attribute; also determine the raven publisher site/type. self._convertApiInfo(newDom) # account id accId = newDom.documentElement.getAttribute(u"account-id") #$NON-NLS-1$ self.validAccounts[accId] = True # convert blog and id format to raven format blogNodeList = newDom.selectNodes(u"/zns:account/zns:blogs/zns:blog") #$NON-NLS-1$ for blogNode in blogNodeList: self._convertAccBlogInfo(accId, blogNode) # Save to disk. newDom.save(ravenAccountXmlName, True) del dom del newDom