# -*- coding: utf-8 -*-
import xbmcaddon
import os, sys
import xbmc
import xbmcvfs


__addon__ = xbmcaddon.Addon('context.medusa.failed')
__cwd__ = xbmcvfs.translatePath(__addon__.getAddonInfo('path'))
__resource__ = xbmcvfs.translatePath(os.path.join(__cwd__, 'resources', 'lib'))
__settings__ = xbmcaddon.Addon('context.medusa.failed')
__language__ = __settings__.getLocalizedString

sys.path.append(os.path.join(__cwd__, 'resources', 'lib'))
xbmc.log('Addon dir: ' + __cwd__, xbmc.LOGINFO)

from resources.lib import context


class MySettings(object):
    def __init__(self, url, username, password, debug):
        self.url = url + '/' if not url[-1] == '/' else url
        self.username = username
        self.password = password
        self.debug = debug


debug = bool(__settings__.getSetting('debug').lower() == 'true')
remote = False
if debug:
    try:
        import web_pdb; web_pdb.set_trace()
    except Exception as error:
        xbmc.log('Failed to import ptvsd, stopping debugging\n Error:' + str(error), xbmc.LOGWARNING)

if __name__ == '__main__':
    # Keep this file to a minimum, as Kodi
    # doesn't keep a compiled copy of this
    ADDON = xbmcaddon.Addon()

    context = context.MedusaFailed(
        MySettings(
            __settings__.getSetting('medusaurl'),
            __settings__.getSetting('username'),
            __settings__.getSetting('password'),
            __settings__.getSetting('debug')
        )
    )
    context.run()
