def log_error(self, message):
"""
Add ERROR message to the Kodi log
:param message: message to write to the Kodi log
:type message: str
"""
self.log(message, xbmc.LOGERROR)
python类LOGERROR的实例源码
def error(self, message):
message = prep_log_message(message)
if xbmc:
self._log(message, xbmc.LOGERROR)
else:
self._log.error(message)
def showError(addonId, errorMessage):
"""
Shows an error to the user and logs it
Parameters:
addonId: the current addon id
message: the message to be shown
"""
notify(addonId, errorMessage)
xbmc.log(errorMessage, xbmc.LOGERROR)
def log_error(msg):
if is_standalone:
print msg
else:
xbmc.log(msg, level=xbmc.LOGERROR)
def log_error(msg):
if is_standalone:
print msg
else:
xbmc.log(msg, level=xbmc.LOGERROR)
def emit(self, record):
levels = {
logging.CRITICAL: xbmc.LOGFATAL,
logging.ERROR: xbmc.LOGERROR,
logging.WARNING: xbmc.LOGWARNING,
logging.INFO: xbmc.LOGINFO,
logging.DEBUG: xbmc.LOGDEBUG,
logging.NOTSET: xbmc.LOGNONE,
}
if get_setting_as_bool('debug'):
try:
xbmc.log(self.format(record), levels[record.levelno])
except UnicodeEncodeError:
xbmc.log(self.format(record).encode(
'utf-8', 'ignore'), levels[record.levelno])
def add_list_items(self, items, content=None, end=True, withNextPage=False):
if content:
xbmcplugin.setContent(plugin.handle, content)
list_items = []
for item in items:
if isinstance(item, Category):
category_items = item.getListItems()
for url, li, isFolder in category_items:
if url and li:
list_items.append((url, li, isFolder))
elif isinstance(item, BrowsableMedia):
url, li, isFolder = item.getListItem()
if url and li:
list_items.append((url, li, isFolder))
if withNextPage and len(items) > 0:
# Add folder for next page
try:
totalNumberOfItems = items[0]._totalNumberOfItems
nextOffset = items[0]._offset + self._config.pageSize
if nextOffset < totalNumberOfItems and len(items) >= self._config.pageSize:
path = urlsplit(sys.argv[0]).path or '/'
path = path.split('/')[:-1]
path.append(str(nextOffset))
url = '/'.join(path)
self.add_directory_item(_T(30244).format(pos1=nextOffset, pos2=min(nextOffset+self._config.pageSize, totalNumberOfItems)), plugin.url_for_path(url))
except:
log('Next Page for URL %s not set' % sys.argv[0], xbmc.LOGERROR)
if len(list_items) > 0:
xbmcplugin.addDirectoryItems(plugin.handle, list_items)
if end:
xbmcplugin.endOfDirectory(plugin.handle)
def __init__(self, pluginName, detailLevel=0, enableTidalApiLog=False):
''' Initialize Error Logging with a given Log Level
detailLevel = 0 : xbmc.LOGERROR and xbmc.LOGNOTICE
detailLevel = 1 : as level 0 plus xbmc.LOGWARNING
detailLevel = 2 : as level 1 plus xbmc.LOGDEBUG
detailLevel = 3 : as level 2 plus xbmc.LOGSEVERE
'''
self.pluginName = pluginName
self.detailLevel = detailLevel
self.debugServer = 'localhost'
# Set Log Handler for tidalapi
self.addTidalapiLogger(pluginName, enableDebug=enableTidalApiLog)
def logException(self, e, txt=''):
''' Logs an Exception as Error Message '''
try:
if txt:
if isinstance(txt, unicode):
txt = unidecode(txt)
xbmc.log(b"[%s] %s\n%s" % (self.pluginName, txt, str(e)), level=xbmc.LOGERROR)
logging.exception(str(e))
except:
pass
def user_playlist_clear(playlist_id):
dialog = xbmcgui.Dialog()
playlist = session.get_playlist(playlist_id)
ok = dialog.yesno(_T(30258), _T(30259).format(name=playlist.title, count=playlist.numberOfItems))
if ok:
xbmc.executebuiltin('ActivateWindow(busydialog)')
try:
session.user.remove_all_playlist_entries(playlist_id)
except Exception, e:
log(str(e), level=xbmc.LOGERROR)
traceback.print_exc()
xbmc.executebuiltin('Dialog.Close(busydialog)')
xbmc.executebuiltin('Container.Refresh()')
def user_playlist_add_item(item_type, item_id):
if item_type == 'playlist':
srcPlaylist = session.get_playlist(item_id)
if not srcPlaylist:
return
items = session.get_playlist_items(playlist=srcPlaylist)
# Sort Items by Artist, Title
sortMode = 'ALBUM' if ALBUM_PLAYLIST_TAG in srcPlaylist.description else 'LABEL'
items.sort(key=lambda line: line.getSortText(mode=sortMode).upper(), reverse=False)
items = ['%s' % item.id for item in items]
elif item_type.startswith('album'):
# Add First Track of the Album
tracks = session.get_album_items(item_id)
for track in tracks:
if track.available:
item_id = track.id
break
items = ['%s' % item_id]
else:
items = [item_id]
playlist = session.user.selectPlaylistDialog(allowNew=True)
if playlist:
xbmc.executebuiltin('ActivateWindow(busydialog)')
try:
session.user.add_playlist_entries(playlist=playlist, item_ids=items)
except Exception, e:
log(str(e), level=xbmc.LOGERROR)
traceback.print_exc()
xbmc.executebuiltin('Dialog.Close(busydialog)')
xbmc.executebuiltin('Container.Refresh()')
def user_playlist_remove_item(playlist_id, entry_no):
item_no = int('0%s' % entry_no) + 1
playlist = session.get_playlist(playlist_id)
ok = xbmcgui.Dialog().yesno(_T(30247) % playlist.title, _T(30241) % item_no)
if ok:
xbmc.executebuiltin('ActivateWindow(busydialog)')
try:
session.user.remove_playlist_entry(playlist, entry_no=entry_no)
except Exception, e:
log(str(e), level=xbmc.LOGERROR)
traceback.print_exc()
xbmc.executebuiltin('Dialog.Close(busydialog)')
xbmc.executebuiltin('Container.Refresh()')
def user_playlist_remove_id(playlist_id, item_id):
playlist = session.get_playlist(playlist_id)
ok = xbmcgui.Dialog().yesno(_T(30247) % playlist.title, _T(30246))
if ok:
xbmc.executebuiltin('ActivateWindow(busydialog)')
try:
session.user.remove_playlist_entry(playlist, item_id=item_id)
except Exception, e:
log(str(e), level=xbmc.LOGERROR)
traceback.print_exc()
xbmc.executebuiltin('Dialog.Close(busydialog)')
xbmc.executebuiltin('Container.Refresh()')
def showError(addonId, errorMessage):
"""
Shows an error to the user and logs it
Parameters:
addonId: the current addon id
message: the message to be shown
"""
notify(addonId, errorMessage)
xbmc.log(errorMessage, xbmc.LOGERROR)
def getControl(self, controlId):
if not controlId:
return None
try:
return super(TVGuide, self).getControl(controlId)
except Exception as detail:
#log(traceback.print_stack())
#xbmc.log("EXCEPTION: (script.tvguide.fullscreen) TVGuide.getControl %s" % detail, xbmc.LOGERROR)
if controlId in self.ignoreMissingControlIds:
return None
if not self.isClosing:
self.close()
return None
def eventLoop(self):
print 'Database.eventLoop() >>>>>>>>>> starting...'
while True:
self.event.wait()
self.event.clear()
event = self.eventQueue.pop(0)
command = event[0]
callback = event[1]
print 'Database.eventLoop() >>>>>>>>>> processing command: ' + command.__name__
try:
result = command(*event[2:])
self.eventResults[command.__name__] = result
if callback:
if self._initialize == command:
threading.Thread(name='Database callback', target=callback, args=[result]).start()
else:
threading.Thread(name='Database callback', target=callback).start()
if self._close == command:
del self.eventQueue[:]
break
except Exception as detail:
xbmc.log('Database.eventLoop() >>>>>>>>>> exception! %s = %s' % (detail,command.__name__), xbmc.LOGERROR)
xbmc.executebuiltin("ActivateWindow(Home)")
print 'Database.eventLoop() >>>>>>>>>> exiting...'
def log_error(self, message):
"""
Add ERROR message to the Kodi log
:param message: message to write to the Kodi log
:type message: str
"""
self.log(message, xbmc.LOGERROR)
def emit(self, record):
levels = {
logging.CRITICAL: xbmc.LOGFATAL,
logging.ERROR: xbmc.LOGERROR,
logging.WARNING: xbmc.LOGWARNING,
logging.INFO: xbmc.LOGINFO,
logging.DEBUG: xbmc.LOGDEBUG,
logging.NOTSET: xbmc.LOGNONE,
}
if get_setting_as_bool('debug'):
try:
xbmc.log(self.format(record), levels[record.levelno])
except UnicodeEncodeError:
xbmc.log(self.format(record).encode(
'utf-8', 'ignore'), levels[record.levelno])
def error(texto=""):
texto = " [" + get_caller() + "] " + encode_log(texto)
xbmc.log("######## ERROR #########", xbmc.LOGERROR)
xbmc.log(texto, xbmc.LOGERROR)
def log(msg):
"""log a message"""
xbmc.log('SKYSTREAMING: %s' % msg, xbmc.LOGERROR)