def runAction(self, actionContext): # @UnusedVariable try: dialog = ZImportZBWProfileDialog(self.manager, self.model) dialog.setProfileName(_extstr(u"importactions.ImportedZBWProfile")) # $NON-NLS-1$ dialog.setJoeyProfilePath(self._detectZBWProfilePath()) defaultProfilePath = self.manager._createProfilePath(u"ImportedProfileZBW") # $NON-NLS-1$ if not os.path.exists(defaultProfilePath): dialog.setProfilePath(defaultProfilePath) dialog.CentreOnParent() if dialog.ShowModal() == wx.ID_OK: profileInfo = dialog.getProfileInfo() joeyProfilePath = dialog.getPathToJoeyProfile() importer = ZBlogWriterProfileImporter(joeyProfilePath, profileInfo[1], self.manager.systemProfile) if ( ZShowProgressDialog(self.manager, _extstr(u"manager.ImportingZBW1XProfile"), importer) == wx.ID_OK ): # $NON-NLS-1$ self.model.createProfile(profileInfo) self.manager.profilesListView.refresh() self.manager.profilesListView.Select(self.manager._getProfileIndex(profileInfo[0]), True) else: # Cancelled - remove any files we may have created. fileutil.deleteDirectory(profileInfo[1], False) dialog.Destroy() except Exception, e: ZShowExceptionMessage(self.manager, e)
def runAction(self, actionContext): #@UnusedVariable try: dialog = ZImportZBWProfileDialog(self.manager, self.model) dialog.setProfileName( _extstr(u"importactions.ImportedZBWProfile")) #$NON-NLS-1$ dialog.setJoeyProfilePath(self._detectZBWProfilePath()) defaultProfilePath = self.manager._createProfilePath( u"ImportedProfileZBW") #$NON-NLS-1$ if not os.path.exists(defaultProfilePath): dialog.setProfilePath(defaultProfilePath) dialog.CentreOnParent() if dialog.ShowModal() == wx.ID_OK: profileInfo = dialog.getProfileInfo() joeyProfilePath = dialog.getPathToJoeyProfile() importer = ZBlogWriterProfileImporter( joeyProfilePath, profileInfo[1], self.manager.systemProfile) if ZShowProgressDialog( self.manager, _extstr(u"manager.ImportingZBW1XProfile"), importer) == wx.ID_OK: #$NON-NLS-1$ self.model.createProfile(profileInfo) self.manager.profilesListView.refresh() self.manager.profilesListView.Select( self.manager._getProfileIndex(profileInfo[0]), True) else: # Cancelled - remove any files we may have created. fileutil.deleteDirectory(profileInfo[1], False) dialog.Destroy() except Exception, e: ZShowExceptionMessage(self.manager, e)
def deleteTemplate(self, templateId): template = self.getTemplate(templateId) if template is not None: self.templates.remove(template) deleteDirectory(template.getTemplateDirectory(), True) self._fireDeletedTemplateEvent(template) return True return False
def deleteProfile(self, profileName, deleteContent = False): profileElem = self.profilesDom.selectSingleNode(u"/profiles/profile[@name = \"%s\"]" % profileName) #$NON-NLS-1$ if not profileElem: raise ZBlogAppException(_extstr(u"manager.ProfileNotFound") % profileName) #$NON-NLS-1$ # Now delete the content... if deleteContent: path = profileElem.getText() fileutil.deleteDirectory(path, True) profileElem.parentNode.removeChild(profileElem) self._saveProfilesDom()
def deleteProfile(self, profileName, deleteContent=False): profileElem = self.profilesDom.selectSingleNode( u"/profiles/profile[@name = \"%s\"]" % profileName) #$NON-NLS-1$ if not profileElem: raise ZBlogAppException( _extstr(u"manager.ProfileNotFound") % profileName) #$NON-NLS-1$ # Now delete the content... if deleteContent: path = profileElem.getText() fileutil.deleteDirectory(path, True) profileElem.parentNode.removeChild(profileElem) self._saveProfilesDom()
def put(self, connectionRespInfo, contentFilename): urlHash = self._hashUrl(connectionRespInfo.getURL()) urlDir = os.path.join(self.cacheDir, urlHash) if os.path.exists(urlDir): deleteDirectory(urlDir, False) else: os.makedirs(urlDir) urlMetaFile = os.path.join(urlDir, u"meta-data.xml") #$NON-NLS-1$ dataFName = self._getContentFilename(contentFilename) self._serializeResponseInfo(urlMetaFile, connectionRespInfo, dataFName) dataFile = os.path.join(urlDir, dataFName) move(contentFilename, dataFile) # Now return a full IZHttpConnectionResp object based on the cached info. url = connectionRespInfo.getURL() code = connectionRespInfo.getCode() message = connectionRespInfo.getMessage() headers = connectionRespInfo.getHeaders() return ZHttpConnectionResp(url, code, message, headers, dataFile)
def _deleteTempFiles(self): tempDir = getApplicationModel().getUserProfile().getTempDirectory() try: deleteDirectory(tempDir, False, tempFileFilter) except Exception, e: getLoggerService().exception(e)
def destroy(self): del self.speller self.speller = None if self.isTempAspellDir: deleteDirectory(self.aspellDir, True)
def _clearAllSnapshots(self): deleteDirectory(self.recoveryDir, False)
def _deleteAccount(self, account): accountDir = account.getDirectoryPath() fileutil.deleteDirectory(accountDir, True)
def _fetchTemplate(self, url, title, bodyStr): templateService = getApplicationModel().getService( IZBlogAppServiceIDs.TEMPLATE_SERVICE_ID) template = templateService.createTemplate() templateDir = template.getTemplateDirectory() try: webPageGetter = ZHttpWebpageGetter(url, templateDir, self) webPageGetter.setBasePathToken( IZTemplateConstants.TEMPLATE_BASE_TOKEN) rootFilePath = webPageGetter.saveAsWebpage() if self.cancelled: raise ZTemplateFetchCancelledException() rootXHtmlDoc = loadXhtmlDocumentFromFile(rootFilePath) rootXHtmlDom = rootXHtmlDoc.getDom() titleElems = self._findTitleElems(rootXHtmlDom, title) if not titleElems: return None contentElems = self._findContentElems(rootXHtmlDom, bodyStr) if not contentElems: return None indexAllUTFileName = os.path.join( templateDir, u"index-all-untrimmed.html") #$NON-NLS-1$ rootXHtmlDom.save(indexAllUTFileName) if self.cancelled: raise ZTemplateFetchCancelledException() for titleElem in titleElems: titleElem.removeAllChildren() titleMarkerElem = rootXHtmlDom.createElement( u"ravenTitle", titleElem.getNamespaceUri()) #$NON-NLS-1$ titleElem.appendChild(titleMarkerElem) for contentElem in contentElems: contentElem.removeAllChildren() contentMarkerElem = rootXHtmlDom.createElement( u"ravenBody", contentElem.getNamespaceUri()) #$NON-NLS-1$ contentElem.appendChild(contentMarkerElem) rootFile = makeRelativePath(templateDir, rootFilePath) indexAllFileName = u"index-all.html" #$NON-NLS-1$ indexBodyOnlyFileName = u"index-body.html" #$NON-NLS-1$ indexTitleAndBodyFileName = u"index-titleBody.html" #$NON-NLS-1$ template.setRootFileName(rootFile) template.setAllFileName(indexAllFileName) template.setBodyOnlyFileName(indexBodyOnlyFileName) template.setTitleAndBodyFileName(indexTitleAndBodyFileName) indexAll = os.path.join(templateDir, indexAllFileName) indexTitleAndBody = os.path.join(templateDir, indexTitleAndBodyFileName) indexBodyOnly = os.path.join(templateDir, indexBodyOnlyFileName) self.listener.grabFeedback( _extstr(u"templategrabber.TemplateDownloaded_Trimming") ) #$NON-NLS-1$ if self.cancelled: raise ZTemplateFetchCancelledException() # Save the 'all' variant rootXHtmlDom.save(indexAll) if self.cancelled: raise ZTemplateFetchCancelledException() # Trim the dom - remove everything except the title and body self._trimStageOne(titleElems, contentElems) rootXHtmlDom.save(indexTitleAndBody) if self.cancelled: raise ZTemplateFetchCancelledException() # Trim the dom again - remove everything except the body self._trimStageTwo(contentElems) rootXHtmlDom.save(indexBodyOnly) if self.cancelled: raise ZTemplateFetchCancelledException() self.listener.grabFeedback( _extstr( u"templategrabber.TemplateTrimmedAndSaved")) #$NON-NLS-1$ return template except Exception, e: getLoggerService().exception(e) deleteDirectory(templateDir, True) raise e
def _fetchTemplate(self, url, title, bodyStr): templateService = getApplicationModel().getService(IZBlogAppServiceIDs.TEMPLATE_SERVICE_ID) template = templateService.createTemplate() templateDir = template.getTemplateDirectory() try: webPageGetter = ZHttpWebpageGetter(url, templateDir, self) webPageGetter.setBasePathToken(IZTemplateConstants.TEMPLATE_BASE_TOKEN) rootFilePath = webPageGetter.saveAsWebpage() if self.cancelled: raise ZTemplateFetchCancelledException() rootXHtmlDoc = loadXhtmlDocumentFromFile(rootFilePath) rootXHtmlDom = rootXHtmlDoc.getDom() titleElems = self._findTitleElems(rootXHtmlDom, title) if not titleElems: return None contentElems = self._findContentElems(rootXHtmlDom, bodyStr) if not contentElems: return None indexAllUTFileName = os.path.join(templateDir, u"index-all-untrimmed.html") #$NON-NLS-1$ rootXHtmlDom.save(indexAllUTFileName) if self.cancelled: raise ZTemplateFetchCancelledException() for titleElem in titleElems: titleElem.removeAllChildren() titleMarkerElem = rootXHtmlDom.createElement(u"ravenTitle", titleElem.getNamespaceUri()) #$NON-NLS-1$ titleElem.appendChild(titleMarkerElem) for contentElem in contentElems: contentElem.removeAllChildren() contentMarkerElem = rootXHtmlDom.createElement(u"ravenBody", contentElem.getNamespaceUri()) #$NON-NLS-1$ contentElem.appendChild(contentMarkerElem) rootFile = makeRelativePath(templateDir, rootFilePath) indexAllFileName = u"index-all.html" #$NON-NLS-1$ indexBodyOnlyFileName = u"index-body.html" #$NON-NLS-1$ indexTitleAndBodyFileName = u"index-titleBody.html" #$NON-NLS-1$ template.setRootFileName(rootFile) template.setAllFileName(indexAllFileName) template.setBodyOnlyFileName(indexBodyOnlyFileName) template.setTitleAndBodyFileName(indexTitleAndBodyFileName) indexAll = os.path.join(templateDir, indexAllFileName) indexTitleAndBody = os.path.join(templateDir, indexTitleAndBodyFileName) indexBodyOnly = os.path.join(templateDir, indexBodyOnlyFileName) self.listener.grabFeedback(_extstr(u"templategrabber.TemplateDownloaded_Trimming")) #$NON-NLS-1$ if self.cancelled: raise ZTemplateFetchCancelledException() # Save the 'all' variant rootXHtmlDom.save(indexAll) if self.cancelled: raise ZTemplateFetchCancelledException() # Trim the dom - remove everything except the title and body self._trimStageOne(titleElems, contentElems) rootXHtmlDom.save(indexTitleAndBody) if self.cancelled: raise ZTemplateFetchCancelledException() # Trim the dom again - remove everything except the body self._trimStageTwo(contentElems) rootXHtmlDom.save(indexBodyOnly) if self.cancelled: raise ZTemplateFetchCancelledException() self.listener.grabFeedback(_extstr(u"templategrabber.TemplateTrimmedAndSaved")) #$NON-NLS-1$ return template except Exception, e: getLoggerService().exception(e) deleteDirectory(templateDir, True) raise e