• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python fileUtils.getFileContent函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.fileUtils.getFileContent函数的典型用法代码示例。如果您正苦于以下问题:Python getFileContent函数的具体用法?Python getFileContent怎么用?Python getFileContent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了getFileContent函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _findItem

    def _findItem(self, item):
        title = re.escape(item.getInfo('title'))    
        cfg = item.getInfo('cfg')
        if cfg:
            cfg = re.escape(cfg)
        url = re.escape(item.getInfo('url'))
    
        regex = [\
            '',
            '########################################################',
            '# ' + title.upper(),
            '########################################################',
            'title=' + title,
            '.*?'
            ]
        
        if cfg:
            regex.append('cfg=' + cfg)
        regex.append('url=' + url)
        regex = '(' + '\s*'.join(regex) + ')'
        
        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):
            data = fu.getFileContent(cfgFile)            
            matches = regexUtils.findall(data, regex)
            if matches and len(matches) > 0:
                fav = matches[0]
                return (cfgFile, data, fav)
        return None
开发者ID:gtfamily,项目名称:gtfamily,代码行数:33,代码来源:favouritesManager.py


示例2: replaceFromDict

def replaceFromDict(dictFilePath, wrd):

    dictionary = enc.smart_unicode(getFileContent(dictFilePath))
    dictionary = dictionary.replace('\r\n','\n')

    p_reg = re.compile('^[^\r\n]+$', re.IGNORECASE + re.DOTALL + re.MULTILINE)
    m_reg = p_reg.findall(dictionary)

    word = enc.smart_unicode(wrd).replace(u'Ãœ','Ü').replace(u'Ö','Ö').replace(u'Ä','Ä')
    try:
        if m_reg and len(m_reg) > 0:
            index = ''
            words = []
            newword = ''
            for m in m_reg:
                if not m.startswith(' '):
                    index = m
                    del words[:]
                else:
                    replWord = m.strip()
                    words.append(replWord)
                    if word.find(' ') != -1:
                        newword = word.replace(replWord,index)

                if (word in words) or (word == index):
                    return index

            if newword != '' and newword != word:
                return newword
    except:
        common.log('Skipped Replacement: ' + word)

    return word
开发者ID:Gemini88,项目名称:addons,代码行数:33,代码来源:customConversions.py


示例3: removeCustomModule

 def removeCustomModule(self, moduleName):    
     try:
         customCfg = self._customModulesFile
         content = fileUtils.getFileContent(customCfg)
         lines = content.splitlines()
         
         startIdx = -1
         cfgUrl = ''
         for i in range(0, len(lines)):
             if lines[i].startswith("title=%s" % moduleName):
                 startIdx = i
             
             elif startIdx > -1 and lines[i].startswith("url="):
                 tmp = lines[i][4:]
                 cfgUrl = os.path.join(self._customModulesFolder, tmp)
                 break
             
         if os.path.isfile(cfgUrl):
             os.remove(cfgUrl)
             os.remove(cfgUrl.replace(".cfg", ".module"))
             return True
     except:
         pass
     
     return False    
开发者ID:gtfamily,项目名称:gtfamily,代码行数:25,代码来源:customModulesManager.py


示例4: removeCustomModule

    def removeCustomModule(self, moduleName):    
        try:
            customCfg = self._customModulesFile
            content = fileUtils.getFileContent(customCfg)
            lines = content.splitlines()
            
            startIdx = -1
            cfgUrl = ''
            for i in range(0, len(lines)):
                if lines[i].startswith("title=%s" % moduleName):
                    startIdx = i
                
                elif startIdx > -1 and lines[i].startswith("url="):
                    tmp = lines[i][4:]
                    cfgUrl = os.path.join(self._customModulesFolder, tmp)
                    break
                
            if os.path.isfile(cfgUrl):
                os.remove(cfgUrl)
                os.remove(cfgUrl.replace(".cfg", ".module"))
                
                # remove all folder that start with cfg name and a dot
                baseDir = os.path.dirname(cfgUrl)
                prefix = os.path.basename(cfgUrl).replace(".cfg", ".")
                dirs = fileUtils.get_immediate_subdirectories(baseDir)
                for d in dirs:
                    if d.startswith(prefix):
                        fileUtils.clearDirectory(os.path.join(baseDir, d))
                        os.removedirs(os.path.join(baseDir, d))

                return True
        except:
            pass
        
        return False    
开发者ID:AMOboxTV,项目名称:AMOBox.LegoBuild,代码行数:35,代码来源:customModulesManager.py


示例5: changeLabel

 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)
开发者ID:Anniyan,项目名称:SportsDevil-Fixes,代码行数:32,代码来源:favouritesManager.py


