Merge pull request #7918 from Montellese/fix_modal_video_refreshing
[xbmc.git] / addons / service.xbmc.versioncheck / service.py
blobd69cbc07112625f1be65eb96cfbdc099cb57f1b6
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 # Copyright (C) 2013 Team-XBMC
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.
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.
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/>.
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 from lib.common import upgrade_message2 as _upgrademessage2
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 oldversion = False
34 class Main:
35 def __init__(self):
36 linux = False
37 packages = []
38 xbmc.sleep(5000)
39 if xbmc.getCondVisibility('System.Platform.Linux') and __addon__.getSetting("upgrade_apt") == 'true':
40 packages = ['kodi']
41 _versionchecklinux(packages)
42 else:
43 oldversion, version_installed, version_available, version_stable = _versioncheck()
44 if oldversion:
45 _upgrademessage2( version_installed, version_available, version_stable, oldversion, False)
47 def _versioncheck():
48 # initial vars
49 from lib.jsoninterface import get_installedversion, get_versionfilelist
50 from lib.versions import compare_version
51 # retrieve versionlists from supplied version file
52 versionlist = get_versionfilelist()
53 # retrieve version installed
54 version_installed = get_installedversion()
55 # copmpare installed and available
56 oldversion, version_installed, version_available, version_stable = compare_version(version_installed, versionlist)
57 return oldversion, version_installed, version_available, version_stable
60 def _versionchecklinux(packages):
61 if platform.dist()[0].lower() in ['ubuntu', 'debian', 'linuxmint']:
62 handler = False
63 result = False
64 try:
65 # try aptdeamon first
66 from lib.aptdeamonhandler import AptdeamonHandler
67 handler = AptdeamonHandler()
68 except:
69 # fallback to shell
70 # since we need the user password, ask to check for new version first
71 from lib.shellhandlerapt import ShellHandlerApt
72 sudo = True
73 handler = ShellHandlerApt(sudo)
74 if dialog_yesno(32015):
75 pass
76 elif dialog_yesno(32009, 32010):
77 log("disabling addon by user request")
78 __addon__.setSetting("versioncheck_enable", 'false')
79 return
81 if handler:
82 if handler.check_upgrade_available(packages[0]):
83 if _upgrademessage(32012, oldversion, True):
84 if __addon__.getSetting("upgrade_system") == "false":
85 result = handler.upgrade_package(packages[0])
86 else:
87 result = handler.upgrade_system()
88 if result:
89 from lib.common import message_upgrade_success, message_restart
90 message_upgrade_success()
91 message_restart()
92 else:
93 log("Error during upgrade")
94 else:
95 log("Error: no handler found")
96 else:
97 log("Unsupported platform %s" %platform.dist()[0])
98 sys.exit(0)
102 if (__name__ == "__main__"):
103 log('Version %s started' % __addonversion__)
104 Main()