def _saveLineup(self, channelList, lineup):
c = self.conn.cursor()
# delete removed channels
c.execute('SELECT * FROM channels WHERE source=? AND lineup=?',
[self.source.KEY, lineup])
to_delete = []
for row in c:
station_id = row['id']
found = False
for channel in channelList:
if channel.id == station_id:
found = True
break
if not found:
xbmc.log('[%s] Removing Channel: %s from lineup: %s' % (
ADDON.getAddonInfo('id'), str(station_id), str(lineup)), xbmc.LOGDEBUG)
to_delete.append(station_id)
if to_delete:
c.execute('DELETE FROM channels WHERE id IN (%s)' %
','.join('?' * len(to_delete)), to_delete)
# Add new channels
for channel in channelList:
xbmc.log('[%s] Adding Channel: %s from lineup: %s' % (
ADDON.getAddonInfo('id'), str(channel.id), str(lineup)), xbmc.LOGDEBUG)
logo = get_logo(channel)
c.execute(
'INSERT OR IGNORE INTO channels(id, title, logo, stream_url, visible, weight, source, lineup) VALUES(?, ?, ?, ?, ?, (CASE ? WHEN -1 THEN (SELECT COALESCE(MAX(weight)+1, 0) FROM channels WHERE source=?) ELSE ? END), ?, ?)',
[channel.id, channel.title, logo, '', True, -1, self.source.KEY, -1, self.source.KEY, lineup])
c.execute("UPDATE sources SET channels_updated=? WHERE id=?",
[datetime.datetime.now(), self.source.KEY])
self.conn.commit()
python类delete()的实例源码
def deleteFile(file):
if xbmcvfs.exists(file):
xbmcvfs.delete(file)
def dltMovie(id, path, video):
kodiJsonRequest({'jsonrpc': '2.0', 'method': 'VideoLibrary.RemoveMovie', 'params': {'movieid': int(id)}, 'id': 1})
if separate_movies == "true":
xdir, xfil = xbmcvfs.listdir(path)
for fl in xfil:
xbmcvfs.delete(path + fl)
deleteDir(path)
else:
deleteVideo(path, video)
xbmc.executebuiltin('Notification(' + xbmc.getInfoLabel('ListItem.Label').replace(",",";") + ',' + lang(30002) + ')')
def maintenance_actions(self, context, re_match):
maint_type = re_match.group('maint_type')
action = re_match.group('action')
if action == 'clear':
if maint_type == 'function_cache':
if context.get_ui().on_remove_content(context.localize(30557)):
context.get_function_cache().clear()
context.get_ui().show_notification(context.localize(30575))
elif maint_type == 'search_cache':
if context.get_ui().on_remove_content(context.localize(30558)):
context.get_search_history().clear()
context.get_ui().show_notification(context.localize(30575))
elif action == 'delete':
_maint_files = {'function_cache': 'cache.sqlite',
'search_cache': 'search.sqlite',
'settings_xml': 'settings.xml'}
_file = _maint_files.get(maint_type, '')
if _file:
if 'sqlite' in _file:
_file_w_path = os.path.join(context._get_cache_path(), _file)
else:
_file_w_path = os.path.join(context._data_path, _file)
if context.get_ui().on_delete_content(_file):
success = xbmcvfs.delete(_file_w_path)
if success:
context.get_ui().show_notification(context.localize(30575))
else:
context.get_ui().show_notification(context.localize(30576))
def showResult(self, message, url=None):
if url:
imagefile = os.path.join(xbmc.translatePath(PROFILE),'%s.png'%str(url.split('/')[-2]))
qrIMG = pyqrcode.create(url)
qrIMG.png(imagefile, scale=10)
qr = QRCode( "script-loguploader-main.xml" , CWD, "default", image=imagefile, text=message)
qr.doModal()
del qr
xbmcvfs.delete(imagefile)
else:
dialog = xbmcgui.Dialog()
confirm = dialog.ok(ADDONNAME, message)
def clearKeysAndCerts(vpn_provider):
# Clear all of the keys for the given provider
keys = getUserKeys(vpn_provider)
for file in keys:
if xbmcvfs.exists(file): xbmcvfs.delete(file)
certs = getUserCerts(vpn_provider)
for file in certs:
if xbmcvfs.exists(file): xbmcvfs.delete(file)
def writeKeyPass(key_pass_name, password):
# Return the password being used for a given key file
try:
if xbmcvfs.exists(key_pass_name):
xbmcvfs.delete(key_pass_name)
debugTrace("Writing key password file " + key_pass_name)
pass_file = open(key_pass_name, 'w')
pass_file.write(password)
pass_file.close()
return True
except Exception as e:
errorTrace("vpnproviders.py", "Failed to write key password file to userdata")
errorTrace("vpnproviders.py", str(e))
return False
def cleanPassFiles():
# Delete the pass.txt file from all of the VPN provider directorys
for provider in providers:
filename = getAddonPath(True, provider + "/pass.txt")
if xbmcvfs.exists(filename) : xbmcvfs.delete(filename)
def cleanGeneratedFiles():
# Delete the GENERATED.txt file from all of the VPN provider directorys
for provider in providers:
filename = getAddonPath(True, provider + "/GENERATED.txt")
if xbmcvfs.exists(filename) : xbmcvfs.delete(filename)
def removeGeneratedFiles():
for provider in providers:
try:
files = getAddonList(provider, "*")
for file in files:
xbmcvfs.delete(file)
except:
pass
def generateSecureVPN():
# Can't use a template as SecureVPN use multiple everything.
# Copy the file to the target directory and strip it of user keys
existing_profiles = glob.glob(getUserDataPath("providers/SecureVPN" + "/*.ovpn"))
for connection in existing_profiles:
xbmcvfs.delete(connection)
# Get the list from the provider data directory
profiles = getProfileList("SecureVPN")
destination_path = getProviderPath("SecureVPN" + "/")
for profile in profiles:
shortname = profile[profile.index("SecureVPN")+10:]
shortname = shortname[:shortname.index(".")]
proto = "(UDP)"
filename = shortname + " " + proto + ".ovpn"
profile_file = open(profile, 'r')
output_file = open(destination_path + filename, 'w')
profile_contents = profile_file.readlines()
profile_file.close()
output = ""
i = 0
write = True;
for line in profile_contents:
line = line.strip(' \t\n\r')
if not (line == "" or line.startswith("#")) :
if "<key>" in line or "<cert>" in line: write = False
if "</key>" in line:
write = True
line = "key #USERKEY"
if "</cert>" in line:
write = True
line = "cert #USERCERT"
if write : output_file.write(line + "\n")
i = i + 1
output_file.close()
generateMetaData("SecureVPN", MINIMUM_LEVEL)
def fakeItTillYouMakeIt(fake):
try:
if fake:
if not fakeConnection():
f = open(getUserDataPath(fake_name),'w')
f.close()
else:
if fakeConnection():
xbmcvfs.delete(getUserDataPath(fake_name))
except Exception as e:
errorTrace("platform.py", "fakeItTillYouMakeIt " + str(fake) + " failed")
errorTrace("platform.py", str(e))
def remove_show(self, title):
"""Removes the DB entry & the strm files for the show given
Parameters
----------
title : :obj:`str`
Title of the show
Returns
-------
bool
Delete successfull
"""
title = re.sub(r'[?|$|!|:|#]', r'', title)
label = self.series_label
rep_str = self.db[label][title]['alt_title'].encode('utf-8')
folder = re.sub(
pattern=r'[?|$|!|:|#]',
repl=r'',
string=rep_str)
progress = xbmcgui.DialogProgress()
progress.create(self.kodi_helper.get_local_string(1210), title)
time.sleep(0.5)
del self.db[self.series_label][title]
self._update_local_db(filename=self.db_filepath, db=self.db)
show_dir = self.kodi_helper.check_folder_path(
path=os.path.join(self.tvshow_path, folder))
if xbmcvfs.exists(show_dir):
show_files = xbmcvfs.listdir(show_dir)[1]
episode_count_total = len(show_files)
step = round(100.0 / episode_count_total, 1)
percent = 100 - step
for filename in show_files:
progress.update(int(percent))
xbmcvfs.delete(os.path.join(show_dir, filename))
percent = percent - step
time.sleep(0.05)
xbmcvfs.rmdir(show_dir)
return True
return False
time.sleep(1)
progress.close()
def maintenance_actions(self, context, re_match):
maint_type = re_match.group('maint_type')
action = re_match.group('action')
if action == 'clear':
if maint_type == 'function_cache':
if context.get_ui().on_remove_content(context.localize(self.LOCAL_MAP['youtube.function.cache'])):
context.get_function_cache().clear()
context.get_ui().show_notification(context.localize(self.LOCAL_MAP['youtube.succeeded']))
elif maint_type == 'search_cache':
if context.get_ui().on_remove_content(context.localize(self.LOCAL_MAP['youtube.search.history'])):
context.get_search_history().clear()
context.get_ui().show_notification(context.localize(self.LOCAL_MAP['youtube.succeeded']))
elif action == 'reset':
if maint_type == 'access_manager':
if context.get_ui().on_yes_no_input(context.get_name(), context.localize(self.LOCAL_MAP['youtube.reset.access.manager.confirm'])):
try:
context.get_function_cache().clear()
access_manager = context.get_access_manager()
client = self.get_client(context)
if access_manager.has_refresh_token():
refresh_tokens = access_manager.get_refresh_token().split('|')
refresh_tokens = list(set(refresh_tokens))
for refresh_token in refresh_tokens:
client.revoke(refresh_token)
self.reset_client()
access_manager.update_access_token(access_token='', refresh_token='')
context.get_ui().refresh_container()
context.get_ui().show_notification(context.localize(self.LOCAL_MAP['youtube.succeeded']))
except:
context.get_ui().show_notification(context.localize(self.LOCAL_MAP['youtube.failed']))
elif action == 'delete':
_maint_files = {'function_cache': 'cache.sqlite',
'search_cache': 'search.sqlite',
'settings_xml': 'settings.xml'}
_file = _maint_files.get(maint_type, '')
if _file:
if 'sqlite' in _file:
_file_w_path = os.path.join(context._get_cache_path(), _file)
else:
_file_w_path = os.path.join(context._data_path, _file)
if context.get_ui().on_delete_content(_file):
success = xbmcvfs.delete(_file_w_path)
if success:
context.get_ui().show_notification(context.localize(self.LOCAL_MAP['youtube.succeeded']))
else:
context.get_ui().show_notification(context.localize(self.LOCAL_MAP['youtube.failed']))