示例6: _parseVirtualFolder

    def _parseVirtualFolder(self, path):
        fullpath = self._getFullPath(path)
        data = fu.getFileContent(fullpath)
        data = data.replace("\r\n", "\n").split("\n")
        items = []
        for m in data:
            if m and m[0] != "#":
                index = m.find("=")
                if index != -1:
                    key = lower(m[:index]).strip()
                    value = m[index + 1 :]

                    index = value.find("|")
                    if value[:index] == "sports.devil.locale":
                        value = common.translate(int(value[index + 1 :]))
                    elif value[:index] == "sports.devil.image":
                        value = os.path.join(common.Paths.imgDir, value[index + 1 :])

                    if key == "title":
                        tmp = CListItem()
                        tmp["title"] = value
                    elif key == "url":
                        tmp["url"] = value
                        items.append(tmp)
                        tmp = None
                    elif tmp != None:
                        tmp[key] = value
        return items
开发者ID:hanspeder36,项目名称:HalowTV,代码行数:28,代码来源:favouritesManager.py


示例7: addXbmcFavourite

    def addXbmcFavourite(self):
        fav_dir = xbmc.translatePath( 'special://profile/favourites.xml' )

        # Check if file exists
        if os.path.exists(fav_dir):
            favourites_xml = fu.getFileContent(fav_dir)
            doc = parseString(favourites_xml)
            xbmcFavs = doc.documentElement.getElementsByTagName('favourite')
            menuItems = []
            favItems = []
            for doc in xbmcFavs:
                title = doc.attributes['name'].nodeValue
                menuItems.append(title)
                try:
                    icon = doc.attributes ['thumb'].nodeValue
                except:
                    icon = ''
                url = doc.childNodes[0].nodeValue
                favItem = XbmcFavouriteItem(title, icon, url)
                favItems.append(favItem)

            select = xbmcgui.Dialog().select('Choose' , menuItems)
            if select == -1:
                return False
            else:
                item = favItems[select].convertToCListItem()
                self.addToFavourites(item)
                return True

        common.showInfo('No favourites found')
        return False
开发者ID:rollysalvana,项目名称:pampereo-xbmc-plugins,代码行数:31,代码来源:favouritesManager.py


示例8: moveToFolder

 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)
开发者ID:rollysalvana,项目名称:pampereo-xbmc-plugins,代码行数:7,代码来源:favouritesManager.py


示例9: changeFanart

 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)
开发者ID:rollysalvana,项目名称:pampereo-xbmc-plugins,代码行数:7,代码来源:favouritesManager.py


示例10: _parseVirtualFolder

    def _parseVirtualFolder(self, path):
        fullpath = self._getFullPath(path)
        data = fu.getFileContent(fullpath)
        data = data.replace('\r\n', '\n').split('\n')
        items = []
        for m in data:
            if m and m[0] != '#':
                index = m.find('=')
                if index != -1:
                    key = lower(m[:index]).strip()
                    value = m[index+1:]

                    index = value.find('|')
                    if value[:index] == 'sports.devil.locale':
                        value = common.translate(int(value[index+1:]))
                    elif value[:index] == 'sports.devil.image':
                        value = os.path.join(common.Paths.imgDir, value[index+1:])

                    if key == 'title':
                        tmp = CListItem()
                        tmp['title'] = value
                    elif key == 'url':
                        tmp['url'] = value
                        items.append(tmp)
                        tmp = None
                    elif tmp != None:
                        tmp[key] = value
        return items   
开发者ID:Anniyan,项目名称:SportsDevil-Fixes,代码行数:28,代码来源:favouritesManager.py


示例11: __init__

    def __init__(self):

        self.simpleScheme = {'(@[email protected])':    os.environ.get('OS'),
                             '(@[email protected])': fu.getFileContent(os.path.join(common.Paths.cacheDir, 'lasturl')),
                             '(@[email protected])':    self.languageShortName(common.language)
                             }

        self.complexScheme = {  'import':     '(#*@IMPORT=([^@]+)@)',
                                'find':       '(#*@FIND\(.*?\)@)',
                                'catch':      '(#*@CATCH\([^\)]+\)@)'
                              }
开发者ID:CYBERxNUKE,项目名称:xbmc-addon,代码行数:11,代码来源:customReplacements.py


示例12: _findItem

 def _findItem(self, item): 
     cfgFile = self._favouritesFile
     definedIn = item.getInfo('definedIn')
     if definedIn and definedIn.startswith('favfolders/'):
         cfgFile = os.path.join(self._favouritesFolder, definedIn)
     if os.path.exists(cfgFile):
         data = fu.getFileContent(cfgFile)
         regex = self.cfgBuilder.buildItem(re.escape(item.getInfo('title')), "[^#]*", re.escape(item.getInfo('url')))
         matches = regexUtils.findall(data, regex)        
         if matches:
             return (cfgFile, data, matches[0])
     return None
开发者ID:Anniyan,项目名称:SportsDevil-Fixes,代码行数:12,代码来源:favouritesManager.py


示例13: install

 def install(self, filename):
     destination = xbmc.translatePath(INSTALL_DIR)
     files = self.extract(filename, destination)
     if files:
         addonXml = filter(lambda x: x.filename.endswith('addon.xml'), files)
         if addonXml:
             path = os.path.join(destination, addonXml[0].filename)
             content = getFileContent(path)
             addonId = findall(content, '<addon id="([^"]+)"')
             if addonId:
                 return addonId[0]
     return None
开发者ID:HarryElSuzio,项目名称:plugin.video.ViendoKodiStreaming-1,代码行数:12,代码来源:addonInstaller.py


