def copyFile(sourcePath, destinationPath, zstreamWrapperListener = None): if not os.path.isfile(sourcePath): return if not zstreamWrapperListener: shutil.copy2(sourcePath, destinationPath) else: # # equivalent code of shutil.copy2() except uses ZStreamWrapper # if os.path.isdir(destinationPath): destinationPath = os.path.join(destinationPath, os.path.basename(sourcePath)) if shutil._samefile(sourcePath, destinationPath): raise Error, u"`%s` and `%s` are the same file" % (sourcePath, destinationPath) #$NON-NLS-1$ srcwrapper = None fdst = None try: fsrc = open(sourcePath, u'rb') #$NON-NLS-1$ srcwrapper = ZStreamWrapper(fsrc, zstreamWrapperListener) fdst = open(destinationPath, u'wb') #$NON-NLS-1$ shutil.copyfileobj(srcwrapper, fdst) finally: if fdst: fdst.close() if srcwrapper: srcwrapper.close() shutil.copystat(sourcePath, destinationPath)
def copyFile(sourcePath, destinationPath, zstreamWrapperListener=None): if not os.path.isfile(sourcePath): return if not zstreamWrapperListener: shutil.copy2(sourcePath, destinationPath) else: # # equivalent code of shutil.copy2() except uses ZStreamWrapper # if os.path.isdir(destinationPath): destinationPath = os.path.join(destinationPath, os.path.basename(sourcePath)) if shutil._samefile(sourcePath, destinationPath): raise Error, u"`%s` and `%s` are the same file" % ( sourcePath, destinationPath) #$NON-NLS-1$ srcwrapper = None fdst = None try: fsrc = open(sourcePath, u'rb') #$NON-NLS-1$ srcwrapper = ZStreamWrapper(fsrc, zstreamWrapperListener) fdst = open(destinationPath, u'wb') #$NON-NLS-1$ shutil.copyfileobj(srcwrapper, fdst) finally: if fdst: fdst.close() if srcwrapper: srcwrapper.close() shutil.copystat(sourcePath, destinationPath)
def uploadFile(self, fileName, fullPath, listener, metaData): u"""Implements the method to adapt the file to a stream and delegate to _uploadStream(filename, fileStream) method. """ #$NON-NLS-1$ try: file = open(fullPath, u"rb") #$NON-NLS-1$ stream = ZStreamWrapper(file, ZStreamToUploadListenerAdapter(listener, fileName)) try: return self._uploadStream(fileName, stream, metaData) finally: stream.close() except Exception, e: # FIXME (PJ) used key prefix mediastorageprovider raise ZBlogAppException(_extstr(u"mediastorageimpl.FailedToUploadFile") % fileName, e) #$NON-NLS-1$
def uploadFile(self, fileName, fullPath, listener, metaData): u"""Implements the method to adapt the file to a stream and delegate to _uploadStream(filename, fileStream) method. """ #$NON-NLS-1$ try: file = open(fullPath, u"rb") #$NON-NLS-1$ stream = ZStreamWrapper( file, ZStreamToUploadListenerAdapter(listener, fileName)) try: return self._uploadStream(fileName, stream, metaData) finally: stream.close() except Exception, e: # FIXME (PJ) used key prefix mediastorageprovider raise ZBlogAppException( _extstr(u"mediastorageimpl.FailedToUploadFile") % fileName, e) #$NON-NLS-1$