Ejemplo n.º 1
0
def connect_openvpn(config, restart=False, sudopassword=None):
    log_debug('Connecting OpenVPN configuration: [%s]' % config)
    global _state

    if _sudo and _sudopwdrequired and sudopassword is None:
        sudopassword = utils.keyboard(
            heading=_settings.get_string(3012), hidden=True)
    openvpn = vpn.OpenVPN(_openvpn, _settings.get_datapath(
        config), ip=_ip, port=_port, args=_args, sudo=_sudo, sudopwd=sudopassword, debug=(_settings['debug'] == 'true'))
    try:
        if restart:
            openvpn.disconnect()
            _state = disconnected
        openvpn.connect()
        display_notification(_settings.get_string(4002) % os.path.splitext(os.path.basename(config))[0])
        _state = connected
    except vpn.OpenVPNError as exception:
        if exception.errno == 1:
            _state = connected
            if utils.yesno(_settings.get_string(3002), _settings.get_string(3009), _settings.get_string(3010)):
                log_debug('User has decided to restart OpenVPN')
                connect_openvpn(config, True, sudopassword)
            else:
                log_debug('User has decided not to restart OpenVPN')
        else:
            utils.ok(_settings.get_string(
                3002), _settings.get_string(3011), exception.string)
            _state = failed
Ejemplo n.º 2
0
def import_ovpn():
    path = utils.browse_files(_settings.get_string(3000), mask='.ovpn|.conf')
    if path and os.path.exists(path) and os.path.isfile(path):
        log_debug('Import: [%s]' % path)
        name = utils.keyboard(heading=_settings.get_string(3001))
        if name and len(name) > 0:
            ovpn = _settings.get_datapath('%s.ovpn' % name)
            if os.path.exists(ovpn) and not utils.yesno(_settings.get_string(3002), _settings.get_string(3003)):
                    utils.ok(_settings.get_string(
                        3002), _settings.get_string(3004))
            else:
                log_debug('Copying [%s] to [%s]' % (path, ovpn))
                shutil.copyfile(path, ovpn)
        else:
            utils.ok(_settings.get_string(3002), _settings.get_string(3005))
Ejemplo n.º 3
0
def import_ovpn():
    path = utils.browse_files(_settings.get_string(3000), mask='.ovpn|.conf')
    if path and os.path.exists(path) and os.path.isfile(path):
        log_debug('Import: [%s]' % path)
        name = utils.keyboard(heading=_settings.get_string(3001))
        if name and len(name) > 0:
            ovpn = _settings.get_datapath('%s.ovpn' % name)
            if os.path.exists(ovpn) and not utils.yesno(
                    _settings.get_string(3002), _settings.get_string(3003)):
                utils.ok(_settings.get_string(3002),
                         _settings.get_string(3004))
            else:
                log_debug('Copying [%s] to [%s]' % (path, ovpn))
                shutil.copyfile(path, ovpn)
        else:
            utils.ok(_settings.get_string(3002), _settings.get_string(3005))
Ejemplo n.º 4
0
def connect_openvpn(config, restart=False, sudopassword=None):
    log_debug('Connecting OpenVPN configuration: [%s]' % config)
    global _state

    if _sudo and _sudopwdrequired and sudopassword is None:
        sudopassword = utils.keyboard(heading=_settings.get_string(3012),
                                      hidden=True)
    openvpn = vpn.OpenVPN(_openvpn,
                          _settings.get_datapath(config),
                          ip=_ip,
                          port=_port,
                          args=_args,
                          sudo=_sudo,
                          sudopwd=sudopassword,
                          debug=(_settings['debug'] == 'true'))
    try:
        if restart:
            openvpn.disconnect()
            _state = disconnected
        openvpn.connect()
        display_notification(
            _settings.get_string(4002) %
            os.path.splitext(os.path.basename(config))[0])
        _state = connected
    except vpn.OpenVPNError as exception:
        if exception.errno == 1:
            _state = connected
            if utils.yesno(_settings.get_string(3002),
                           _settings.get_string(3009),
                           _settings.get_string(3010)):
                log_debug('User has decided to restart OpenVPN')
                connect_openvpn(config, True, sudopassword)
            else:
                log_debug('User has decided not to restart OpenVPN')
        else:
            utils.ok(_settings.get_string(3002), _settings.get_string(3011),
                     exception.string)
            _state = failed