示例14: getSearchPhrase

    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
开发者ID:rollysalvana,项目名称:pampereo-xbmc-plugins,代码行数:13,代码来源:main.py


示例15: getSearchPhrase

    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
开发者ID:hackur,项目名称:SportsDevil-Fixes,代码行数:13,代码来源:main.py


示例16: removeItem

    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)
开发者ID:rollysalvana,项目名称:pampereo-xbmc-plugins,代码行数:15,代码来源:favouritesManager.py


示例17: getCustomModules

 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)
开发者ID:AMOboxTV,项目名称:AMOBox.LegoBuild,代码行数:17,代码来源:customModulesManager.py


示例18: __loadLocal

    def __loadLocal(self, filename, lItem = None):
        """Loads cfg, creates list and sets up rules for scraping."""
        params = []

        #get Parameters
        if filename.find('@') != -1:
            params = filename.split('@')
            filename = params.pop(0)

        # get cfg file
        cfg = filename
        if not os.path.exists(cfg):
            cfg = os.path.join(common.Paths.modulesDir, filename)
            if not os.path.exists(cfg):
                tmpPath = os.path.dirname(os.path.join(common.Paths.modulesDir, lItem["definedIn"]))
                cfg = os.path.join(tmpPath ,filename)
                if not os.path.exists(cfg):
                    srchFilename = filename
                    if filename.find('/') > -1:
                        srchFilename = srchFilename.split('/')[1]
                    try:
                        cfg = findInSubdirectory(srchFilename, common.Paths.modulesDir)
                    except:
                        try:
                            cfg = findInSubdirectory(srchFilename, common.Paths.favouritesFolder)
                        except:
                            try:
                                cfg = findInSubdirectory(srchFilename, common.Paths.customModulesDir)
                            except:
                                common.log('File not found: ' + srchFilename)
                                return None

        #load file and apply parameters
        data = getFileContent(cfg)
        data = cr.CustomReplacements().replace(os.path.dirname(cfg), data, lItem, params)

        #log
        msg = 'Local file ' +  filename + ' opened'
        if len(params) > 0:
            msg += ' with Parameter(s): '
            msg += ",".join(params)
        common.log(msg)

        outputList = self.__parseCfg(filename, data, lItem)

        return outputList
开发者ID:mrknow,项目名称:filmkodi,代码行数:46,代码来源:parser.py


示例19: __loadLocal

    def __loadLocal(self, filename, lItem=None):
        params = []

        # get Parameters
        if filename.find("@") != -1:
            params = filename.split("@")
            filename = params.pop(0)

        # get cfg file
        cfg = filename
        if not os.path.exists(cfg):
            cfg = os.path.join(common.Paths.modulesDir, filename)
            if not os.path.exists(cfg):
                tmpPath = os.path.dirname(os.path.join(common.Paths.modulesDir, lItem["definedIn"]))
                cfg = os.path.join(tmpPath, filename)
                if not os.path.exists(cfg):
                    srchFilename = filename
                    if filename.find("/") > -1:
                        srchFilename = srchFilename.split("/")[1]
                    try:
                        cfg = findInSubdirectory(srchFilename, common.Paths.modulesDir)
                    except:
                        try:
                            cfg = findInSubdirectory(srchFilename, common.Paths.favouritesFolder)
                        except:
                            try:
                                cfg = findInSubdirectory(srchFilename, common.Paths.customModulesDir)
                            except:
                                common.log("File not found: " + srchFilename)
                                return None

        # load file and apply parameters
        data = getFileContent(cfg)
        data = cr.CustomReplacements().replace(os.path.dirname(cfg), data, lItem, params)

        # log
        msg = "Local file " + filename + " opened"
        if len(params) > 0:
            msg += " with Parameter(s): "
            msg += ",".join(params)
        common.log(msg)

        outputList = self.__parseCfg(filename, data, lItem)

        return outputList
开发者ID:cyberwarrior,项目名称:dmind,代码行数:45,代码来源:parser.py


示例20: __replaceImports

 def __replaceImports(self, pathToImports, data):
     while True:
         m_reg = findall(data, self.regex('import'))
         if len(m_reg) > 0:
             for idat in m_reg:
                 if idat[0].startswith('#'):
                     data = data.replace(idat[0],'')
                     continue
                 filename = idat[1]
                 pathImp = os.path.join(self.Paths.modulesDir, filename)
                 if not os.path.exists(pathImp):
                     pathImp = os.path.join(pathToImports, filename)
                     if not (os.path.exists(pathImp)):
                         common.log('Skipped Import: ' + filename)
                         continue
                 dataImp = fu.getFileContent(pathImp)
                 dataImp = dataImp.replace('\r\n','\n')
                 data = data.replace(idat[0], dataImp)
         else:
             break
     return data
开发者ID:rollysalvana,项目名称:pampereo-xbmc-plugins,代码行数:21,代码来源:customReplacements.py



注:本文中的utils.fileUtils.getFileContent函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python fileUtils.setFileContent函数代码示例发布时间:2022-05-26
下一篇:
Python feedparser.parse函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap