[addons] sync addons to repo
[vuplus_xbmc] / addons / service.xbmc.versioncheck / lib / versions.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 from lib.common import log
20
21 def compare_version(version_installed, versionlist):
22     # Create seperate version lists
23     versionlist_stable = versionlist['releases']['stable']
24     versionlist_rc = versionlist['releases']['releasecandidate']
25     versionlist_beta = versionlist['releases']['beta']
26     versionlist_alpha = versionlist['releases']['alpha']
27     versionlist_prealpha = versionlist['releases']['prealpha'] 
28     ### Check to upgrade to newest available stable version
29     # check on smaller major version. Smaller version than available always notify
30     oldversion = False
31     msg = ''
32     if version_installed['major'] < int(versionlist_stable[0]['major']):
33         msg = 32003
34         oldversion = True
35         log("Version available  %s" %versionlist_stable[0])
36
37     # check on same major version installed and available
38     elif version_installed['major'] == int(versionlist_stable[0]['major']):
39         # check on smaller minor version
40         if version_installed['minor'] < int(versionlist_stable[0]['minor']):
41             msg = 32003
42             oldversion = True
43             log("Version available  %s" %versionlist_stable[0])
44         # check if not installed a stable so always notify
45         elif version_installed['minor'] == int(versionlist_stable[0]['minor']) and version_installed['tag'] != "stable":
46             msg = 32008
47             oldversion = True
48             log("Version available  %s" %versionlist_stable[0])
49         else:
50             log("Last available stable installed")
51
52     ### Check to upgrade to newest available RC version if not installed stable
53     ## Check also oldversion hasn't been set true by previous check because if so this need to be skipped
54     if not oldversion and version_installed['tag'] != "stable":
55         if 'revision' in version_installed.keys():
56             # only check on equal or lower major because newer installed beta/alpha/prealpha version will be higher
57             if versionlist_rc and version_installed['major'] <= int(versionlist_rc[0]['major']):
58                 if version_installed['revision'] <= versionlist_rc[0]['revision']:
59                     msg = 32004
60                     oldversion = True
61                     log("Version available  %s" %versionlist_rc[0])
62
63             # exclude if installed RC on checking for newer beta
64             if not oldversion and versionlist_beta and version_installed['tag'] not in ["releasecandidate"]:
65                 if version_installed['major'] <= int(versionlist_beta[0]['major']):
66                     if version_installed['revision'] < versionlist_beta[0]['revision']:
67                         msg = 32005
68                         oldversion = True
69                         log("Version available  %s" %versionlist_beta[0])
70         
71             # exclude if installed RC or beta on checking for newer alpha
72             if not oldversion and versionlist_alpha and version_installed['tag'] not in ["releasecandidate", "beta"]:
73                 if version_installed['major'] <= int(versionlist_alpha[0]['major']):
74                     if version_installed['revision'] < versionlist_alpha[0]['revision']:
75                         msg = 32006
76                         oldversion = True
77                         log("Version available  %s" %versionlist_alpha[0])
78
79             # exclude if installed RC, beta or alpha on checking for newer prealpha
80             if not oldversion and versionlist_prealpha and version_installed['tag'] not in ["releasecandidate", "beta", "alpha"]:
81                 if version_installed['major'] <= int(versionlist_prealpha[0]['major']):
82                     if  version_installed['revision'] < versionlist_prealpha[0]['revision']:
83                         msg = 32007
84                         oldversion = True
85                         log("Version available  %s" %versionlist_prealpha[0])
86
87         log("Nothing to see here, move along. Running a latest non stable release")
88         # Nothing to see here, move along
89     else:
90         log("Nothing to see here, move along. Running a stable release")
91         # Nothing to see here, move along
92         pass
93     return oldversion, msg