Esempio n. 1
0
 def _convertUrl(self, url):
     decodedFilePath = decodeUri(url)
     relativePath = makeRelativePath(self.dataDir, decodedFilePath)
     if relativePath != decodedFilePath:
         return u"%s/%s" % (IZDocumentSerializationConstants.
                            RAVEN_BLOG_DOCUMENT_PATH_TOKEN, relativePath
                            )  #$NON-NLS-1$
Esempio n. 2
0
 def _fixupHrefs(self, fileName, hrefs):
     content = self._loadFileContent(fileName)
     if content:
         for href in hrefs:
             newHref = None
             filePath = self.resourceMap[href]
             if self.basePathToken is not None:
                 relativeFilePath = makeRelativePath(self.outputDir, filePath)
                 newHref = (
                     u"file://" + self.basePathToken + u"/" + relativeFilePath.replace(u"\\", u"/")
                 )  # $NON-NLS-1$ #$NON-NLS-2$ #$NON-NLS-3$ #$NON-NLS-4$
             else:
                 newHref = u"file://" + filePath.replace(u"\\", u"/")  # $NON-NLS-1$ #$NON-NLS-2$ #$NON-NLS-3$
             content = content.replace(href, newHref)
     self._saveFileContent(fileName, content)
Esempio n. 3
0
    def _save(self):
        if not self.registryFile:
            return

        mediaStorageDir = os.path.basename(self.registryFile)

        dom = ZDom()
        dom.loadXML(u"<registry/>")  #$NON-NLS-1$
        registryElem = dom.documentElement
        for fileName in self.fileMap:
            (size, timestamp, uploadResponse) = self.fileMap[fileName]
            relativeFileName = makeRelativePath(mediaStorageDir, fileName)
            url = uploadResponse.getUrl()
            embedFragment = uploadResponse.getEmbedFragment()
            metaData = uploadResponse.getMetaData()

            entryElem = dom.createElement(u"entry")  #$NON-NLS-1$
            entryElem.setAttribute(u"size", unicode(size))  #$NON-NLS-1$
            entryElem.setAttribute(u"timestamp",
                                   unicode(timestamp))  #$NON-NLS-1$

            fileElem = dom.createElement(u"file")  #$NON-NLS-1$
            urlElem = dom.createElement(u"url")  #$NON-NLS-1$
            embedElem = dom.createElement(u"embed")  #$NON-NLS-1$
            metaDataElem = dom.createElement(u"metaData")  #$NON-NLS-1$

            # When in portable mode, save the file paths as relative (which will
            # only happen when the image is on the same drive as the app).
            if isPortableEnabled():
                fileElem.setText(relativeFileName)
            else:
                fileElem.setText(fileName)

            entryElem.appendChild(fileElem)
            if url:
                urlElem.setText(unicode(url))
            entryElem.appendChild(urlElem)
            if embedFragment is not None:
                embedElem.appendChild(dom.importNode(embedFragment, True))
            entryElem.appendChild(embedElem)
            if metaData is not None:
                metaDataElem.appendChild(dom.importNode(metaData, True))
            entryElem.appendChild(metaDataElem)

            registryElem.appendChild(entryElem)

        dom.save(self.registryFile, True)
Esempio n. 4
0
 def _fixupHrefs(self, fileName, hrefs):
     content = self._loadFileContent(fileName)
     if content:
         for href in hrefs:
             newHref = None
             filePath = self.resourceMap[href]
             if self.basePathToken is not None:
                 relativeFilePath = makeRelativePath(
                     self.outputDir, filePath)
                 newHref = u"file://" + self.basePathToken + u"/" + relativeFilePath.replace(
                     u"\\", u"/"
                 )  #$NON-NLS-1$ #$NON-NLS-2$ #$NON-NLS-3$ #$NON-NLS-4$
             else:
                 newHref = u"file://" + filePath.replace(
                     u"\\", u"/")  #$NON-NLS-1$ #$NON-NLS-2$ #$NON-NLS-3$
             content = content.replace(href, newHref)
     self._saveFileContent(fileName, content)
