# Path: resources/lib/settings.py
# def log(txt, loglevel=xbmc.LOGDEBUG):
#     if (ADDON.getSetting("logEnabled") == "true") or (loglevel != xbmc.LOGDEBUG):
#         if isinstance(txt, str):
#             txt = txt.decode("utf-8")
#         message = u'%s: %s' % (ADDON_ID, txt)
#         xbmc.log(msg=message.encode("utf-8"), level=loglevel)
# 
# Path: resources/lib/settings.py
# def os_path_join(dir, file):
#     # Check if it ends in a slash
#     if dir.endswith("/") or dir.endswith("\\"):
#         # Remove the slash character
#         dir = dir[:-1]
# 
#     # Convert each argument - if an error, then it will use the default value
#     # that was passed in
#     try:
#         dir = dir.decode("utf-8")
#     except:
#         pass
#     try:
#         file = file.decode("utf-8")
#     except:
#         pass
#     return os.path.join(dir, file)


import xbmc
import xbmcaddon
import xbmcvfs
import xbmcgui
from resources.lib.settings import log
from resources.lib.settings import os_path_join
# -*- coding: utf-8 -*-

# Import the common settings

ADDON = xbmcaddon.Addon(id='script.ebooks')


#########################
# Main
#########################
if __name__ == '__main__':
    log("EBookDeleteDb: Delete book database called (version %s)" % ADDON.getAddonInfo('version'))

    configPath = xbmc.translatePath(ADDON.getAddonInfo('profile'))
    databasefile = os_path_join(configPath, "ebooks_database.db")
    log("EBookDeleteDb: Database file location = %s" % databasefile)

    # If the database file exists, delete it
    if xbmcvfs.exists(databasefile):
        xbmcvfs.delete(databasefile)
        log("EBookDeleteDb: Removed database: %s" % databasefile)
    else:

# Path: resources/lib/settings.py
# def log(txt, loglevel=xbmc.LOGDEBUG):
#     if (ADDON.getSetting("logEnabled") == "true") or (loglevel != xbmc.LOGDEBUG):
#         if isinstance(txt, str):
#             txt = txt.decode("utf-8")
#         message = u'%s: %s' % (ADDON_ID, txt)
#         xbmc.log(msg=message.encode("utf-8"), level=loglevel)
# 
# Path: resources/lib/settings.py
# def os_path_join(dir, file):
#     # Check if it ends in a slash
#     if dir.endswith("/") or dir.endswith("\\"):
#         # Remove the slash character
#         dir = dir[:-1]
# 
#     # Convert each argument - if an error, then it will use the default value
#     # that was passed in
#     try:
#         dir = dir.decode("utf-8")
#     except:
#         pass
#     try:
#         file = file.decode("utf-8")
#     except:
#         pass
#     return os.path.join(dir, file)


# Path: deletedb.py
import xbmc
import xbmcaddon
import xbmcvfs
import xbmcgui
from resources.lib.settings import log
from resources.lib.settings import os_path_join

# -*- coding: utf-8 -*-

# Import the common settings

ADDON = xbmcaddon.Addon(id='script.ebooks')


#########################
# Main
#########################
if __name__ == '__main__':
    log("EBookDeleteDb: Delete book database called (version %s)" % ADDON.getAddonInfo('version'))

    configPath = xbmc.translatePath(ADDON.getAddonInfo('profile'))
    databasefile = os_path_join(configPath, "ebooks_database.db")
    log("EBookDeleteDb: Database file location = %s" % databasefile)

    # If the database file exists, delete it
    if xbmcvfs.exists(databasefile):
        xbmcvfs.delete(databasefile)
        log("EBookDeleteDb: Removed database: %s" % databasefile)
    else:

        log("EBookDeleteDb: No database exists: %s" % databasefile)