def __download(url, path, addonsettings, progressdialog=None, chunk_size=8192, cancelhook=None, reporthook=None): response = urllib2.urlopen(url) downloadfile = os.path.join( path, os.path.basename(urlparse.urlsplit(url)[2])) total_size = response.info().getheader('Content-Length').strip() total_size = int(total_size) bytes_so_far = 0 result = True if os.path.exists(downloadfile): filename = os.path.basename(urlparse.urlsplit(url)[2]) if not utils.yesno(addonsettings.get_string(4000), addonsettings.get_string(4003) % filename, addonsettings.get_string(4006)): xbmc.log('[XBMC Download] File already exists. Do not overwrite.', xbmc.LOGINFO) return (False, downloadfile) file = open(downloadfile, 'wb') while 1: chunk = response.read(chunk_size) bytes_so_far += len(chunk) if not chunk: break if cancelhook and cancelhook(progressdialog): xbmc.log( '[XBMC Download] Download has been cancelled', xbmc.LOGINFO) if os.path.exists(downloadfile): os.remove(downloadfile) result = False break file.write(chunk) if reporthook: reporthook(addonsettings, progressdialog, downloadfile, bytes_so_far, chunk_size, total_size) file.close() return (result, downloadfile)
def remove_user(userid): if not xbmcutils.yesno("注销帐号", "是否注销帐号 %s?" % userid): return config = plugin.get_storage("config") users = config.setdefault("users", {}) users.pop(userid, None) if config.get("current_user") == userid: config["current_user"] = users.keys()[0] if users else None config.sync() userdata = plugin.get_storage("userdata") userdata.pop(userid, None) userdata.sync() plugin.notify("帐号已经注销成功", delay=3000) xbmcutils.refresh()
def remove_user(userid): if not xbmcutils.yesno('注销帐号', '是否注销帐号 %s?' % userid): return config = plugin.get_storage('config') users = config.setdefault('users', {}) users.pop(userid, None) if config.get('current_user') == userid: config['current_user'] = users.keys()[0] if users else None config.sync() userdata = plugin.get_storage('userdata') userdata.pop(userid, None) userdata.sync() plugin.notify('帐号已经注销成功', delay=3000) xbmcutils.refresh()
def __download(url, path, addonsettings, progressdialog=None, chunk_size=8192, cancelhook=None, reporthook=None): response = urllib2.urlopen(url) downloadfile = os.path.join(path, os.path.basename(urlparse.urlsplit(url)[2])) total_size = response.info().getheader('Content-Length').strip() total_size = int(total_size) bytes_so_far = 0 result = True if os.path.exists(downloadfile): filename = os.path.basename(urlparse.urlsplit(url)[2]) if not utils.yesno(addonsettings.get_string(4000), addonsettings.get_string(4003) % filename, addonsettings.get_string(4006)): xbmc.log('[XBMC Download] File already exists. Do not overwrite.', xbmc.LOGINFO) return (False, downloadfile) file = open(downloadfile, 'wb') while 1: chunk = response.read(chunk_size) bytes_so_far += len(chunk) if not chunk: break if cancelhook and cancelhook(progressdialog): xbmc.log('[XBMC Download] Download has been cancelled', xbmc.LOGINFO) if os.path.exists(downloadfile): os.remove(downloadfile) result = False break file.write(chunk) if reporthook: reporthook(addonsettings, progressdialog, downloadfile, bytes_so_far, chunk_size, total_size) file.close() return (result, downloadfile)