def changeLabel(self, item, newLabel): found = self._findItem(item) if found: item['title'] = newLabel [cfgFile, data, fav] = found # if it's a virtual folder, rename file, rename header, update link if self._isVirtualFolder(item): url = item.getInfo('url') oldFile = self._getFullPath(url) newFilename = urllib.quote_plus(fu.cleanFilename(newLabel)) virtualFolderFile = newFilename + '.cfg' physicalFolder = os.path.normpath(self._favouritesFoldersFolder) virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile) # check if new target is valid if os.path.exists(virtualFolderPath): prefix = newFilename + '-' suffix = '.cfg' virtualFolderFile = fu.randomFilename(directory=physicalFolder, prefix=prefix, suffix=suffix) virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile) # update header content = fu.getFileContent(oldFile) oldHeader = self.cfgBuilder.buildHeader(item['title']) newHeader = self.cfgBuilder.buildHeader(newLabel) content = content.replace(oldHeader, newHeader) # rename file self._removeVirtualFolder(oldFile, False) fu.setFileContent(virtualFolderPath, content) # update link item['url'] = self._getShortPath(virtualFolderPath) newfav = self._createFavourite(item) new = data.replace(fav, enc.smart_unicode(newfav).encode('utf-8')) fu.setFileContent(cfgFile, new)
def _addFolder(self, name, rootFolder=None): # create cfg filename = urllib.quote_plus(fu.cleanFilename(name)) virtualFolderFile = filename + '.cfg' physicalFolder = os.path.normpath(self._favouritesFoldersFolder) virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile) if os.path.exists(virtualFolderPath): prefix = filename + '-' suffix = '.cfg' virtualFolderFile = fu.randomFilename(directory=physicalFolder, prefix=prefix, suffix=suffix) virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile) self._createVirtualFolder(name, virtualFolderPath) # create link linkToFolder = self._createItem(name, 'rss', '', '', None, 'favfolders/' + virtualFolderFile) if not rootFolder or os.path.normpath(rootFolder) == self._favouritesFile: rootFolder = self._favouritesFile fu.appendFileContent(rootFolder, linkToFolder) return True
def _addFolder(self, name, rootFolder=None): # create cfg filename = urllib.quote_plus(fu.cleanFilename(name)) virtualFolderFile = filename + '.cfg' physicalFolder = os.path.normpath(self._favouritesFoldersFolder) virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile) if os.path.exists(virtualFolderPath): prefix = filename + '-' suffix = '.cfg' virtualFolderFile = fu.randomFilename(directory=physicalFolder, prefix=prefix, suffix=suffix) virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile) self._createVirtualFolder(name, virtualFolderPath) # create link linkToFolder = self._createItem(name, 'rss', '', '', None, 'favfolders/' + virtualFolderFile) if not rootFolder or os.path.normpath( rootFolder) == self._favouritesFile: rootFolder = self._favouritesFile fu.appendFileContent(rootFolder, linkToFolder) return True
def changeLabel(self, item, newLabel): found = self._findItem(item) if found: item['title'] = newLabel [cfgFile, data, fav] = found # if it's a virtual folder, rename file, rename header, update link if self._isVirtualFolder(item): url = item.getInfo('url') oldFile = self._getFullPath(url) newFilename = urllib.quote_plus(fu.cleanFilename(newLabel)) virtualFolderFile = newFilename + '.cfg' physicalFolder = os.path.normpath( self._favouritesFoldersFolder) virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile) # check if new target is valid if os.path.exists(virtualFolderPath): prefix = newFilename + '-' suffix = '.cfg' virtualFolderFile = fu.randomFilename( directory=physicalFolder, prefix=prefix, suffix=suffix) virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile) # update header content = fu.getFileContent(oldFile) oldHeader = self.cfgBuilder.buildHeader(item['title']) newHeader = self.cfgBuilder.buildHeader(newLabel) content = content.replace(oldHeader, newHeader) # rename file self._removeVirtualFolder(oldFile, False) fu.setFileContent(virtualFolderPath, content) # update link item['url'] = self._getShortPath(virtualFolderPath) newfav = self._createFavourite(item) new = data.replace(fav, enc.smart_unicode(newfav).encode('utf-8')) fu.setFileContent(cfgFile, new)