Merge pull request #4875 from koying/fixdroidremotekeyboard
[vuplus_xbmc] / addons / service.xbmc.versioncheck / lib / jsoninterface.py
1 # -*- coding: utf-8 -*-
2 #
3 #     Copyright (C) 2013 Team-XBMC
4 #
5 #    This program is free software: you can redistribute it and/or modify
6 #    it under the terms of the GNU General Public License as published by
7 #    the Free Software Foundation, either version 3 of the License, or
8 #    (at your option) any later version.
9 #
10 #    This program is distributed in the hope that it will be useful,
11 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #    GNU General Public License for more details.
14 #
15 #    You should have received a copy of the GNU General Public License
16 #    along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #
18
19 import os
20 import sys
21 import xbmc
22 import xbmcaddon
23 import xbmcvfs
24 import lib.common
25 from lib.common import log
26
27 __addonpath__    = lib.common.__addonpath__
28
29 import json as jsoninterface
30
31 def get_installedversion():
32     # retrieve current installed version
33     json_query = xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "Application.GetProperties", "params": {"properties": ["version", "name"]}, "id": 1 }')
34     json_query = unicode(json_query, 'utf-8', errors='ignore')
35     json_query = jsoninterface.loads(json_query)
36     version_installed = []
37     if json_query.has_key('result') and json_query['result'].has_key('version'):
38         version_installed  = json_query['result']['version']
39     return version_installed
40     
41 def get_versionfilelist():
42     # retrieve versionlists from supplied version file
43     version_file = os.path.join(__addonpath__, 'resources/versions.txt')
44     # Eden didn't have xbmcvfs.File()
45     if xbmcaddon.Addon('xbmc.addon').getAddonInfo('version') < "11.9.3":
46         file = open(version_file, 'r')
47     else:
48         file = xbmcvfs.File(version_file)
49     data = file.read()
50     file.close()
51     version_query = unicode(data, 'utf-8', errors='ignore')
52     version_query = jsoninterface.loads(version_query)
53     return version_query