FIX: [droid] set "remote as keyboard" default to true
[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
21 import platform
22 import xbmc
23 import lib.common
24 from lib.common import log, dialog_yesno
25 from lib.common import upgrade_message as _upgrademessage
26
27 __addon__        = lib.common.__addon__
28 __addonversion__ = lib.common.__addonversion__
29 __addonname__    = lib.common.__addonname__
30 __addonpath__    = lib.common.__addonpath__
31 __icon__         = lib.common.__icon__
32 __localize__     = lib.common.__localize__
33
34
35 class Main:
36     def __init__(self):
37         linux = False
38         packages = []
39         if __addon__.getSetting("versioncheck_enable") == 'true' and not xbmc.getCondVisibility('System.HasAddon(os.openelec.tv)'):
40             if not sys.argv[0]:
41                 xbmc.executebuiltin('XBMC.AlarmClock(CheckAtBoot,XBMC.RunScript(service.xbmc.versioncheck, started),00:00:30,silent)')
42                 xbmc.executebuiltin('XBMC.AlarmClock(CheckWhileRunning,XBMC.RunScript(service.xbmc.versioncheck, started),24:00:00,silent,loop)')
43             elif sys.argv[0] and sys.argv[1] == 'started':
44                 if xbmc.getCondVisibility('System.Platform.Linux'):
45                     packages = ['xbmc']
46                     _versionchecklinux(packages)
47                 else:
48                     oldversion, msg = _versioncheck()
49                     if oldversion:
50                         _upgrademessage(msg, False)
51             else:
52                 pass
53                 
54 def _versioncheck():
55     # initial vars
56     from lib.jsoninterface import get_installedversion, get_versionfilelist
57     from lib.versions import compare_version
58     # retrieve versionlists from supplied version file
59     versionlist = get_versionfilelist()
60     # retrieve version installed
61     version_installed = get_installedversion()
62     # copmpare installed and available
63     oldversion, msg = compare_version(version_installed, versionlist)
64     return oldversion, msg
65
66
67 def _versionchecklinux(packages):
68     if platform.dist()[0].lower() in ['ubuntu', 'debian', 'linuxmint']:
69         handler = False
70         result = False
71         try:
72             # try aptdeamon first
73             from lib.aptdeamonhandler import AptdeamonHandler
74             handler = AptdeamonHandler()
75         except:
76             # fallback to shell
77             # since we need the user password, ask to check for new version first
78             from lib.shellhandlerapt import ShellHandlerApt
79             sudo = True
80             handler = ShellHandlerApt(sudo)
81             if dialog_yesno(32015):
82                 pass
83             elif dialog_yesno(32009, 32010):
84                 log("disabling addon by user request")
85                 __addon__.setSetting("versioncheck_enable", 'false')
86                 return
87
88         if handler:
89             if handler.check_upgrade_available(packages[0]):
90                 if _upgrademessage(32012, True):
91                     if __addon__.getSetting("upgrade_system") == "false":
92                         result = handler.upgrade_package(packages[0])
93                     else:
94                         result = handler.upgrade_system()
95                     if result:
96                         from lib.common import message_upgrade_success, message_restart
97                         message_upgrade_success()
98                         message_restart()
99                     else:
100                         log("Error during upgrade")
101         else:
102             log("Error: no handler found")
103     else:
104         log("Unsupported platform %s" %platform.dist()[0])
105         sys.exit(0)
106
107
108
109 if (__name__ == "__main__"):
110     log('Version %s started' % __addonversion__)
111     Main()