Ejemplo n.º 5
0
    def onAction(self, action):
        actionid = action.getId()
        # if actionid != 107:
        #    print 'onAction: %s' % actionid

        if actionid == _action_previous_menu or actionid == _action_nav_back:
            self.close()

        elif actionid == _action_select_item:
            if self._layertype == _layer_type_hybrid:
                self._layertype = 0
            else:
                self._layertype += 1
            self.set_tiles()

        elif actionid == _action_move_left or actionid == _action_move_right or actionid == _action_move_up or actionid == _action_move_down:
            if actionid == _action_move_left:
                self._centre_tilex -= 1
            elif actionid == _action_move_right:
                self._centre_tilex += 1
            elif actionid == _action_move_up:
                self._centre_tiley -= 1
            elif actionid == _action_move_down:
                self._centre_tiley += 1
            self._lat_deg, self._lon_deg = self.num2deg(
                self._centre_tilex, self._centre_tiley, self._zoom)
            self.set_tiles()

        elif actionid == _action_page_up or actionid == _action_page_down:
            if actionid == _action_page_up:
                if self._zoom < _map_max_zoom:
                    self._zoom += 1
            elif actionid == _action_page_down:
                if self._zoom > _map_min_zoom:
                    self._zoom -= 1
            self._centre_tilex, self._centre_tiley, self._home_pixelx, self._home_pixely = self.deg2num(
                self._lat_deg, self._lon_deg, self._zoom)
            self._home_column, self._home_row, self._home_pixelx, self._home_pixely = self.deg2num(
                self._home_lat_deg, self._home_lon_deg, self._zoom)
            self.set_tiles()

        elif actionid == _action_context_menu:
            query = utils.keyboard('', heading=self._settings.get_string(3001))
            if query and len(query) > 0:
                if self._settings.get('api') == 0:
                    osm = mapsapi.OpenStreetMapApi()
                else:
                    osm = mapsapi.MapQuestOpenApi()
                response = osm.search(query)
                if len(response) > 0:
                    index = 0
                    if len(response) > 1:
                        displaynames = []
                        for result in response:
                            displaynames.append(result['display_name'])
                        index = utils.select(self._settings.get_string(3002),
                                             displaynames)
                    if index >= 0 and index < len(response):
                        self._home_lat_deg = self._lat_deg = float(
                            response[index]['lat'])
                        self._home_lon_deg = self._lon_deg = float(
                            response[index]['lon'])
                        self._centre_tilex, self._centre_tiley, self._home_pixelx, self._home_pixely = self.deg2num(
                            self._lat_deg, self._lon_deg, self._zoom)
                        self._home_column = self._centre_tilex
                        self._home_row = self._centre_tiley
                        self.set_tiles()
                else:
                    utils.ok(self._settings.get_string(3000),
                             self._settings.get_string(3003) % query,
                             self._settings.get_string(3004))
Ejemplo n.º 6
0
        'artist': episode['podcastTitle']
    })
    if (__prompt__ and xbmc.Player().isPlayingAudio()):
        if (utils.yesno(__addonname__, __settings__.get_string(3001))):
            xbmc.Player().play(item=episode['url'], listitem=liz)
    else:
        xbmc.Player().play(item=episode['url'], listitem=liz)

# Refresh display.
elif __path__ == 'refresh':
    xbmc.executebuiltin('Container.Refresh')

