Esempio n. 1
0
 def uploadFile(self, fileName, fullPath, mediaStoreListener,
                metaData):  #@UnusedVariable
     u"Called to upload a file to the remote media storage.  Returns the URL of the uploaded file."  #$NON-NLS-1$
     account = self._getAccount()
     blog = self._getBlog(account)
     publisherService = getApplicationModel().getService(
         IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
     # publisher is instance of IZBlogPublisher
     publisher = createBlogPublisherFromAccount(account, publisherService)
     # FIXME (PJ) verify publisher supports upload.
     listener = None
     if mediaStoreListener:
         listener = ZBlogServerToMediaStorageUploadListenerAdapter(
             fileName, mediaStoreListener)
     izBlogMediaServerUploadResult = publisher.uploadFile(
         blog, fullPath, fileName, listener)
     if izBlogMediaServerUploadResult:
         # convert/adapt blog server IzBlogMediaServerUploadResult to raven app IZUploadResponse
         url = izBlogMediaServerUploadResult.getUrl()
         embedNode = izBlogMediaServerUploadResult.getEmbedFragment()
         metadataNode = izBlogMediaServerUploadResult.getMetaData()
         resp = ZUploadResponse(url, embedNode, metadataNode)
         return resp
     else:
         raise ZPublisherException(u"File upload failed: %s" %
                                   fileName)  #$NON-NLS-1$
Esempio n. 2
0
    def _run(self):
        publisherService = getApplicationModel().getService(
            IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
        dataStoreService = getApplicationModel().getService(
            IZBlogAppServiceIDs.DATA_STORE_SERVICE_ID)
        publisher = None
        self.commands = []
        if self.blogs:
            for blog in self.blogs:
                account = blog.getAccount()
                publisher = createBlogPublisherFromAccount(
                    account, publisherService)
                command = ZDeleteEntryCommand(publisher, dataStoreService,
                                              account, blog, self.document,
                                              False)
                command.addListener(self)
                self.commands.append(command)
        else:
            command = ZDeleteEntryCommand(None, dataStoreService, None, None,
                                          self.document, True)
            command.addListener(self)
            self.commands.append(command)

        if self.deleteLocal and self.commands:
            self.commands[len(self.commands) - 1].setDeleteLocalEntry(True)

        # Now run all of the commands.
        for command in self.commands:
            self.currentCommand = command
            if self.isCancelled():
                return
            else:
                self.currentCommand.doCommand()
Esempio n. 3
0
    def _run(self):
        publisherService = getApplicationModel().getService(IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
        dataStoreService = getApplicationModel().getService(IZBlogAppServiceIDs.DATA_STORE_SERVICE_ID)
        publisher = None
        self.commands = []
        if self.blogs:
            for blog in self.blogs:
                account = blog.getAccount()
                publisher = createBlogPublisherFromAccount(account, publisherService)
                command = ZDeleteEntryCommand(publisher, dataStoreService, account, blog, self.document, False)
                command.addListener( self )
                self.commands.append(command)
        else:
            command = ZDeleteEntryCommand(None, dataStoreService, None, None, self.document, True)
            command.addListener( self )
            self.commands.append(command)

        if self.deleteLocal and self.commands:
            self.commands[len(self.commands) - 1].setDeleteLocalEntry(True)

        # Now run all of the commands.
        for command in self.commands:
            self.currentCommand = command
            if self.isCancelled():
                return
            else:
                self.currentCommand.doCommand()
Esempio n. 4
0
 def updateCategories(self, account, blogList, izcommandActivityListener):
     accStoreService = getApplicationModel().getService(IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
     publisherService = getApplicationModel().getService(IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
     publisher = createBlogPublisherFromAccount(account, publisherService)
     blogList = self._getFilteredAccBlogList(account, blogList)
     cmd = ZListCategoriesCommand(publisher, account, blogList)
     cmd.addListener(izcommandActivityListener)
     cmd.doCommand()
     accStoreService.saveAccount(account)
Esempio n. 5
0
    def downloadPosts(self, account, blogList, maxDocs, izcommandActivityListener):
        docIndexService = getApplicationModel().getService(IZBlogAppServiceIDs.DOCUMENT_INDEX_SERVICE_ID)
        publisherService = getApplicationModel().getService(IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
        dataStoreService = getApplicationModel().getService(IZBlogAppServiceIDs.DATA_STORE_SERVICE_ID)
        publisher = createBlogPublisherFromAccount(account, publisherService)

        blogList = self._getFilteredAccBlogList(account, blogList)
        cmd = ZDownloadEntriesCommand(dataStoreService, docIndexService, publisher, account, blogList, maxDocs)
        cmd.addListener(izcommandActivityListener)
        cmd.doCommand()
Esempio n. 6
0
 def createMediaStorages(self, account, izcommandActivityListener):
     accStoreService = getApplicationModel().getService(IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
     publisherService = getApplicationModel().getService(IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
     mediaStoreService = getApplicationModel().getService(IZBlogAppServiceIDs.MEDIA_STORAGE_SERVICE_ID)
     # create publisher
     publisher = createBlogPublisherFromAccount(account, publisherService)
     cmd = ZCreateOrUpdateBlogMediaStoragesCommand(publisher, mediaStoreService, account)
     cmd.addListener(izcommandActivityListener)
     cmd.doCommand()
     accStoreService.saveAccount(account)
Esempio n. 7
0
 def updateCategories(self, account, blogList, izcommandActivityListener):
     accStoreService = getApplicationModel().getService(
         IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
     publisherService = getApplicationModel().getService(
         IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
     publisher = createBlogPublisherFromAccount(account, publisherService)
     blogList = self._getFilteredAccBlogList(account, blogList)
     cmd = ZListCategoriesCommand(publisher, account, blogList)
     cmd.addListener(izcommandActivityListener)
     cmd.doCommand()
     accStoreService.saveAccount(account)
Esempio n. 8
0
 def _createCommand(self, account, blog, pubMetaData):
     publisherService = getApplicationModel().getService(IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
     dataStoreService = getApplicationModel().getService(IZBlogAppServiceIDs.DATA_STORE_SERVICE_ID)
     publisher = createBlogPublisherFromAccount(account, publisherService)
     # create update or publish command and execute
     command = None
     if self.document.isPublishedToBlog( blog.getId() ):
         command = ZUpdateEntryCommand(publisher, dataStoreService, account, blog, self.document, pubMetaData)
     else:
         command = ZPublishEntryCommand(publisher, dataStoreService, account, blog, self.document, pubMetaData)
     return command
Esempio n. 9
0
    def updateBlogList(self, account, selectedBlogList, izcommandActivityListener): #@UnusedVariable
        accStoreService = getApplicationModel().getService(IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
        publisherService = getApplicationModel().getService(IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
        # create publisher
        publisher = createBlogPublisherFromAccount(account, publisherService)

        # update account's blog list from server
        cmd = ZListBlogsCommand(publisher, account, selectedBlogList)
        cmd.addListener(izcommandActivityListener)
        cmd.listBlogs();
        # save account with the new blog lists.
        accStoreService.saveAccount(account)
Esempio n. 10
0
 def createMediaStorages(self, account, izcommandActivityListener):
     accStoreService = getApplicationModel().getService(
         IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
     publisherService = getApplicationModel().getService(
         IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
     mediaStoreService = getApplicationModel().getService(
         IZBlogAppServiceIDs.MEDIA_STORAGE_SERVICE_ID)
     # create publisher
     publisher = createBlogPublisherFromAccount(account, publisherService)
     cmd = ZCreateOrUpdateBlogMediaStoragesCommand(publisher,
                                                   mediaStoreService,
                                                   account)
     cmd.addListener(izcommandActivityListener)
     cmd.doCommand()
     accStoreService.saveAccount(account)
Esempio n. 11
0
    def downloadPosts(self, account, blogList, maxDocs,
                      izcommandActivityListener):
        docIndexService = getApplicationModel().getService(
            IZBlogAppServiceIDs.DOCUMENT_INDEX_SERVICE_ID)
        publisherService = getApplicationModel().getService(
            IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
        dataStoreService = getApplicationModel().getService(
            IZBlogAppServiceIDs.DATA_STORE_SERVICE_ID)
        publisher = createBlogPublisherFromAccount(account, publisherService)

        blogList = self._getFilteredAccBlogList(account, blogList)
        cmd = ZDownloadEntriesCommand(dataStoreService, docIndexService,
                                      publisher, account, blogList, maxDocs)
        cmd.addListener(izcommandActivityListener)
        cmd.doCommand()
Esempio n. 12
0
    def updateBlogList(self, account, selectedBlogList,
                       izcommandActivityListener):  #@UnusedVariable
        accStoreService = getApplicationModel().getService(
            IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
        publisherService = getApplicationModel().getService(
            IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
        # create publisher
        publisher = createBlogPublisherFromAccount(account, publisherService)

        # update account's blog list from server
        cmd = ZListBlogsCommand(publisher, account, selectedBlogList)
        cmd.addListener(izcommandActivityListener)
        cmd.listBlogs()
        # save account with the new blog lists.
        accStoreService.saveAccount(account)
Esempio n. 13
0
 def listAllBlogs(self):
     # return list of account blogs - both local and online
     publisher = createBlogPublisherFromAccount(self.account, self.publisherService)
     onlineBlogs = publisher.listBlogs()
     rval = []
     rval.extend(self.account.getBlogs())
     for blog in onlineBlogs:
         add = True
         for temp in self.account.getBlogs():
             if temp.getId() == blog.getId():
                 #  blog exists locally with in the account.
                 add = False
                 break
         if add:
             rval.append(blog)                
     return rval
Esempio n. 14
0
 def _createCommand(self, account, blog, pubMetaData):
     publisherService = getApplicationModel().getService(
         IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
     dataStoreService = getApplicationModel().getService(
         IZBlogAppServiceIDs.DATA_STORE_SERVICE_ID)
     publisher = createBlogPublisherFromAccount(account, publisherService)
     # create update or publish command and execute
     command = None
     if self.document.isPublishedToBlog(blog.getId()):
         command = ZUpdateEntryCommand(publisher, dataStoreService, account,
                                       blog, self.document, pubMetaData)
     else:
         command = ZPublishEntryCommand(publisher, dataStoreService,
                                        account, blog, self.document,
                                        pubMetaData)
     return command
Esempio n. 15
0
 def listAllBlogs(self):
     # return list of account blogs - both local and online
     publisher = createBlogPublisherFromAccount(self.account,
                                                self.publisherService)
     onlineBlogs = publisher.listBlogs()
     rval = []
     rval.extend(self.account.getBlogs())
     for blog in onlineBlogs:
         add = True
         for temp in self.account.getBlogs():
             if temp.getId() == blog.getId():
                 #  blog exists locally with in the account.
                 add = False
                 break
         if add:
             rval.append(blog)
     return rval
Esempio n. 16
0
 def uploadFile(self, fileName, fullPath, mediaStoreListener, metaData): #@UnusedVariable
     u"Called to upload a file to the remote media storage.  Returns the URL of the uploaded file." #$NON-NLS-1$
     account = self._getAccount()
     blog = self._getBlog(account)
     publisherService = getApplicationModel().getService(IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
     # publisher is instance of IZBlogPublisher
     publisher = createBlogPublisherFromAccount(account,publisherService)
     # FIXME (PJ) verify publisher supports upload.
     listener = None
     if mediaStoreListener:
         listener = ZBlogServerToMediaStorageUploadListenerAdapter(fileName, mediaStoreListener)
     izBlogMediaServerUploadResult = publisher.uploadFile(blog, fullPath, fileName, listener)
     if izBlogMediaServerUploadResult:
         # convert/adapt blog server IzBlogMediaServerUploadResult to raven app IZUploadResponse
         url =  izBlogMediaServerUploadResult.getUrl()
         embedNode = izBlogMediaServerUploadResult.getEmbedFragment()
         metadataNode = izBlogMediaServerUploadResult.getMetaData()
         resp = ZUploadResponse(url, embedNode, metadataNode)
         return resp
     else:
         raise ZPublisherException(u"File upload failed: %s" % fileName) #$NON-NLS-1$
Esempio n. 17
0
 def _getPublisher(self):
     publisherService = getApplicationModel().getService(
         IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
     return createBlogPublisherFromAccount(self._getAccount(),
                                           publisherService)
Esempio n. 18
0
 def _getPublisher(self):
     publisherService = getApplicationModel().getService(IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
     return createBlogPublisherFromAccount(self._getAccount(), publisherService)
Esempio n. 19
0
    def _doGrab(self):
        account = self.blog.getAccount()
        pubService = getApplicationModel().getService(IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
        publisher = createBlogPublisherFromAccount(account, pubService)

        if self.cancelled:
            return None

        self.listener.grabFeedback(_extstr(u"templategrabber.ConnectingToFeed")) #$NON-NLS-1$

        template = None
        documents = publisher.listEntries(self.blog, 5)

        if self.cancelled:
            return None

        self.listener.grabBlogPostAnalysisStarted()
        if len(documents) == 0:
            raise ZException(_extstr(u"templategrabber.BlogHasNoPosts")) #$NON-NLS-1$
        for document in documents:
            if self.cancelled:
                return None
            self.listener.grabFeedback(_extstr(u"templategrabber.AnalysingFrom") % getSafeString(document.getTitle())) #$NON-NLS-1$
            title = document.getTitle()
            content = document.getContent()
            xhtml = content.getXhtmlDocument()
            body = xhtml.getBody()
            bodyStr = getSafeString(body.selectRaw(u"string(.)")) #$NON-NLS-1$
            bodyStr = string.strip(bodyStr)

            if not title or not bodyStr:
                continue

            url = self._getDocumentUrl(document)
            altHtmlDoc = self._downloadAltHtml(url)

            altHtmlDom = altHtmlDoc.getDom()
            if altHtmlDom is None:
                continue

            self.listener.grabFeedback(_extstr(u"templategrabber.FindingBlogPostTitle")) #$NON-NLS-1$
            titleElems = self._findTitleElems(altHtmlDom, title)
            if not titleElems:
                continue

            self.listener.grabFeedback(_extstr(u"templategrabber.FindingBlogPostContent")) #$NON-NLS-1$
            contentElems = self._findContentElems(altHtmlDom, bodyStr)
            if not contentElems:
                continue

            self.listener.grabFeedback(_extstr(u"templategrabber.BlogContentAnalysed")) #$NON-NLS-1$

            if self.cancelled:
                return None

            template = self._fetchTemplate(url, title, bodyStr)
            if template is not None:
                break
        # end foreach

        self.listener.grabBlogPostAnalysisComplete()

        if template is None:
            raise ZException(_extstr(u"templategrabber.UnableToDetectTemplate")) #$NON-NLS-1$

        return template
Esempio n. 20
0
    def _doGrab(self):
        account = self.blog.getAccount()
        pubService = getApplicationModel().getService(
            IZBlogAppServiceIDs.PUBLISHING_SERVICE_ID)
        publisher = createBlogPublisherFromAccount(account, pubService)

        if self.cancelled:
            return None

        self.listener.grabFeedback(
            _extstr(u"templategrabber.ConnectingToFeed"))  #$NON-NLS-1$

        template = None
        documents = publisher.listEntries(self.blog, 5)

        if self.cancelled:
            return None

        self.listener.grabBlogPostAnalysisStarted()
        if len(documents) == 0:
            raise ZException(
                _extstr(u"templategrabber.BlogHasNoPosts"))  #$NON-NLS-1$
        for document in documents:
            if self.cancelled:
                return None
            self.listener.grabFeedback(
                _extstr(u"templategrabber.AnalysingFrom") %
                getSafeString(document.getTitle()))  #$NON-NLS-1$
            title = document.getTitle()
            content = document.getContent()
            xhtml = content.getXhtmlDocument()
            body = xhtml.getBody()
            bodyStr = getSafeString(body.selectRaw(u"string(.)"))  #$NON-NLS-1$
            bodyStr = string.strip(bodyStr)

            if not title or not bodyStr:
                continue

            url = self._getDocumentUrl(document)
            altHtmlDoc = self._downloadAltHtml(url)

            altHtmlDom = altHtmlDoc.getDom()
            if altHtmlDom is None:
                continue

            self.listener.grabFeedback(
                _extstr(u"templategrabber.FindingBlogPostTitle"))  #$NON-NLS-1$
            titleElems = self._findTitleElems(altHtmlDom, title)
            if not titleElems:
                continue

            self.listener.grabFeedback(
                _extstr(
                    u"templategrabber.FindingBlogPostContent"))  #$NON-NLS-1$
            contentElems = self._findContentElems(altHtmlDom, bodyStr)
            if not contentElems:
                continue

            self.listener.grabFeedback(
                _extstr(u"templategrabber.BlogContentAnalysed"))  #$NON-NLS-1$

            if self.cancelled:
                return None

            template = self._fetchTemplate(url, title, bodyStr)
            if template is not None:
                break
        # end foreach

        self.listener.grabBlogPostAnalysisComplete()

        if template is None:
            raise ZException(_extstr(
                u"templategrabber.UnableToDetectTemplate"))  #$NON-NLS-1$

        return template