def _copyNonPortableFile(self, resourceStore, zxhtmlPortablePathElementInfo, fileNumber, totalFiles): #@UnusedVariable srcPath = zxhtmlPortablePathElementInfo.getPath() (name, path, fsize, schemadt) = getFileMetaData( srcPath ) #@UnusedVariable self.currFileCopiedBytes = 0 self.currFileTotalBytes = fsize progress = u"%d/%d %s" % (fileNumber, totalFiles, name) #$NON-NLS-1$ self.currProgressText = _extstr(u"blogeditor.CopyNonPortableFilesProgressAction") % progress #$NON-NLS-1$ self._fireWorkDoneEvent(1, self.currProgressText) #$NON-NLS-1$ # check if already uploaded (i.e. duplicate entries e.g. second <img> pointing to same image) if self.copiedContent.has_key(srcPath): (dstPath, fsize) = self.copiedContent[srcPath] zxhtmlPortablePathElementInfo.setPath( dstPath ) # call back for progress meter self.streamRead(fsize, None) else: try: self.logger.debug(u"Copying non-portable path %s " % srcPath ) #$NON-NLS-1$ resEntry = resourceStore.addResource( srcPath, self ) if resEntry: zxhtmlPortablePathElementInfo.setPath( resEntry.getFilePath() ) self.copiedContent[srcPath] = (resEntry.getFilePath(), fsize) else: self.logger.debug(u"Failed to copy non-portable path %s " % zxhtmlPortablePathElementInfo.getPath() ) #$NON-NLS-1$ except Exception, e: self.logger.exception(e)
def delete(self, fileName): (shortName, filePath, size, timestamp) = getFileMetaData(fileName) if not self.registry.hasFile(filePath, size, timestamp): return self.provider.deleteFile(shortName, self.registry.getMetaData(filePath)) self.registry.removeFile(filePath)
def _validatePlugin(self, plugin, validPlugins): doQuickValidation = False userPluginsDir = self.userProfile.getDirectory(u"plugins") #$NON-NLS-1$ pluginValidatedFilePath = os.path.join(userPluginsDir, plugin.getId() + u".xml") #$NON-NLS-1$ pluginXMLFilePath = os.path.join(plugin.getPluginDirectory(), u"zplugin.xml") #$NON-NLS-1$ if os.path.isfile(pluginValidatedFilePath): pluginValidatedTimestamp = getFileMetaData(pluginValidatedFilePath)[3] pluginXMLTimestamp = getFileMetaData(pluginXMLFilePath)[3] doQuickValidation = pluginXMLTimestamp < pluginValidatedTimestamp if doQuickValidation: plugin.quickValidate(validPlugins) else: schemaXML = self._loadPluginSchemaXML() plugin.validate(schemaXML, validPlugins, self.extensionDefs) ZDom(u"""<validated timestamp="%s" />""" % unicode(ZSchemaDateTime())).save(pluginValidatedFilePath) #$NON-NLS-1$
def _createNewFileEntryInfo(self, filePath): (name, path, fsize, schemadt) = getFileMetaData(filePath) #@UnusedVariable resId = self._createResourceId(name) storeEntryPath = self._getStorePath(resId) entry = ZResourceStoreEntry(resId, storeEntryPath) entry.setAttribute(u"name", name) #$NON-NLS-1$ entry.setAttribute(u"size", unicode(fsize)) #$NON-NLS-1$ entry.setAttribute(u"timestamp", unicode(schemadt)) #$NON-NLS-1$ entry.setAttribute(u"source-path", os.path.abspath(filePath)) #$NON-NLS-1$ entry.setAttribute(u"source-type", IZResourceStoreEntry.SOURCE_TYPE_FILE) #$NON-NLS-1$ try: entryStat = os.stat(filePath) entry.setAttribute(u"source-st-dev", unicode(entryStat[stat.ST_DEV])) #$NON-NLS-1$ entry.setAttribute(u"source-st-size", unicode(entryStat[stat.ST_SIZE])) #$NON-NLS-1$ entry.setAttribute(u"source-st-mtime", unicode(entryStat[stat.ST_MTIME])) #$NON-NLS-1$ entry.setAttribute(u"source-st-ctime", unicode(entryStat[stat.ST_CTIME])) #$NON-NLS-1$ except: raise self._populateEntryPlatformMetaData(entry) return entry
def __init__(self, mediaFile, izMediaUploadListener): self.mediaUploadListener = izMediaUploadListener (shortName, filePath, size, timestamp) = getFileMetaData(mediaFile) #@UnusedVariable self.encTotal = size self.encStarted = False self.currTotalEnc = 0 self.transferTotal = 0 self.currTotalTranfered = 0 self.sessionStarted = False
def __init__(self, mediaFile, izMediaUploadListener): self.mediaUploadListener = izMediaUploadListener (shortName, filePath, size, timestamp) = getFileMetaData(mediaFile) #@UnusedVariable self.encTotal = size self.encStarted = False self.currTotalEnc = 0 self.transferTotal = 0 self.currTotalTranfered = 0 self.sessionStarted = False
def tempFileFilter(filePath): if os.path.isfile(filePath): (shortFileName, absolutePath, fileSize, timeStamp) = getFileMetaData(filePath) #@UnusedVariable today = ZSchemaDateTime() today.setHour(0) today.setMinutes(0) today.setSeconds(0) return timeStamp < today else: return False
def _createProperties(self): userPropsFilename = self._getNamedFile(u"config", u"user-properties.xml") #$NON-NLS-2$ #$NON-NLS-1$ if not os.path.isfile(userPropsFilename): self._writeEmptyUserPropertiesFile(userPropsFilename) metaData = getFileMetaData(userPropsFilename) # If the file size is 0, write out an empty one (defect 596) if metaData[2] == 0: self._writeEmptyUserPropertiesFile(userPropsFilename) return ZSystemProperties(userPropsFilename)
def _createProperties(self): userPropsFilename = self._getNamedFile( u"config", u"user-properties.xml") #$NON-NLS-2$ #$NON-NLS-1$ if not os.path.isfile(userPropsFilename): self._writeEmptyUserPropertiesFile(userPropsFilename) metaData = getFileMetaData(userPropsFilename) # If the file size is 0, write out an empty one (defect 596) if metaData[2] == 0: self._writeEmptyUserPropertiesFile(userPropsFilename) return ZSystemProperties(userPropsFilename)
def tempFileFilter(filePath): if os.path.isfile(filePath): (shortFileName, absolutePath, fileSize, timeStamp) = getFileMetaData(filePath) #@UnusedVariable today = ZSchemaDateTime() today.setHour(0) today.setMinutes(0) today.setSeconds(0) return timeStamp < today else: return False
def _createNewUrlEntryInfo(self, url, downloadFilePath): (name, path, fsize, schemadt) = getFileMetaData(downloadFilePath) #@UnusedVariable # FIXME (PJ) create name from url filename resId = self._createResourceId(name) storeEntryPath = self._getStorePath(resId) entry = ZResourceStoreEntry(resId, storeEntryPath) entry.setAttribute(u"name", name) #$NON-NLS-1$ entry.setAttribute(u"size", unicode(fsize)) #$NON-NLS-1$ entry.setAttribute(u"timestamp", unicode(schemadt)) #$NON-NLS-1$ entry.setAttribute(u"source-path", url) #$NON-NLS-1$ entry.setAttribute(u"source-type", IZResourceStoreEntry.SOURCE_TYPE_URL) #$NON-NLS-1$ self._populateEntryPlatformMetaData(entry) return entry
def _validatePlugin(self, plugin, validPlugins): doQuickValidation = False userPluginsDir = self.userProfile.getDirectory( u"plugins") #$NON-NLS-1$ pluginValidatedFilePath = os.path.join(userPluginsDir, plugin.getId() + u".xml") #$NON-NLS-1$ pluginXMLFilePath = os.path.join(plugin.getPluginDirectory(), u"zplugin.xml") #$NON-NLS-1$ if os.path.isfile(pluginValidatedFilePath): pluginValidatedTimestamp = getFileMetaData( pluginValidatedFilePath)[3] pluginXMLTimestamp = getFileMetaData(pluginXMLFilePath)[3] doQuickValidation = pluginXMLTimestamp < pluginValidatedTimestamp if doQuickValidation: plugin.quickValidate(validPlugins) else: schemaXML = self._loadPluginSchemaXML() plugin.validate(schemaXML, validPlugins, self.extensionDefs) ZDom(u"""<validated timestamp="%s" />""" % unicode(ZSchemaDateTime())).save( pluginValidatedFilePath) #$NON-NLS-1$
def _createNewUrlEntryInfo(self, url, downloadFilePath): (name, path, fsize, schemadt) = getFileMetaData(downloadFilePath) #@UnusedVariable # FIXME (PJ) create name from url filename resId = self._createResourceId(name) storeEntryPath = self._getStorePath(resId) entry = ZResourceStoreEntry(resId, storeEntryPath) entry.setAttribute(u"name", name) #$NON-NLS-1$ entry.setAttribute(u"size", unicode(fsize)) #$NON-NLS-1$ entry.setAttribute(u"timestamp", unicode(schemadt)) #$NON-NLS-1$ entry.setAttribute(u"source-path", url) #$NON-NLS-1$ entry.setAttribute(u"source-type", IZResourceStoreEntry.SOURCE_TYPE_URL) #$NON-NLS-1$ self._populateEntryPlatformMetaData(entry) return entry
def _getFileMetaData(self, fileName): u"""Returns (url, shortName, absPath, size, schemaDate).""" #$NON-NLS-1$ url = None shortName = None absPath = None size = None schemaDate = None try: (shortName, absPath, size, schemaDate) = getFileMetaData(fileName) #@UnusedVariable if shortName: shortName = convertToUnicode(shortName) url = getUriFromFilePath(absPath) except: pass return (url, shortName, absPath, size, schemaDate)
def _getFileMetaData(self, fileName): u"""Returns (url, shortName, absPath, size, schemaDate).""" #$NON-NLS-1$ url = None shortName = None absPath = None size = None schemaDate = None try: (shortName, absPath, size, schemaDate) = getFileMetaData(fileName) #@UnusedVariable if shortName: shortName = convertToUnicode(shortName) url = getUriFromFilePath(absPath) except: pass return (url, shortName, absPath, size, schemaDate)
def insertImageFile(self, parentWindow, imageContext): u"""insertImageFile(wxWindow, IZXHTMLEditControlImageContext) -> void Shows the File open dialog to display an image. """ #$NON-NLS-1$ file = None wildcard = u"Image files|*.gif;*.jpg;*.png;*.jpeg" #$NON-NLS-1$ dialog = wx.FileDialog(parentWindow, u"Choose an image file.", u"", u"", wildcard, wx.OPEN) #$NON-NLS-4$ #$NON-NLS-3$ #$NON-NLS-2$ #$NON-NLS-1$ if dialog.ShowModal() == wx.ID_OK: file = getNoneString(dialog.GetPath()) dialog.Destroy() if file: (shortName, absPath, size, schemaDate) = getFileMetaData(file) #@UnusedVariable if shortName: shortName = convertToUnicode(shortName) else: shortName = u"" #$NON-NLS-1$ url = getUriFromFilePath(absPath) attrs = { u"src" : url, u"alt" : shortName} #$NON-NLS-1$ #$NON-NLS-2$ imageContext.insertImage(attrs)
def _createNewFileEntryInfo(self, filePath): (name, path, fsize, schemadt) = getFileMetaData(filePath) #@UnusedVariable resId = self._createResourceId(name) storeEntryPath = self._getStorePath(resId) entry = ZResourceStoreEntry(resId, storeEntryPath) entry.setAttribute(u"name", name) #$NON-NLS-1$ entry.setAttribute(u"size", unicode(fsize)) #$NON-NLS-1$ entry.setAttribute(u"timestamp", unicode(schemadt)) #$NON-NLS-1$ entry.setAttribute(u"source-path", os.path.abspath(filePath)) #$NON-NLS-1$ entry.setAttribute(u"source-type", IZResourceStoreEntry.SOURCE_TYPE_FILE) #$NON-NLS-1$ try: entryStat = os.stat(filePath) entry.setAttribute(u"source-st-dev", unicode(entryStat[stat.ST_DEV]) ) #$NON-NLS-1$ entry.setAttribute(u"source-st-size", unicode(entryStat[stat.ST_SIZE]) ) #$NON-NLS-1$ entry.setAttribute(u"source-st-mtime", unicode(entryStat[stat.ST_MTIME]) ) #$NON-NLS-1$ entry.setAttribute(u"source-st-ctime", unicode(entryStat[stat.ST_CTIME]) ) #$NON-NLS-1$ except: raise self._populateEntryPlatformMetaData(entry) return entry
def addResource(self, filePath, zstreamWrapperListener = None): #@UnusedVariable # if url, then get shortname from url or create shortname if not filePath or not os.path.isfile(filePath): return None # check if this resource is already in the store filePath = os.path.abspath(filePath) if filePath.startswith( self.storeDir ): (name, path, fsize, schemadt) = getFileMetaData(filePath) #@UnusedVariable resourceStoreEntryPath = self._getStorePath(name) metaStoreEntryPath = self._getStorePath(self._getMetaFileId(name)) # resource and meta xml file aready exists in store if os.path.isfile(resourceStoreEntryPath) and os.path.isfile(metaStoreEntryPath): return self.getResource(name) entry = self._createNewFileEntryInfo(filePath) copyFile(filePath, entry.getFilePath(), zstreamWrapperListener) self._saveMeta(entry) return entry
def upload(self, fileName, listener = None, bypassRegistry = False): if listener is None: listener = IZMediaStorageUploadListener() uploadResponse = None (shortName, filePath, size, timestamp) = getFileMetaData(fileName) shortName = sanitizeFileName(shortName) listener.onUploadStarted(fileName, size) try: if not bypassRegistry and self.registry.hasFile(filePath, size, timestamp): listener.onUploadChunk(fileName, size) uploadResponse = self.registry.getUploadResponse(filePath) else: metaData = self.registry.getMetaData(filePath) uploadResponse = self.provider.uploadFile(shortName, filePath, listener, metaData) if uploadResponse is not None: self.registry.addFileEntry(filePath, size, timestamp, uploadResponse) listener.onUploadComplete(fileName) except Exception, e: listener.onUploadFailed(fileName, e) listener.onUploadComplete(fileName) raise e
def addResource(self, filePath, zstreamWrapperListener=None): #@UnusedVariable # if url, then get shortname from url or create shortname if not filePath or not os.path.isfile(filePath): return None # check if this resource is already in the store filePath = os.path.abspath(filePath) if filePath.startswith(self.storeDir): (name, path, fsize, schemadt) = getFileMetaData(filePath) #@UnusedVariable resourceStoreEntryPath = self._getStorePath(name) metaStoreEntryPath = self._getStorePath(self._getMetaFileId(name)) # resource and meta xml file aready exists in store if os.path.isfile(resourceStoreEntryPath) and os.path.isfile( metaStoreEntryPath): return self.getResource(name) entry = self._createNewFileEntryInfo(filePath) copyFile(filePath, entry.getFilePath(), zstreamWrapperListener) self._saveMeta(entry) return entry
def upload(self, fileName, listener=None, bypassRegistry=False): if listener is None: listener = IZMediaStorageUploadListener() uploadResponse = None (shortName, filePath, size, timestamp) = getFileMetaData(fileName) shortName = sanitizeFileName(shortName) listener.onUploadStarted(fileName, size) try: if not bypassRegistry and self.registry.hasFile( filePath, size, timestamp): listener.onUploadChunk(fileName, size) uploadResponse = self.registry.getUploadResponse(filePath) else: metaData = self.registry.getMetaData(filePath) uploadResponse = self.provider.uploadFile( shortName, filePath, listener, metaData) if uploadResponse is not None: self.registry.addFileEntry(filePath, size, timestamp, uploadResponse) listener.onUploadComplete(fileName) except Exception, e: listener.onUploadFailed(fileName, e) listener.onUploadComplete(fileName) raise e
def getContentLength(self): if os.path.isfile(self.contentFilename): return getFileMetaData(self.contentFilename)[2] return ZHttpConnectionRespInfo.getContentLength(self)
def delete(self, fileName): (shortName, filePath, size, timestamp) = getFileMetaData(fileName) if not self.registry.hasFile(filePath, size, timestamp): return self.provider.deleteFile(shortName, self.registry.getMetaData(filePath)) self.registry.removeFile(filePath)
def _isImageFile(self): (fileName, absFilePath, filePath, dateTime) = getFileMetaData(self.getFile()) #@UnusedVariable fileExt = getFileExtension(fileName) return fileExt and fileExt in self.imgExtensions
def _isImageFile(self): (fileName, absFilePath, filePath, dateTime) = getFileMetaData( self.getFile() ) #@UnusedVariable fileExt = getFileExtension(fileName) return fileExt and fileExt in self.imgExtensions