Esempio n. 5
0
    def _save(self):
        if not self.registryFile:
            return

        mediaStorageDir = os.path.basename(self.registryFile)

        dom = ZDom()
        dom.loadXML(u"<registry/>") #$NON-NLS-1$
        registryElem = dom.documentElement
        for fileName in self.fileMap:
            (size, timestamp, uploadResponse) = self.fileMap[fileName]
            relativeFileName = makeRelativePath(mediaStorageDir, fileName)
            url = uploadResponse.getUrl()
            embedFragment = uploadResponse.getEmbedFragment()
            metaData = uploadResponse.getMetaData()

            entryElem = dom.createElement(u"entry") #$NON-NLS-1$
            entryElem.setAttribute(u"size", unicode(size)) #$NON-NLS-1$
            entryElem.setAttribute(u"timestamp", unicode(timestamp)) #$NON-NLS-1$

            fileElem = dom.createElement(u"file") #$NON-NLS-1$
            urlElem = dom.createElement(u"url") #$NON-NLS-1$
            embedElem = dom.createElement(u"embed") #$NON-NLS-1$
            metaDataElem = dom.createElement(u"metaData") #$NON-NLS-1$

            # When in portable mode, save the file paths as relative (which will
            # only happen when the image is on the same drive as the app).
            if isPortableEnabled():
                fileElem.setText(relativeFileName)
            else:
                fileElem.setText(fileName)

            entryElem.appendChild(fileElem)
            if url:
                urlElem.setText(unicode(url))
            entryElem.appendChild(urlElem)
            if embedFragment is not None:
                embedElem.appendChild(dom.importNode(embedFragment, True))
            entryElem.appendChild(embedElem)
            if metaData is not None:
                metaDataElem.appendChild(dom.importNode(metaData, True))
            entryElem.appendChild(metaDataElem)

            registryElem.appendChild(entryElem)

        dom.save(self.registryFile, True)
Esempio n. 6
0
    def createProfile(self, profileInfo):
        (name, path) = profileInfo
        fullPath = path

        # if running in portable mode, the path needs to be stored
        # relative to the profiles.xml file.
        if isPortableEnabled():
            profileDirPath = self.getDefaultProfilesDirectory()
            path = makeRelativePath(profileDirPath, fullPath)

        # Check if we have one with the same name already.
        if self.getProfile(name) is not None:
            raise ZBlogAppException(_extstr(u"manager.ProfileAlreadyExists") % name) #$NON-NLS-1$

        profileElem = self.profilesDom.createElement(u"profile") #$NON-NLS-1$
        profileElem.setAttribute(u"name", name) #$NON-NLS-1$
        profileElem.setText(path)
        self.profilesDom.documentElement.appendChild(profileElem)
        self._saveProfilesDom()

        if not os.path.exists(fullPath):
            os.makedirs(fullPath)
Esempio n. 7
0
    def createProfile(self, profileInfo):
        (name, path) = profileInfo
        fullPath = path

        # if running in portable mode, the path needs to be stored
        # relative to the profiles.xml file.
        if isPortableEnabled():
            profileDirPath = self.getDefaultProfilesDirectory()
            path = makeRelativePath(profileDirPath, fullPath)

        # Check if we have one with the same name already.
        if self.getProfile(name) is not None:
            raise ZBlogAppException(
                _extstr(u"manager.ProfileAlreadyExists") % name)  #$NON-NLS-1$

        profileElem = self.profilesDom.createElement(u"profile")  #$NON-NLS-1$
        profileElem.setAttribute(u"name", name)  #$NON-NLS-1$
        profileElem.setText(path)
        self.profilesDom.documentElement.appendChild(profileElem)
        self._saveProfilesDom()

        if not os.path.exists(fullPath):
            os.makedirs(fullPath)
Esempio n. 8
0
    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
Esempio n. 9
0
 def _downloadTemplate(self, permaLink, template):
     templateDir = template.getTemplateDirectory()
     webPageGetter = ZHttpWebpageGetter(permaLink, templateDir, self)
     rootFilePath = webPageGetter.saveAsWebpage()
     rootFile = makeRelativePath(templateDir, rootFilePath)
     template.setRootFileName(rootFile)
Esempio n. 10
0
 def _convertUrl(self, url):
     decodedFilePath = decodeUri(url)
     relativePath = makeRelativePath(self.dataDir, decodedFilePath)
     if relativePath != decodedFilePath:
         return u"%s/%s" % (IZDocumentSerializationConstants.RAVEN_BLOG_DOCUMENT_PATH_TOKEN, relativePath) #$NON-NLS-1$
Esempio n. 11
0
    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
Esempio n. 12
0
 def _downloadTemplate(self, permaLink, template):
     templateDir = template.getTemplateDirectory()
     webPageGetter = ZHttpWebpageGetter(permaLink, templateDir, self)
     rootFilePath = webPageGetter.saveAsWebpage()
     rootFile = makeRelativePath(templateDir, rootFilePath)
     template.setRootFileName(rootFile)