Пример #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$
Пример #2
0
    def _load(self):
        if not self.registryFile or not os.path.exists(self.registryFile):
            return

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

        dom = ZDom()
        dom.load(self.registryFile)
        # Legacy handling - old registry file format
        for fileElem in dom.selectNodes(u"/registry/file"):  #$NON-NLS-1$
            fileName = fileElem.getText()
            size = int(fileElem.getAttribute(u"size"))  #$NON-NLS-1$
            timestamp = ZSchemaDateTime(
                fileElem.getAttribute(u"timestamp"))  #$NON-NLS-1$
            url = fileElem.getAttribute(u"url")  #$NON-NLS-1$
            self.addFile(fileName, size, timestamp, url)
        # New registry file format
        for entryElem in dom.selectNodes(u"/registry/entry"):  #$NON-NLS-1$
            size = int(entryElem.getAttribute(u"size"))  #$NON-NLS-1$
            timestamp = ZSchemaDateTime(
                entryElem.getAttribute(u"timestamp"))  #$NON-NLS-1$
            relativeFileName = entryElem.selectSingleNodeText(
                u"file")  #$NON-NLS-1$
            fileName = resolveRelativePath(mediaStorageDir, relativeFileName)
            url = entryElem.selectSingleNodeText(u"url")  #$NON-NLS-1$
            embedFragment = entryElem.selectSingleNode(
                u"embed/*")  #$NON-NLS-1$
            metaData = entryElem.selectSingleNode(u"metaData/*")  #$NON-NLS-1$
            uploadResponse = ZUploadResponse(url, embedFragment, metaData)
            self.addFileEntry(fileName, size, timestamp, uploadResponse)
Пример #3
0
 def _uploadStream(self, fileName, fileStream, metaData):  #@UnusedVariable
     albumName = self._getAlbumName()
     if not albumName:
         raise ZException(
             u"LJ Fotobilder web album name is required.")  #$NON-NLS-1$
     fotoBilderUploadResult = self._getPhotoBilderServer().uploadFile(
         fileStream, gallery=albumName)
     if fotoBilderUploadResult:
         if fotoBilderUploadResult.getUploadPicResponseNode():
             return ZUploadResponse(
                 fotoBilderUploadResult.getUrl(),
                 metaData=fotoBilderUploadResult.getUploadPicResponseNode())
         else:
             return ZUploadResponse(fotoBilderUploadResult.getUrl())
     else:
         raise ZException(u"LJ FotoBilder upload failed.")  #$NON-NLS-1$
Пример #4
0
    def _uploadStream(self, fileName, fileStream, metaData): #@UnusedVariable
        (host, path, username, password, port, urlBase, pasv) = self._getFTPSettings()

        ftp = ftplib.FTP()
        try:
            self._connect(ftp, host, port, username, password, path, pasv)
            ftp.storbinary(u"STOR " + fileName, fileStream, 4096) #$NON-NLS-1$
        finally:
            self._disconnect(ftp)

        url = urlBase.rstrip(u"/") + u"/" + fileName #$NON-NLS-1$ #$NON-NLS-2$
        return ZUploadResponse(url)
Пример #5
0
 def _uploadStream(self, fileName, fileStream, metaData):  #@UnusedVariable
     shortName = os.path.basename(fileName)
     flickr = flickrapi.FlickrAPI(FLICKR_API_KEY, SECRET)
     flickr.token_cache = ZFlickrTokenCache(self.properties)
     tags = self._getTags()
     hidden = self._getHidden()
     uploadResult = flickr.upload(fileStream,
                                  title=shortName,
                                  tags=tags,
                                  hidden=hidden)
     photoIds = uploadResult.photoid
     photoId = photoIds[0].text
     photoInfo = flickr.photos_getInfo(photo_id=photoId)
     photo = photoInfo.photo[0]
     if u"originalsecret" in photo:  #$NON-NLS-1$
         imageUrl = self._createOriginalUrl(photo)
     else:
         imageUrl = self._createUrl(photo)
     return ZUploadResponse(imageUrl)
Пример #6
0
    def _uploadStream(self, fileName, fileStream, metaData):  #@UnusedVariable
        u"""_uploadStream(string, stream, ZElement) -> IZUploadResponse
        Called to upload a file stream to the remote media storage.
        Returns the URL of the uploaded file.""" #$NON-NLS-1$

        photoEditMediaLink = self._getEditMediaLinkFromMetaData(metaData)
        self._logDebug(u"upload file %s" % fileName)  #$NON-NLS-1$
        self._logDebug(u"photoEditMediaLink is %s" %
                       photoEditMediaLink)  #$NON-NLS-1$
        photoEntry = None
        if photoEditMediaLink:
            # update existing file.
            photoEntry = self._getPicasaServer().updatePhotoFile(
                photoEditMediaLink, fileStream)
        else:
            # add new photo
            albumName = self._getAlbumName()
            self._logDebug(u"upload albumName %s" % albumName)  #$NON-NLS-1$
            if not getNoneString(albumName):
                self._logError(
                    u"Picasa web album name is required.")  #$NON-NLS-1$
                raise ZException(
                    u"Picasa web album name is required.")  #$NON-NLS-1$
            albumEntry = self._getPicasaAlbumEntry(albumName)
            if not albumEntry:
                self._logError(u"Picasa web album '%s' does not exist." %
                               albumName)  #$NON-NLS-1$
                raise ZException(u"Picasa web album '%s' does not exist." %
                                 albumName)  #$NON-NLS-1$
            photoEntry = self._getPicasaServer().addPhotoFile(
                albumEntry.getAlbumName(), fileStream)
        if not photoEntry:
            self._logError(u"Picasa web album upload failed for file %s" %
                           fileName)  #$NON-NLS-1$
            raise ZException(u"Picasa web album upload failed for file %s" %
                             fileName)  #$NON-NLS-1$

        return ZUploadResponse(photoEntry.getUrl(),
                               metaData=photoEntry.getNode())
Пример #7
0
 def _uploadStream(self, fileName, fileStream, metaData):  #@UnusedVariable
     data = {
         u"xml": u"yes",  #$NON-NLS-1$ #$NON-NLS-2$
         u"fileupload": fileStream  #$NON-NLS-1$
     }
     code = self._getRegistrationCode()
     if code:
         data[u"cookie"] = code  #$NON-NLS-1$
     imageShackUrl = u"http://www.imageshack.us/index.php"  #$NON-NLS-1$
     request = ZSimpleTextHTTPRequest(imageShackUrl)
     ok = request.send(data)
     if ok:
         respData = request.getResponse()
         dom = ZDom()
         dom.loadXML(respData)
         url = dom.selectSingleNodeText(u"/links/image_link")  #$NON-NLS-1$
         return ZUploadResponse(url)
     else:
         code = unicode(request.getHttpStatusCode())
         msg = unicode(request.getHttpStatusMessage())
         raise ZException(
             u"ImageShackMedia upload failed. HTTP response: %s %s" %
             (code, msg))  #$NON-NLS-1$
Пример #8
0
 def addFile(self, filePath, size, timestamp, url):
     self.addFileEntry(filePath, size, timestamp, ZUploadResponse(url))