本文整理汇总了Python中xbmcvfs.delete函数的典型用法代码示例。如果您正苦于以下问题:Python delete函数的具体用法?Python delete怎么用?Python delete使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了delete函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: restoreColorTheme
def restoreColorTheme():
import shutil
import zipfile
zip_path = None
userThemesPath = os.path.join(userThemesDir,"themes") + os.sep
zip_path = get_browse_dialog(dlg_type=1,heading=ADDON.getLocalizedString(32020),mask=".zip")
if zip_path and zip_path != "protocol://":
#create temp path
temp_path = xbmc.translatePath('special://temp/skinbackup/').decode("utf-8")
if xbmcvfs.exists(temp_path):
shutil.rmtree(temp_path)
xbmcvfs.mkdir(temp_path)
#unzip to temp
if "\\" in zip_path:
delim = "\\"
else:
delim = "/"
zip_temp = xbmc.translatePath('special://temp/' + zip_path.split(delim)[-1]).decode("utf-8")
xbmcvfs.copy(zip_path,zip_temp)
zfile = zipfile.ZipFile(zip_temp)
zfile.extractall(temp_path)
zfile.close()
xbmcvfs.delete(zip_temp)
dirs, files = xbmcvfs.listdir(temp_path)
for file in files:
if file.endswith(".theme") or file.endswith(".jpg"):
sourcefile = os.path.join(temp_path,file)
destfile = os.path.join(userThemesPath,file)
xbmcvfs.copy(sourcefile,destfile)
xbmcgui.Dialog().ok(ADDON.getLocalizedString(32022), ADDON.getLocalizedString(32021))
示例2: downloadURL
def downloadURL(self,targetdir,url,fname=None,final_target_dir=None):
if not fname:
fname = os.path.basename(urlparse.urlsplit(url)[2])
if not fname: fname = 'file'
f,e = os.path.splitext(fname)
fn = f
ct=0
while ct < 1000:
ct += 1
path = os.path.join(targetdir,fn + e)
finalPath = os.path.join(final_target_dir,fn + e)
if not xbmcvfs.exists(path): break
fn = f + str(ct)
else:
raise Exception
try:
self.current = 0
self.display = '{0}: {1}'.format(T(32100),os.path.basename(path))
self.prog.update(0,self.message,self.display)
t,ftype = self.getUrlFile(url,path,callback=self.progCallback) #@UnusedVariable
except:
ERROR('DOWNLOAD URL ERROR')
self.prog.close()
return (None,'')
finally:
self.prog.close()
if final_target_dir:
xbmcvfs.copy(path,finalPath)
xbmcvfs.delete(path)
return (os.path.basename(path),ftype)
示例3: 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)
示例4: delete_empty_folders
def delete_empty_folders(self, location):
"""
Delete the folder if it is empty. Presence of custom file extensions can be ignored while scanning.
To achieve this, edit the ignored file types setting in the addon settings.
Example:
success = delete_empty_folders(path)
:type location: str
:param location: The path to the folder to be deleted.
:rtype: bool
:return: True if the folder was deleted successfully, False otherwise.
"""
if not get_setting(delete_folders):
debug("Deleting of empty folders is disabled.")
return False
folder = self.unstack(location)[0] # Stacked paths should have the same parent, use any
debug("Checking if %r is empty" % folder)
ignored_file_types = [file_ext.strip() for file_ext in get_setting(ignore_extensions).split(",")]
debug("Ignoring file types %r" % ignored_file_types)
subfolders, files = xbmcvfs.listdir(folder)
debug("Contents of %r:\nSubfolders: %r\nFiles: %r" % (folder, subfolders, files))
empty = True
try:
for f in files:
_, ext = os.path.splitext(f)
if ext and not ext in ignored_file_types: # ensure f is not a folder and its extension is not ignored
debug("Found non-ignored file type %r" % ext)
empty = False
break
except OSError as oe:
debug("Error deriving file extension. Errno " + str(oe.errno), xbmc.LOGERROR)
empty = False
# Only delete directories if we found them to be empty (containing no files or filetypes we ignored)
if empty:
debug("Directory is empty and will be removed")
try:
# Recursively delete any subfolders
for f in subfolders:
debug("Deleting file at " + str(os.path.join(folder, f)))
self.delete_empty_folders(os.path.join(folder, f))
# Delete any files in the current folder
for f in files:
debug("Deleting file at " + str(os.path.join(folder, f)))
xbmcvfs.delete(os.path.join(folder, f))
# Finally delete the current folder
return xbmcvfs.rmdir(folder)
except OSError as oe:
debug("An exception occurred while deleting folders. Errno " + str(oe.errno), xbmc.LOGERROR)
return False
else:
debug("Directory is not empty and will not be removed")
return False
示例5: 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
示例6: _checkValidationFile
def _checkValidationFile(self,path):
result = False
#copy the file and open it
self.xbmc_vfs.put(path + "xbmcbackup.val",xbmc.translatePath(utils.data_dir() + "xbmcbackup_restore.val"))
vFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "xbmcbackup_restore.val"),'r')
jsonString = vFile.read()
vFile.close()
#delete after checking
xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "xbmcbackup_restore.val"))
try:
json_dict = json.loads(jsonString)
if(xbmc.getInfoLabel('System.BuildVersion') == json_dict['xbmc_version']):
result = True
else:
result = xbmcgui.Dialog().yesno(utils.getString(30085),utils.getString(30086),utils.getString(30044))
except ValueError:
#may fail on older archives
result = True
return result
示例7: _reset_all_shortcuts
def _reset_all_shortcuts( self ):
log( "### Resetting all shortcuts" )
log( repr( self.WARNING) )
dialog = xbmcgui.Dialog()
shouldRun = None
if self.WARNING is not None and self.WARNING.lower() == "false":
shouldRun = True
# Ask the user if they're sure they want to do this
if shouldRun is None:
shouldRun = dialog.yesno( __language__( 32037 ), __language__( 32038 ) )
if shouldRun:
for files in xbmcvfs.listdir( __datapath__ ):
# Try deleting all shortcuts
if files:
for file in files:
if file != "settings.xml":
file_path = os.path.join( __datapath__, file.decode( 'utf-8' ) ).encode( 'utf-8' )
if xbmcvfs.exists( file_path ):
try:
xbmcvfs.delete( file_path )
except:
print_exc()
log( "### ERROR could not delete file %s" % file[0] )
# Update home window property (used to automatically refresh type=settings)
xbmcgui.Window( 10000 ).setProperty( "skinshortcuts",strftime( "%Y%m%d%H%M%S",gmtime() ) )
# Reset all window properties (so menus will be reloaded)
self.reset_window_properties()
示例8: housekeeper
def housekeeper():
file_flag = xbmcvfs.exists("special://home/userdata/addon_data/script.audio.rhapsody/.clean_me")
files = [".albumdb.obj", ".artistdb.obj", ".genres.obj", ".rhapuser.obj"]
#now = time.time()
#print "current timestamp, type: %s %s" % (str(now), type(now))
if file_flag:
print "Found the clean_me file! Now let's delete it"
xbmcvfs.delete("special://home/userdata/addon_data/script.audio.rhapsody/.clean_me")
else:
print "No clean-me file. Let's check file dates"
for item in files:
f = "special://home/userdata/addon_data/script.audio.rhapsody/"+item
f_os = xbmc.translatePath(f)
print "Checking "+f_os
if xbmcvfs.exists(f):
modifiedTime = os.path.getmtime(f_os)
if modifiedTime < AGE_STAMP:
file_flag = True
print "%s is too old. Let's do some housekeeping." % (item)
break
if file_flag:
print "Deleting files..."
for item in files:
f = "special://home/userdata/addon_data/script.audio.rhapsody/"+item
f_os = xbmc.translatePath(f)
print "Deleting "+f_os
if xbmcvfs.exists(f):
xbmcvfs.delete(f)
print "Performed housekeeping"
else:
print "No housekeeping necessary"
示例9: extract_and_copy
def extract_and_copy(extraction=0):
for root, dirs, files in os.walk(extractPath, topdown=False):
for file in files:
dirfile = os.path.join(root, file)
# Sanitize filenames - converting them to ASCII - and remove them from folders
f = xbmcvfs.File(dirfile)
temp = f.read()
f.close()
xbmcvfs.delete(dirfile)
dirfile_with_path_name = normalizeString(os.path.relpath(dirfile, extractPath))
dirname, basename = os.path.split(dirfile_with_path_name)
dirname = re.sub(r"[/\\]{1,10}","-", dirname)
dirfile_with_path_name = "(%s)%s" % (dirname, basename) if len(dirname) else basename
new_dirfile = os.path.join(extractPath, dirfile_with_path_name)
with open(new_dirfile, "w") as f:
f.write(temp)
# Get the file extension
ext = os.path.splitext(new_dirfile)[1][1:].lower()
if ext in sub_ext and xbmcvfs.exists(new_dirfile):
if not new_dirfile in subtitles:
#Append the matching file
subtitles.append(new_dirfile)
elif ext in "rar zip" and not extraction:
# Extract compressed files, extracted priorly
xbmc.executebuiltin("XBMC.Extract(%s, %s)" % (new_dirfile, extractPath))
xbmc.sleep(1000)
extract_and_copy(1)
elif ext not in "idx":
xbmcvfs.delete(new_dirfile)
for dir in dirs:
dirfolder = os.path.join(root, dir)
xbmcvfs.rmdir(dirfolder)
示例10: check_login
def check_login():
login = __settings__.getSetting("Login")
password = __settings__.getSetting("Password")
if len(login) > 0:
http = GET(httpSiteUrl, httpSiteUrl)
if http is None:
return False
beautifulSoup = BeautifulSoup(http)
userPanel = beautifulSoup.find('a', 'b-header__user-profile')
if userPanel is None:
xbmcvfs.delete(cookiepath)
loginResponse = GET(httpSiteUrl + '/login.aspx', httpSiteUrl, {
'login': login,
'passwd': password,
'remember': 'on'
})
loginSoup = BeautifulSoup(loginResponse)
userPanel = loginSoup.find('a', 'b-header__user-profile')
if userPanel is None:
show_message('Login', 'Check login and password', 3000)
else:
return True
else:
return True
return False
示例11: delete_advancedxml
def delete_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)
mensagemok(translate(40000),translate(40066))
xbmc.executebuiltin("Container.Refresh")
示例12: 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")
示例13: UpdateFiles
def UpdateFiles():
log('UpdateFiles')
url='https://github.com/Lunatixz/XBMC_Addons/raw/master/zips/repository.lunatixz/repository.lunatixz-1.0.zip'
name = 'repository.lunatixz.zip'
MSG = 'Lunatixz Repository Installed'
path = xbmc.translatePath(os.path.join('special://home/addons','packages'))
addonpath = xbmc.translatePath(os.path.join('special://','home/addons'))
lib = os.path.join(path,name)
log('URL = ' + url)
# Delete old install package
try:
xbmcvfs.delete(lib)
log('deleted old package')
except:
pass
try:
download(url, lib, '')
log('downloaded new package')
all(lib,addonpath,'')
log('extracted new package')
except:
MSG = 'Failed to install Lunatixz Repository, Try Again Later'
pass
xbmc.executebuiltin("XBMC.UpdateLocalAddons()");
xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % ("PseudoTV Live", MSG, 1000, THUMB) )
return
示例14: removeFile
def removeFile(self, path):
if xbmcvfs.exists(path):
try:
print "Unlinking: %s" % path
xbmcvfs.delete(path)
except:
print "Exception: ",str(sys.exc_info())
示例15: writeconfig
def writeconfig():
system("systemctl stop service.net-snmp.service")
community = __addon__.getSetting("COMMUNITY")
location = __addon__.getSetting("LOCATION")
contact = __addon__.getSetting("CONTACT")
snmpversion = __addon__.getSetting("SNMPVERSION")
if xbmcvfs.exists(persistent):
xbmcvfs.delete(persistent)
file = xbmcvfs.File(config, 'w')
file.write('com2sec local default {}\n'.format(community))
file.write('group localgroup {} local\n'.format(snmpversion))
file.write('access localgroup "" any noauth exact all all none\n')
file.write('view all included .1 80\n')
file.write('syslocation {}\n'.format(location))
file.write('syscontact {}\n'.format(contact))
file.write('dontLogTCPWrappersConnects yes\n')
file.close()
if snmpversion == "v3":
snmppassword = __addon__.getSetting("SNMPPASSWORD")
snmpuser = __addon__.getSetting("SNMPUSER")
system("net-snmp-config --create-snmpv3-user -a {0} {1}".format(snmppassword,snmpuser))
system("systemctl start service.net-snmp.service")