# Path: lib/libs/pykodi.py
# def log(message, level=xbmc.LOGDEBUG, tag=None):
#     if is_addon_watched() and level < xbmc.LOGNOTICE:
#         # Messages from this add-on are being watched, elevate to NOTICE so Kodi logs it
#         level_tag = _log_level_tag_lookup[level] + ': ' if level in _log_level_tag_lookup else ''
#         level = xbmc.LOGNOTICE
#     else:
#         level_tag = ''
# 
#     if isinstance(message, (dict, list)) and len(message) > 300:
#         message = str(message)
#     elif isinstance(message, unicode):
#         message = message.encode('utf-8')
#     elif not isinstance(message, str):
#         message = json.dumps(message, cls=UTF8PrettyJSONEncoder)
# 
#     addontag = ADDONID if not tag else ADDONID + ':' + tag
#     file_message = '%s[%s] %s' % (level_tag, addontag, scrub_message(message))
#     xbmc.log(file_message, level)
# 
# def localize(messageid):
#     if isinstance(messageid, basestring):
#         result = messageid
#     elif messageid >= 32000 and messageid < 33000:
#         result = get_main_addon().getLocalizedString(messageid)
#     else:
#         result = xbmc.getLocalizedString(messageid)
#     return result.encode('utf-8') if isinstance(result, unicode) else result


import xbmc
import xbmcgui
import xbmcvfs
import xml.etree.ElementTree as ET
from contextlib import closing
from lib.libs.pykodi import log, localize as L
        try:
            return ET.parse(as_xml, parser).getroot()
        except ET.ParseError:
            log("Can't parse advancedsettings.xml", xbmc.LOGWARNING)

def save_xml(advancedsettings):
    indent(advancedsettings)
    with closing(xbmcvfs.File(FILENAME, 'w')) as as_xml:
        ET.ElementTree(advancedsettings).write(as_xml, 'utf-8', True)

def save_backup():
    if xbmcvfs.exists(FILENAME):
        xbmcvfs.copy(FILENAME, FILENAME_BAK)
        result = xbmcvfs.exists(FILENAME_BAK)
        if result:
            xbmcgui.Dialog().notification("Artwork Beef", L(BACKUP_SUCCESSFUL))
        else:
            xbmcgui.Dialog().notification("Artwork Beef", L(BACKUP_UNSUCCESSFUL), xbmc.LOGWARNING)
        return result
    log("advancedsettings.xml doesn't exist, can't save backup", xbmc.LOGNOTICE)
    return True

def restore_backup():
    if xbmcvfs.exists(FILENAME_BAK):
        xbmcvfs.copy(FILENAME_BAK, FILENAME)
        xbmcvfs.delete(FILENAME_BAK)
        result = xbmcvfs.exists(FILENAME)
        if result:
            xbmcgui.Dialog().notification("Artwork Beef", L(RESTORE_SUCCESSFUL))
        else:

# Path: lib/libs/pykodi.py
# def log(message, level=xbmc.LOGDEBUG, tag=None):
#     if is_addon_watched() and level < xbmc.LOGNOTICE:
#         # Messages from this add-on are being watched, elevate to NOTICE so Kodi logs it
#         level_tag = _log_level_tag_lookup[level] + ': ' if level in _log_level_tag_lookup else ''
#         level = xbmc.LOGNOTICE
#     else:
#         level_tag = ''
# 
#     if isinstance(message, (dict, list)) and len(message) > 300:
#         message = str(message)
#     elif isinstance(message, unicode):
#         message = message.encode('utf-8')
#     elif not isinstance(message, str):
#         message = json.dumps(message, cls=UTF8PrettyJSONEncoder)
# 
#     addontag = ADDONID if not tag else ADDONID + ':' + tag
#     file_message = '%s[%s] %s' % (level_tag, addontag, scrub_message(message))
#     xbmc.log(file_message, level)
# 
# def localize(messageid):
#     if isinstance(messageid, basestring):
#         result = messageid
#     elif messageid >= 32000 and messageid < 33000:
#         result = get_main_addon().getLocalizedString(messageid)
#     else:
#         result = xbmc.getLocalizedString(messageid)
#     return result.encode('utf-8') if isinstance(result, unicode) else result


# Path: lib/advancedsettings.py
import xbmc
import xbmcgui
import xbmcvfs
import xml.etree.ElementTree as ET
from contextlib import closing
from lib.libs.pykodi import log, localize as L

        try:
            return ET.parse(as_xml, parser).getroot()
        except ET.ParseError:
            log("Can't parse advancedsettings.xml", xbmc.LOGWARNING)

def save_xml(advancedsettings):
    indent(advancedsettings)
    with closing(xbmcvfs.File(FILENAME, 'w')) as as_xml:
        ET.ElementTree(advancedsettings).write(as_xml, 'utf-8', True)

def save_backup():
    if xbmcvfs.exists(FILENAME):
        xbmcvfs.copy(FILENAME, FILENAME_BAK)
        result = xbmcvfs.exists(FILENAME_BAK)
        if result:
            xbmcgui.Dialog().notification("Artwork Beef", L(BACKUP_SUCCESSFUL))
        else:
            xbmcgui.Dialog().notification("Artwork Beef", L(BACKUP_UNSUCCESSFUL), xbmc.LOGWARNING)
        return result
    log("advancedsettings.xml doesn't exist, can't save backup", xbmc.LOGNOTICE)
    return True

def restore_backup():
    if xbmcvfs.exists(FILENAME_BAK):
        xbmcvfs.copy(FILENAME_BAK, FILENAME)
        xbmcvfs.delete(FILENAME_BAK)
        result = xbmcvfs.exists(FILENAME)
        if result:
            xbmcgui.Dialog().notification("Artwork Beef", L(RESTORE_SUCCESSFUL))
        else:

            xbmcgui.Dialog().notification("Artwork Beef", L(RESTORE_UNSUCCESSFUL), xbmc.LOGWARNING)