Merge pull request #4875 from koying/fixdroidremotekeyboard
[vuplus_xbmc] / addons / service.xbmc.versioncheck / service.py
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 #
4 #     Copyright (C) 2013 Team-XBMC
5 #
6 #    This program is free software: you can redistribute it and/or modify
7 #    it under the terms of the GNU General Public License as published by
8 #    the Free Software Foundation, either version 3 of the License, or
9 #    (at your option) any later version.
10 #
11 #    This program is distributed in the hope that it will be useful,
12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #    GNU General Public License for more details.
15 #
16 #    You should have received a copy of the GNU General Public License
17 #    along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 import platform
21 import xbmc
22 import lib.common
23 from lib.common import log, dialog_yesno
24 from lib.common import upgrade_message as _upgrademessage
25
26 __addon__        = lib.common.__addon__
27 __addonversion__ = lib.common.__addonversion__
28 __addonname__    = lib.common.__addonname__
29 __addonpath__    = lib.common.__addonpath__
30 __icon__         = lib.common.__icon__
31 oldversion = False
32
33 class Main:
34     def __init__(self):
35         linux = False
36         packages = []
37         if not xbmc.getCondVisibility('System.HasAddon(os.openelec.tv)'):
38             if not sys.argv[0]:
39                 xbmc.executebuiltin('XBMC.AlarmClock(CheckAtBoot,XBMC.RunScript(service.xbmc.versioncheck, started),00:00:30,silent)')
40                 xbmc.executebuiltin('XBMC.AlarmClock(CheckWhileRunning,XBMC.RunScript(service.xbmc.versioncheck, started),24:00:00,silent,loop)')
41             elif sys.argv[0] and sys.argv[1] == 'started':
42                 if xbmc.getCondVisibility('System.Platform.Linux') and __addon__.getSetting("upgrade_apt") == 'true':
43                     packages = ['xbmc']
44                     _versionchecklinux(packages)
45                 else:
46                     oldversion, msg = _versioncheck()
47                     if oldversion:
48                         _upgrademessage(msg, oldversion, False)
49             else:
50                 pass
51                 
52 def _versioncheck():
53     # initial vars
54     from lib.jsoninterface import get_installedversion, get_versionfilelist
55     from lib.versions import compare_version
56     # retrieve versionlists from supplied version file
57     versionlist = get_versionfilelist()
58     # retrieve version installed
59     version_installed = get_installedversion()
60     # copmpare installed and available
61     oldversion, msg = compare_version(version_installed, versionlist)
62     return oldversion, msg
63
64
65 def _versionchecklinux(packages):
66     if platform.dist()[0].lower() in ['ubuntu', 'debian', 'linuxmint']:
67         handler = False
68         result = False
69         try:
70             # try aptdeamon first
71             from lib.aptdeamonhandler import AptdeamonHandler
72             handler = AptdeamonHandler()
73         except:
74             # fallback to shell
75             # since we need the user password, ask to check for new version first
76             from lib.shellhandlerapt import ShellHandlerApt
77             sudo = True
78             handler = ShellHandlerApt(sudo)
79             if dialog_yesno(32015):
80                 pass
81             elif dialog_yesno(32009, 32010):
82                 log("disabling addon by user request")
83                 __addon__.setSetting("versioncheck_enable", 'false')
84                 return
85
86         if handler:
87             if handler.check_upgrade_available(packages[0]):
88                 if _upgrademessage(32012, oldversion, True):
89                     if __addon__.getSetting("upgrade_system") == "false":
90                         result = handler.upgrade_package(packages[0])
91                     else:
92                         result = handler.upgrade_system()
93                     if result:
94                         from lib.common import message_upgrade_success, message_restart
95                         message_upgrade_success()
96                         message_restart()
97                     else:
98                         log("Error during upgrade")
99         else:
100             log("Error: no handler found")
101     else:
102         log("Unsupported platform %s" %platform.dist()[0])
103         sys.exit(0)
104
105
106
107 if (__name__ == "__main__"):
108     log('Version %s started' % __addonversion__)
109     Main()