本文整理汇总了Python中xbmcvfs.rename函数的典型用法代码示例。如果您正苦于以下问题:Python rename函数的具体用法?Python rename怎么用?Python rename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rename函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_advancedxml
def import_advancedxml():
userdatapath = xbmc.translatePath(os.path.join('special://home/userdata'.decode('utf-8'),''.decode('utf-8')))
advancedsettings_var = os.path.join(userdatapath,'advancedsettings.xml')
advancedsettingsbackup_var = os.path.join(userdatapath,'advancedsettingsbackup.xml')
if xbmcvfs.exists(advancedsettings_var):
print("An advanced settings XML file already exists")
if xbmcvfs.exists(advancedsettingsbackup_var):
print("An advanced settings backup already exists")
xbmcvfs.delete(advancedsettingsbackup_var)
xbmcvfs.rename(advancedsettings_var,advancedsettingsbackup_var)
advancedname = ["Cachemembuffer=252420","freememorycachepercent=5"]
advancedurl = ["http://p2p-strm.googlecode.com/svn/trunk/Advancedsettings/advancedsettings.xml","http://p2p-strm.googlecode.com/svn/trunk/Advancedsettings/advancedsettingstonicillo.xml"]
index = xbmcgui.Dialog().select(translate(40185), advancedname)
if index > -1:
download_tools().Downloader(advancedurl[index],advancedsettings_var,translate(40059),translate(40000))
mensagemok(translate(40000),translate(40060))
else:
xbmcvfs.rename(advancedsettings_var,advancedsettingsbackup_var)
advancedname = ["Cachemembuffer=252420","freememorycachepercent=5"]
advancedurl = ["http://p2p-strm.googlecode.com/svn/trunk/Advancedsettings/advancedsettings.xml","http://p2p-strm.googlecode.com/svn/trunk/Advancedsettings/advancedsettingstonicillo.xml"]
index = xbmcgui.Dialog().select(translate(40185), advancedname)
if index > -1:
download_tools().Downloader(advancedurl[index],advancedsettings_var,translate(40059),translate(40000))
mensagemok(translate(40000),translate(40060))
else:
print("No advancedsettings.xml in the system yet")
advancedname = ["Cachemembuffer=252420","freememorycachepercent=5"]
advancedurl = ["http://p2p-strm.googlecode.com/svn/trunk/Advancedsettings/advancedsettings.xml","http://p2p-strm.googlecode.com/svn/trunk/Advancedsettings/advancedsettingstonicillo.xml"]
index = xbmcgui.Dialog().select(translate(40185), advancedname)
if index > -1:
download_tools().Downloader(advancedurl[index],advancedsettings_var,translate(40059),translate(40000))
mensagemok(translate(40000),translate(40060))
xbmc.executebuiltin("Container.Refresh")
示例2: unInstallFont
def unInstallFont(paths=None):
paths = paths or getPaths()
if not os.path.exists(paths.fontBackupPath): return False
if os.path.exists(paths.fontPath): xbmcvfs.delete(paths.fontPath)
xbmcvfs.rename(paths.fontBackupPath,paths.fontPath)
dialogs.showMessage(T(32417),T(32590))
return True
示例3: createNfos
def createNfos(self):
progressDialog = xbmcgui.DialogProgress()
progressDialog.create( "Extras", "Searching for files" )
pendingFiles = self.getExtraNfoFiles( self.get_movie_sources() )
pattern = "-extras-nfo-"
current = 0
total = len( pendingFiles )
for file in pendingFiles:
current = current + 1
log( "Creating nfo for " + file )
progressDialog.update( current / total, "Creating nfo for " + file )
directory = os.path.dirname( file )
filename = os.path.basename( file )
patternStart = filename.index(pattern)
patternEnd = len( pattern )
displayName = filename[patternStart + patternEnd:]
displayName = os.path.splitext(displayName)[0].replace(".sample", "")
newName = filename[0:patternStart] + "-" + filename[patternStart + patternEnd:]
newName = newName.replace( ".sample", "" )
xbmcvfs.rename( file, os.path.join( directory, newName ) )
seasonAndEpisode = self.getSeasonAndEpisode(filename)
nfoFile = xbmcvfs.File( os.path.join( directory, os.path.splitext(newName)[0] ) + ".nfo", 'w' )
nfoFile.write( "<episodedetails><title>" + displayName.replace(":", ":") + "</title>" + seasonAndEpisode[0] + seasonAndEpisode[1] + "</episodedetails>" )
nfoFile.close()
progressDialog.close()
if current > 0:
xbmc.executebuiltin("UpdateLibrary(video)")
xbmcgui.Dialog().ok("Extras", "Finished scan")
示例4: panFetch
def panFetch(song, path):
global _high
isad = int(_settings.getSetting('isad')) * 1024
wait = int(_settings.getSetting('delay'))
qual = _settings.getSetting('quality')
skip = _settings.getSetting('skip')
url = urlparse.urlsplit(song.audioUrl[qual])
conn = httplib.HTTPConnection(url.netloc, timeout = 9)
conn.request('GET', "%s?%s" % (url.path, url.query))
strm = conn.getresponse()
size = int(strm.getheader('content-length'))
if size in (341980, 173310): # empty song cause requesting to fast
xbmc.log("%s.Fetch MT (%13s,%8d) '%s - %s - %s'" % (_plugin, _stamp, size, song.songId[:4], song.artist, song.title), xbmc.LOGDEBUG)
panMsg(song, 'To Many Songs Requested')
return
xbmc.log("%s.Fetch %s (%13s,%8d) '%s - %s - %s'" % (_plugin, strm.reason, _stamp, size, song.songId[:4], song.artist, song.title))
totl = 0
qued = False
last = time.time()
file = open(path, 'wb', 0)
while (totl < size) and (not xbmc.abortRequested):
try: data = strm.read(min(4096, size - totl))
except socket.timeout:
xbmc.log("%s.Fetch TO (%13s,%8d) '%s - %s - %s'" % (_plugin, _stamp, totl, song.songId[:4], song.artist, song.title), xbmc.LOGDEBUG)
break
if _high < (time.time() - last): _high = time.time() - last
last = time.time()
file.write(data)
totl += len(data)
if (not qued) and (size > isad):
threading.Timer(wait, panQueue, (song, path)).start()
qued = True
file.close()
conn.close()
if totl < size: # incomplete file
xbmc.log("%s.Fetch RM (%13s) '%s - %s - %s'" % (_plugin, _stamp, song.songId[:4], song.artist, song.title), xbmc.LOGDEBUG)
xbmcvfs.delete(path)
elif size <= isad: # looks like an ad
if skip == 'true':
xbmc.log("%s.Fetch AD (%13s) '%s - %s - %s'" % (_plugin, _stamp, song.songId[:4], song.artist, song.title), xbmc.LOGDEBUG)
xbmcvfs.delete(path)
elif qued == False: # play it anyway
song.artist = song.album = song.title = 'Advertisement'
dest = path + '.ad.m4a'
xbmcvfs.rename(path, dest)
panQueue(song, dest)
else: panSave(song, path)
示例5: _download
def _download( self, src, dst, dst2 ):
if (not xbmc.abortRequested):
tmpname = xbmc.translatePath('special://profile/addon_data/%s/temp/%s' % ( addonname , xbmc.getCacheThumbName(src) ))
lw.log( ['the tmpname is ' + tmpname] )
if xbmcvfs.exists(tmpname):
success, loglines = deleteFile( tmpname )
lw.log( loglines )
success, loglines, urldata = imgURL.Get( src, params=self.params )
lw.log( loglines )
if success:
success, loglines = writeFile( urldata, tmpname )
lw.log( loglines )
if not success:
return False
if xbmcvfs.Stat( tmpname ).st_size() > 999:
image_ext = getImageType( tmpname )
if not xbmcvfs.exists ( dst + image_ext ):
lw.log( ['copying %s to %s' % (tmpname, dst2 + image_ext)] )
xbmcvfs.copy( tmpname, dst2 + image_ext )
lw.log( ['moving %s to %s' % (tmpname, dst + image_ext)] )
xbmcvfs.rename( tmpname, dst + image_ext )
return True
else:
lw.log( ['image already exists, deleting temporary file'] )
success, loglines = deleteFile( tmpname )
lw.log( loglines )
return False
else:
success, loglines = deleteFile( tmpname )
lw.log( loglines )
return False
示例6: recoverbackup_advancedxml
def recoverbackup_advancedxml():
userdatapath = xbmc.translatePath(os.path.join('special://home/userdata'.decode('utf-8'),''.decode('utf-8')))
advancedsettings_var = os.path.join(userdatapath,'advancedsettings.xml')
advancedsettingsbackup_var = os.path.join(userdatapath,'advancedsettingsbackup.xml')
xbmcvfs.delete(advancedsettings_var)
xbmcvfs.rename(advancedsettingsbackup_var,advancedsettings_var)
mensagemok(translate(40000),translate(40062))
xbmc.executebuiltin("Container.Refresh")
示例7: move_file
def move_file(self, source, dest_folder):
"""Move a file to a new destination. Will create destination if it does not exist.
Example:
success = move_file(a, b)
:type source: str
:param source: the source path (absolute)
:type dest_folder: str
:param dest_folder: the destination path (absolute)
:rtype: bool
:return: True if (at least one) file was moved successfully, False otherwise.
"""
if isinstance(source, unicode):
source = source.encode("utf-8")
paths = self.unstack(source)
success = []
dest_folder = xbmc.makeLegalFilename(dest_folder)
if self.is_excluded(paths[0]):
debug("Detected a file on an excluded path. Aborting.")
return False
for p in paths:
debug("Attempting to move %r to %r." % (p, dest_folder))
if xbmcvfs.exists(p):
if not xbmcvfs.exists(dest_folder):
if xbmcvfs.mkdirs(dest_folder):
debug("Created destination %r." % dest_folder)
else:
debug("Destination %r could not be created." % dest_folder, xbmc.LOGERROR)
return False
new_path = os.path.join(dest_folder, os.path.basename(p))
if xbmcvfs.exists(new_path):
debug("A file with the same name already exists in the holding folder. Checking file sizes.")
existing_file = xbmcvfs.File(new_path)
file_to_move = xbmcvfs.File(p)
if file_to_move.size() > existing_file.size():
debug("This file is larger than the existing file. Replacing it with this one.")
existing_file.close()
file_to_move.close()
success.append(bool(xbmcvfs.delete(new_path) and xbmcvfs.rename(p, new_path)))
else:
debug("This file isn't larger than the existing file. Deleting it instead of moving.")
existing_file.close()
file_to_move.close()
success.append(bool(xbmcvfs.delete(p)))
else:
debug("Moving %r to %r." % (p, new_path))
success.append(bool(xbmcvfs.rename(p, new_path)))
else:
debug("File %r no longer exists." % p, xbmc.LOGWARNING)
success.append(False)
return any(success)
示例8: checkKBModRemove
def checkKBModRemove(skinPath):
backupPath = getSkinFilePath(skinPath,'DialogKeyboard.xml.FBbackup')
dialogPath = getSkinFilePath(skinPath,'DialogKeyboard.xml')
if backupPath and dialogPath:
xbmcvfs.delete(dialogPath)
xbmcvfs.rename(backupPath,dialogPath)
setSetting('keyboard_installed',False)
dialogs.showMessage(T(32476),T(32476),' ',T(32477))
return True
示例9: download_sub
def download_sub(subtitle):
xbmc_temp = xbmc.translatePath('special://temp')
tempdir = os.path.join(xbmc_temp, 'phudeVMF')
if 'subscene.com' in subtitle:
response = urlfetch.get(subtitle)
sub = re.search(r'href=\"(/subtitle/download?.*?)\"', response.body)
sub = sub.group(1)
subpath = "https://subscene.com" + sub
if 'phudeviet.org' in subtitle:
f = urlfetch.get(subtitle)
match = re.search(r"(http://phudeviet.org/download/.+?html)", f.body)
subpath = match.group(1)
f = urlfetch.get(subpath)
subpath = f.getheader('location')
vDialog.create('Vietmediaf','Bắt đầu tải phụ đề xin vui lòng đợi trong giây lát.','Downloading...')
if not os.path.exists(tempdir):
try:
xbmcvfs.mkdirs(tempdir)
time.sleep(20)
except:pass
else:
for root, dirs, files in os.walk(tempdir, topdown=False):
for name in files:
try:os.remove(os.path.join(root, name))
except:pass
for name in dirs:
try:os.rmdir(os.path.join(root, name))
except:pass
useragent = ("User-Agent=Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0")
headers = {'User-Agent': useragent, 'Referer': subtitle}
tmp_file = os.path.join(tempdir, "phude.zip")
try:
if os.path.exists(tmp_file):
os.remove(tmp_file)
request = urllib2.Request(subpath, '', headers)
response = urllib2.urlopen(request)
file_handle = xbmcvfs.File(tmp_file, "wb")
file_handle.write(response.read())
xbmc.sleep(500)
file_handle.close()
xbmc.executebuiltin('XBMC.Extract("%s","%s")' % (tmp_file, tempdir))
except:
notify('Không tải được phụ đề')
pass
vDialog.close()
exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass"]
sub_temp = os.path.join(tempdir, "sub.file")
for file in xbmcvfs.listdir(tempdir)[1]:
if os.path.splitext(file)[1] in exts:
sub_file = os.path.join(tempdir, file)
xbmcvfs.rename(sub_file, sub_temp)
return sub_temp
示例10: Restore
def Restore(bak, org):
log('Restore ' + str(bak) + ' - ' + str(org))
if FileAccess.exists(bak):
if FileAccess.exists(org):
try:
xbmcvfs.delete(org)
except:
pass
xbmcvfs.rename(bak, org)
xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % ("PseudoTV Live", "Restore Complete, Restarting...", 1000, THUMB) )
示例11: loop
def loop(self):
if self.local: return
pos=self.pos
self.log.out('1')
if len(self.player.coms)>0:
comm=self.player.coms[0]
self.player.coms.remove(comm)
self.TSpush(comm)
self.log.out('2')
if self.player.isPlaying():
if self.player.getTotalTime()>0: cpos= int((1-(self.player.getTotalTime()-self.player.getTime())/self.player.getTotalTime())*100)
else: cpos=0
if cpos in pos:
pos.remove(cpos)
comm='PLAYBACK '+self.player.link.replace('\r','').replace('\n','')+' %s'%cpos
self.TSpush(comm)
self.log.out('3')
if self.tsserv.event and self.save:
self.log.out('Try to save file in loop')
try: comm='SAVE %s path=%s'%(self.tsserv.event[0]+' '+self.tsserv.event[1],urllib.quote(self.filename))
except: comm='SAVE %s path=%s'%(self.tsserv.event[0]+' '+self.tsserv.event[1],urllib.quote(self.filenam.encode('utf-8')))
self.TSpush(comm)
self.tsserv.event=None
succ=True
self.saved=True
self.log.out('4')
if self.saved:
self.log.out('4.1')
try: tt=os.path.exists(self.filename.decode('utf-8'))
except: tt=os.path.exists(self.filename)
if self.player.isPlaying() and tt:
xbmc.sleep(3000)
self.log.out('Start local file')
self.tsserv.got_url=self.filename
self.local=True
self.sm('Start Local File')
try: time1=self.player.getTime()
except: time1=0
i = xbmcgui.ListItem("***%s"%self.title)
i.setProperty('StartOffset', str(time1))
self.log.out('Play local file')
try:
xbmcvfs.rename(self.filename.decode('utf-8'),self.filename.decode('utf-8'))
xbmc.Player().play(self.filename.decode('utf-8'),i)
except:
xbmcvfs.rename(self.filename,self.filename)
xbmc.Player().play(self.filename,i)
self.local=True
self.player.active=False
saved=False
self.save=False
self.log.out('loop succ')
示例12: saveTorrent
def saveTorrent(self, torrentUrl):
if re.match("^magnet\:.+$", torrentUrl):
self.magnetLink = torrentUrl
self.magnetToTorrent(torrentUrl)
self.magnetLink = None
return self.torrentFile
else:
if not xbmcvfs.exists(self.torrentFilesPath):
xbmcvfs.mkdirs(self.torrentFilesPath)
torrentFile = self.torrentFilesPath + self.md5(
torrentUrl) + '.torrent'
try:
if not re.match("^http\:.+$", torrentUrl):
contentFile = xbmcvfs.File(torrentUrl, "rb")
content = contentFile.read()
contentFile.close()
else:
request = urllib2.Request(torrentUrl)
request.add_header('Referer', torrentUrl)
request.add_header('Accept-encoding', 'gzip')
result = urllib2.urlopen(request)
if result.info().get('Content-Encoding') == 'gzip':
buf = StringIO(result.read())
decomp = zlib.decompressobj(16 + zlib.MAX_WBITS)
content = decomp.decompress(buf.getvalue())
else:
content = result.read()
localFile = xbmcvfs.File(torrentFile, "w+b")
localFile.write(content)
localFile.close()
except Exception, e:
log('Unable to save torrent file from "' + torrentUrl + '" to "' + torrentFile + '" in Torrent::saveTorrent' + '. Exception: ' + str(e))
return
if xbmcvfs.exists(torrentFile):
try:
e=self.lt.bdecode(xbmcvfs.File(torrentFile,'rb').read())
self.torrentFileInfo = self.lt.torrent_info(e)
except Exception, e:
log('Exception: ' + str(e))
xbmcvfs.delete(torrentFile)
return
if not xbmcvfs.exists(self.torrentFilesPath):
xbmcvfs.mkdirs(self.torrentFilesPath)
newFile = self.torrentFilesPath + self.md5(torrentUrl) + '.torrent'
if newFile != torrentFile:
if xbmcvfs.exists(newFile):
xbmcvfs.delete(newFile)
if not xbmcvfs.exists(newFile):
try:
xbmcvfs.rename(torrentFile, newFile)
except Exception, e:
log('Unable to rename torrent file from %s to %s in Torrent::renameTorrent. Exception: %s' %
(torrentFile, newFile, str(e)))
return
示例13: saveTorrent
def saveTorrent(self, torrentUrl):
if re.match("^magnet\:.+$", torrentUrl):
self.magnetLink = torrentUrl
self.magnetToTorrent(torrentUrl)
self.magnetLink = None
return self.torrentFile
else:
if not xbmcvfs.exists(self.torrentFilesPath):
xbmcvfs.mkdirs(self.torrentFilesPath)
torrentFile = self.torrentFilesPath + self.md5(
torrentUrl) + '.torrent'
try:
if not re.match("^http\:.+$", torrentUrl):
content = xbmcvfs.File(torrentUrl, "rb").read()
else:
request = urllib2.Request(torrentUrl)
request.add_header('Referer', torrentUrl)
request.add_header('Accept-encoding', 'gzip')
result = urllib2.urlopen(request)
if result.info().get('Content-Encoding') == 'gzip':
buf = StringIO(result.read())
f = gzip.GzipFile(fileobj=buf)
content = f.read()
else:
content = result.read()
localFile = xbmcvfs.File(torrentFile, "w+b")
localFile.write(content)
localFile.close()
except Exception, e:
print 'Unable to save torrent file from "' + torrentUrl + '" to "' + torrentFile + '" in Torrent::saveTorrent' + '. Exception: ' + str(
e)
return
if xbmcvfs.exists(torrentFile):
try:
e=self.lt.bdecode(xbmcvfs.File(torrentFile,'rb').read())
self.torrentFileInfo = self.lt.torrent_info(e)
except Exception, e:
print 'Exception: ' + str(e)
xbmcvfs.delete(torrentFile)
return
baseName = file_encode(os.path.basename(self.getFilePath()))
if not xbmcvfs.exists(self.torrentFilesPath):
xbmcvfs.mkdirs(self.torrentFilesPath)
newFile = self.torrentFilesPath + self.md5(baseName) + '.' + self.md5(
torrentUrl) + '.torrent' # + '.'+ baseName
if xbmcvfs.exists(newFile):
xbmcvfs.delete(newFile)
if not xbmcvfs.exists(newFile):
try:
xbmcvfs.rename(torrentFile, newFile)
except Exception, e:
print 'Unable to rename torrent file from "' + torrentFile + '" to "' + newFile + '" in Torrent::renameTorrent' + '. Exception: ' + str(
e)
return
示例14: break_sopcast
def break_sopcast():
if xbmc.getCondVisibility('system.platform.windows'):
import _winreg
aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)
try:
aKey = _winreg.OpenKey(aReg, r'SOFTWARE\SopCast\Player\InstallPath',0, _winreg.KEY_READ)
name, value, type = _winreg.EnumValue(aKey, 0)
codec_file = os.path.join(os.path.join(value.replace("SopCast.exe","")),'codec','sop.ocx.old')
_winreg.CloseKey(aKey)
if xbmcvfs.exists(codec_file): xbmcvfs.rename(codec_file,os.path.join(os.path.join(value.replace("SopCast.exe","")),'codec','sop.ocx'))
except:pass
示例15: save_session
def save_session():
temp_file = utility.session_file() + '.tmp'
if xbmcvfs.exists(temp_file):
xbmcvfs.delete(temp_file)
session_backup = pickle.dumps(session)
file_handler = xbmcvfs.File(temp_file, 'wb')
file_handler.write(session_backup)
file_handler.close()
if xbmcvfs.exists(utility.session_file()):
xbmcvfs.delete(utility.session_file())
xbmcvfs.rename(temp_file, utility.session_file())