# Search for a podcast.
elif __path__ == 'search':
    try:
        searchstring = utils.keyboard(heading=__settings__.get_string(3000))
        if (searchstring and len(searchstring) > 0):
            podcasts = __overcast__.search(searchstring)
            contextmenu = [(__settings__.get_string(1001),
                            'XBMC.RunPlugin(%s?path=refresh)' %
                            (__settings__.get_argv(0)))]
            for podcast in podcasts:
                liz = xbmcgui.ListItem(podcast['title'],
                                       iconImage=podcast['thumbURL'],
                                       thumbnailImage=podcast['artworkURL'])
                liz.addContextMenuItems(items=contextmenu, replaceItems=True)
                u = utils.add_params(root=__settings__.get_argv(0),
                                     params={
                                         'path':
                                         'podcast',
                                         'url':
    def onAction(self, action):
        actionid = action.getId()
        # if actionid != 107:
        #    print 'onAction: %s' % actionid

        if actionid == _action_previous_menu or actionid == _action_nav_back:
            self.close()

        elif actionid == _action_select_item:
            if self._layertype == _layer_type_hybrid:
                self._layertype = 0
            else:
                self._layertype += 1
            self.set_tiles()

        elif actionid == _action_move_left or actionid == _action_move_right or actionid == _action_move_up or actionid == _action_move_down:
            if actionid == _action_move_left:
                self._centre_tilex -= 1
            elif actionid == _action_move_right:
                self._centre_tilex += 1
            elif actionid == _action_move_up:
                self._centre_tiley -= 1
            elif actionid == _action_move_down:
                self._centre_tiley += 1
            self._lat_deg, self._lon_deg = self.num2deg(
                self._centre_tilex, self._centre_tiley, self._zoom)
            self.set_tiles()

        elif actionid == _action_page_up or actionid == _action_page_down:
            if actionid == _action_page_up:
                if self._zoom < _map_max_zoom:
                    self._zoom += 1
            elif actionid == _action_page_down:
                if self._zoom > _map_min_zoom:
                    self._zoom -= 1
            self._centre_tilex, self._centre_tiley, self._home_pixelx, self._home_pixely = self.deg2num(
                self._lat_deg, self._lon_deg, self._zoom)
            self._home_column, self._home_row, self._home_pixelx, self._home_pixely = self.deg2num(
                self._home_lat_deg, self._home_lon_deg, self._zoom)
            self.set_tiles()

        elif actionid == _action_context_menu:
            query = utils.keyboard('', heading=self._settings.get_string(3001))
            if query and len(query) > 0:
                if self._settings.get('api') == 0:
                    osm = mapsapi.OpenStreetMapApi()
                else:
                    osm = mapsapi.MapQuestOpenApi()
                response = osm.search(query)
                if len(response) > 0:
                    index = 0
                    if len(response) > 1:
                        displaynames = []
                        for result in response:
                            displaynames.append(result['display_name'])
                        index = utils.select(self._settings.get_string(3002), displaynames)
                    if index >= 0 and index < len(response):
                        self._home_lat_deg = self._lat_deg = float(
                            response[index]['lat'])
                        self._home_lon_deg = self._lon_deg = float(
                            response[index]['lon'])
                        self._centre_tilex, self._centre_tiley, self._home_pixelx, self._home_pixely = self.deg2num(
                            self._lat_deg, self._lon_deg, self._zoom)
                        self._home_column = self._centre_tilex
                        self._home_row = self._centre_tiley
                        self.set_tiles()
                else:
                    utils.ok(self._settings.get_string(3000), self._settings.get_string(3003) % query, self._settings.get_string(3004))
Ejemplo n.º 8
0
                add_custom_url(recent, presets=False)
        xbmcplugin.endOfDirectory(int(__settings__.get_argv(1)))

    except __tunein__.TuneInError as e:
        utils.ok(__addonname__, __settings__.get_string(3011),
                 __settings__.get_string(3010))
        log_error('TuneInError: %s %s' % (e.status, e.fault))
    except urllib2.URLError as e:
        utils.ok(__addonname__, __settings__.get_string(3009),
                 __settings__.get_string(3010))
        log_error('URLError: %s' % e)

# Search for a radio station.
elif __path__ == 'search':
    try:
        searchstring = utils.keyboard(heading=__settings__.get_string(3000))
        if (searchstring and len(searchstring) > 0):
            results = __tunein__.search(searchstring, 'standard')
            process_tunein_json(results)
            xbmcplugin.endOfDirectory(int(__settings__.get_argv(1)))

    except __tunein__.TuneInError as e:
        utils.ok(__addonname__, __settings__.get_string(3011),
                 __settings__.get_string(3010))
        log_error('TuneInError: %s %s' % (e.status, e.fault))
    except urllib2.URLError as e:
        utils.ok(__addonname__, __settings__.get_string(3009),
                 __settings__.get_string(3010))
        log_error('URLError: %s' % e)

# Play custom url.