本文整理汇总了Python中utils.fileUtils.getFileContent函数的典型用法代码示例。如果您正苦于以下问题:Python getFileContent函数的具体用法?Python getFileContent怎么用?Python getFileContent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getFileContent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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
示例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
示例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)
示例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
示例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
示例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)
示例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)
示例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
示例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\([^\)]+\)@)'
}
示例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
示例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
示例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
示例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