Ejemplo n.º 1
0
 def changeIcon(self, item, newIcon):
     found = self._findItem(item)
     if found:
         [cfgFile, data, fav] = found
         newfav = self._createFavourite(item, icon=newIcon)
         new = data.replace(fav, newfav.encode("utf-8"))
         fu.setFileContent(cfgFile, new)
 def moveToFolder(self, cfgFile, item, newCfgFile):
     if os.path.exists(cfgFile) and os.path.exists(newCfgFile):
         fav = self._createFavourite(item)
         old = fu.getFileContent(cfgFile)
         new = old.replace(enc.smart_unicode(fav).encode('utf-8'),'')
         fu.setFileContent(cfgFile, new)
         fu.appendFileContent(newCfgFile, fav)
Ejemplo n.º 3
0
 def changeIcon(self, item, newIcon):
     found = self._findItem(item)
     if found:
         [cfgFile, data, fav] = found
         newfav = self._createFavourite(item, icon=newIcon)
         new = data.replace(fav, newfav.encode('utf-8'))
         fu.setFileContent(cfgFile, new)
    def addFolder(self):
        if not (os.path.exists(self._favouritesFile) and os.path.exists(self._favouritesFoldersFolder)):
            return False
        
        # get name
        name = getKeyboard(default = '', heading = 'Set name')
        if not name or name == "":
            return False

        # create cfg
        virtualFolderFile = urllib.quote_plus(name) + '.cfg'
        physicalFolder = self._favouritesFoldersFolder
        virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile)
        if os.path.exists(virtualFolderPath):
            common.showInfo('Folder already exists')
            return False
        data = [\
            '\n',
            '########################################################',
            '# ' + name.upper(),
            '########################################################'
            ]
        fu.setFileContent(virtualFolderPath, '\n'.join(data))

        # create link
        linkToFolder = self._createItem(name, 'rss', '', '', None, 'favfolders/' + virtualFolderFile)
        fu.appendFileContent(self._favouritesFile, linkToFolder)
        return True    
 def changeFanart(self, cfgFile, item, newFanart):
     if os.path.exists(cfgFile):
         fav = self._createFavourite(item)
         newfav = self._createFavourite(item, fanart=newFanart)
         old = fu.getFileContent(cfgFile)
         new = old.replace(enc.smart_unicode(fav).encode('utf-8'), enc.smart_unicode(newfav).encode('utf-8'))
         fu.setFileContent(cfgFile, new)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 def changeFanart(self, item, newFanart):
     found = self._findItem(item)
     if found:
         [cfgFile, data, fav] = found
         newfav = self._createFavourite(item, fanart=newFanart)
         new = data.replace(fav, enc.smart_unicode(newfav).encode('utf-8'))
         fu.setFileContent(cfgFile, new)
Ejemplo n.º 8
0
 def changeFanart(self, item, newFanart):
     found = self._findItem(item)
     if found:
         [cfgFile, data, fav] = found
         newfav = self._createFavourite(item, fanart=newFanart)
         new = data.replace(fav, enc.smart_unicode(newfav).encode('utf-8'))
         fu.setFileContent(cfgFile, new)
Ejemplo n.º 9
0
 def moveToFolder(self, cfgFile, item, newCfgFile):
     found = self._findItem(item)
     if found:
         [cfgFile, data, fav] = found
         if os.path.exists(newCfgFile):
             new = data.replace(fav, '')
             fu.setFileContent(cfgFile, new)
             fu.appendFileContent(newCfgFile, fav)
Ejemplo n.º 10
0
 def moveToFolder(self, cfgFile, item, newCfgFile):
     found = self._findItem(item)
     if found:
         [cfgFile, data, fav] = found
         if os.path.exists(newCfgFile):
             new = data.replace(fav,'')
             fu.setFileContent(cfgFile, new)
             fu.appendFileContent(newCfgFile, fav)
Ejemplo n.º 11
0
    def removeItem(self, item):
        found = self._findItem(item)
        if found:
            [cfgFile, data, fav] = found
            new = data.replace(fav,'')
            fu.setFileContent(cfgFile, new)

            # delete virtual folder
            if self._isVirtualFolder(item):
                self._removeVirtualFolder(item)
Ejemplo n.º 12
0
    def getSearchPhrase(self):
        searchCache = os.path.join(common.Paths.cacheDir, 'search')
        default_phrase = fu.getFileContent(searchCache)
        if not default_phrase:
            default_phrase = ''

        search_phrase = common.showOSK(default_phrase, common.translate(30102))
        if search_phrase == '':
            return None
        xbmc.sleep(10)
        fu.setFileContent(searchCache, search_phrase)

        return search_phrase
Ejemplo n.º 13
0
    def getSearchPhrase(self):
        searchCache = os.path.join(common.Paths.cacheDir, 'search')
        try:
            curr_phrase = fu.getFileContent(searchCache)
        except:
            curr_phrase = ''
        search_phrase = getKeyboard(default = curr_phrase, heading = common.translate(30102))
        if search_phrase == '':
            return None
        xbmc.sleep(10)
        fu.setFileContent(searchCache, search_phrase)

        return search_phrase
Ejemplo n.º 14
0
    def getSearchPhrase(self):
        searchCache = os.path.join(common.Paths.cacheDir, 'search')
        default_phrase = fu.getFileContent(searchCache)
        if not default_phrase:
            default_phrase = ''

        search_phrase = common.showOSK(default_phrase, common.translate(30102))
        if search_phrase == '':
            return None
        xbmc.sleep(10)
        fu.setFileContent(searchCache, search_phrase)

        return search_phrase
Ejemplo n.º 15
0
    def do(self):
        if self.source and self.target:
            response = None
            try:
                f = urllib.urlopen(self.source.file)
                response = f.read()
                f.close()
            except:
                return False

            fU.setFileContent(self.target.file, response, True)
            return True

        return False
Ejemplo n.º 16
0
 def do(self):
     if self.source and self.target:
         response = None
         try:
             f = urllib.urlopen(self.source.file)
             response = f.read()
             f.close()
         except:
             return False
                     
         fU.setFileContent(self.target.file, response)
         return True
     
     return False
Ejemplo n.º 17
0
 def removeItem(self, item):
     found = self._findItem(item)
     if found:
         try:
             # delete virtual folder
             if self._isVirtualFolder(item):
                 self._removeVirtualFolder(item['url'], True)
             # delete link
             [cfgFile, data, fav] = found
             new = data.replace(fav,'')
             fu.setFileContent(cfgFile, new)
             return True
         except:
             return False 
     return False
    def removeItem(self, item):
        cfgFile = self._favouritesFile
        definedIn = item.getInfo('definedIn')
        if definedIn and definedIn.startswith('favfolders/'):
            cfgFile = os.path.join(self._favouritesFoldersFolder, definedIn.split('/')[1])

        if os.path.exists(cfgFile):
            fav = self._createFavourite(item)
            old = fu.getFileContent(cfgFile)
            new = old.replace(enc.smart_unicode(fav).encode('utf-8'),'')
            fu.setFileContent(cfgFile, new)

            # delete virtual folder
            if self._isVirtualFolder(item):
                self._removeVirtualFolder(item)
Ejemplo n.º 19
0
 def removeItem(self, item):
     found = self._findItem(item)
     if found:
         try:
             # delete virtual folder
             if self._isVirtualFolder(item):
                 self._removeVirtualFolder(item['url'], True)
             # delete link
             [cfgFile, data, fav] = found
             new = data.replace(fav, '')
             fu.setFileContent(cfgFile, new)
             return True
         except:
             return False
     return False
 def getCustomModules(self):
     head = [\
         '########################################################',
         '#                    Custom Modules                    #',
         '########################################################',
         ''
         ]        
             
     txt = '\n'.join(head)
     
     self.modules = []
     for root, _, files in os.walk(self._customModulesFolder , topdown = False):
         for name in files:
             if name.endswith('.module'):
                 self.modules.append(name)
                 txt += fileUtils.getFileContent(os.path.join(root, name)) + '\n'
     fileUtils.setFileContent(self._customModulesFile, txt)
 def getCustomModules(self):
     head = [\
         '########################################################',
         '#                    Custom Modules                    #',
         '########################################################',
         ''
         ]        
             
     txt = '\n'.join(head)
     
     self.modules = []
     for root, _, files in os.walk(self._customModulesFolder , topdown = False):
         for name in files:
             if name.endswith('.module'):
                 self.modules.append(name)
                 txt += fileUtils.getFileContent(os.path.join(root, name)) + '\n'
     fileUtils.setFileContent(self._customModulesFile, txt)
    def __init__(self, favouritesFolder):
        self._favouritesFolder = favouritesFolder
        if not os.path.exists(self._favouritesFolder):
            os.makedirs(self._favouritesFolder, 0777)

        self._favouritesFile = os.path.join(self._favouritesFolder, 'favourites.cfg')
        if not os.path.exists(self._favouritesFile):
            data = [\
                '########################################################',
                '#                    Favourites                        #',
                '########################################################'
                ]
            fu.setFileContent(self._favouritesFile, '\n'.join(data))

        self._favouritesFoldersFolder = os.path.join(self._favouritesFolder, 'favfolders')
        if not os.path.exists(self._favouritesFoldersFolder):
            os.mkdir(self._favouritesFoldersFolder)
Ejemplo n.º 23
0
 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 changeLabel(self, cfgFile, item, newLabel):
        if os.path.exists(cfgFile):
            oldfav = self._createFavourite(item)
            old = fu.getFileContent(cfgFile)

            # if it's a virtual folder, change target url too; check if target already exists; rename target
            # (helpful, if you want to edit files manually)

            if self._isVirtualFolder(item):
                url = item.getInfo('url')
                oldTargetFile = os.path.join(self._favouritesFoldersFolder, url.split('/')[1])
                # check if new target is valid
                newTargetFile = os.path.join(self._favouritesFoldersFolder, urllib.quote_plus(newLabel) + '.cfg')
                if os.path.exists(newTargetFile):
                    common.showInfo('Folder already exists')
                    return
                # rename target
                os.rename(oldTargetFile, newTargetFile)
                # update target url
                item.setInfo('url', 'favfolders/' + urllib.quote_plus(newLabel) + '.cfg')

            newfav = self._createFavourite(item, title=newLabel)
            new = old.replace(enc.smart_unicode(oldfav).encode('utf-8'), enc.smart_unicode(newfav).encode('utf-8'))
            fu.setFileContent(cfgFile, new)
Ejemplo n.º 25
0
 def _createVirtualFolder(self, name, path):
     fullPath = self._getFullPath(path)
     data = self.cfgBuilder.buildHeader(name)
     fu.setFileContent(fullPath, data)
Ejemplo n.º 26
0
 def _createVirtualFolder(self, name, path):
     fullPath = self._getFullPath(path)
     data = self.cfgBuilder.buildHeader(name)
     fu.setFileContent(fullPath, data)