1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright (C) 2013-2014 Team-XBMC
Copyright (C) 2014-2019 Team Kodi
This file is part of service.xbmc.versioncheck
SPDX-License-Identifier: GPL-3.0-or-later
See LICENSES/GPL-3.0-or-later.txt for more information.
"""
import platform
import sys
import xbmc # pylint: disable=import-error
import xbmcgui # pylint: disable=import-error
from .common import ADDON
from .common import ADDON_NAME
from .common import ADDON_VERSION
from .common import dialog_yes_no
from .common import localise
from .common import log
from .common import wait_for_abort
from .common import message_restart
from .common import message_upgrade_success
from .common import upgrade_message
from .common import upgrade_message2
from .json_interface import get_version_file_list
from .json_interface import get_installed_version
from .versions import compare_version
if sys.version_info[0] == 3 and sys.version_info[1] >= 8:
try:
from .distro import distro
DISTRIBUTION = distro.linux_distribution(full_distribution_name=False)[0].lower()
except (AttributeError, ImportError):
DISTRIBUTION = ''
else:
DISTRIBUTION = platform.linux_distribution(full_distribution_name=0)[0].lower() # pylint: disable=deprecated-method
if not DISTRIBUTION:
DISTRIBUTION = platform.uname()[0].lower()
def _version_check():
""" Check versions (non-linux)
:return: old, current, available, and stable versions
:rtype: bool / 'stable', dict, dict, dict
"""
# retrieve version_lists from supplied version file
version_list = get_version_file_list()
# retrieve version installed
version_installed = get_installed_version()
# compare installed and available
old_version, version_installed, version_available, version_stable = \
compare_version(version_installed, version_list)
return old_version, version_installed, version_available, version_stable
def _version_check_linux(packages):
""" Check package version on linux
:param packages: list of packages to check
:type packages: list of str
"""
if DISTRIBUTION in ['ubuntu', 'debian', 'linuxmint']:
try:
# try aptdaemon first
# pylint: disable=import-outside-toplevel
from .apt_daemon_handler import AptDaemonHandler
handler = AptDaemonHandler()
except: # pylint: disable=bare-except
# fallback to shell
# since we need the user password, ask to check for new version first
# pylint: disable=import-outside-toplevel
from .shell_handler_apt import ShellHandlerApt
handler = ShellHandlerApt(use_sudo=True)
if dialog_yes_no(32015):
pass
elif dialog_yes_no(32009, 32010):
log('disabling addon by user request')
ADDON.setSetting('versioncheck_enable', 'false')
return
if handler:
if handler.check_upgrade_available(packages[0]):
if upgrade_message(32012):
if ADDON.getSetting('upgrade_system') == 'false':
result = handler.upgrade_package(packages[0])
else:
result = handler.upgrade_system()
if result:
message_upgrade_success()
message_restart()
else:
log('Error during upgrade')
return
log('No upgrade available')
return
log('Error: no handler found')
return
log('Unsupported platform %s' % DISTRIBUTION)
sys.exit(0)
def _check_cryptography():
""" Check for cryptography package, and version
Python cryptography < 1.7 (still shipped with Ubuntu 16.04) has issues with
pyOpenSSL integration, leading to all sorts of weird bugs - check here to save
on some troubleshooting. This check may be removed in the future (when switching
to Python3?)
See https://github.com/pyca/pyopenssl/issues/542
"""
try:
import cryptography # pylint: disable=import-outside-toplevel
ver = cryptography.__version__
except ImportError:
# If the module is not found - no problem
return
ver_parts = list(map(int, ver.split('.')))
if len(ver_parts) < 2 or ver_parts[0] < 1 or (ver_parts[0] == 1 and ver_parts[1] < 7):
log('Python cryptography module version %s is too old, at least version 1.7 needed' % ver)
xbmcgui.Dialog().ok(
ADDON_NAME,
'[CR]'.join([localise(32040) % ver, localise(32041), localise(32042)])
)
def run():
""" Service entry-point
"""
_check_cryptography()
if ADDON.getSetting('versioncheck_enable') == 'false':
log('Disabled')
else:
log('Version %s started' % ADDON_VERSION)
if wait_for_abort(5):
sys.exit(0)
if (xbmc.getCondVisibility('System.Platform.Linux') and
ADDON.getSetting('upgrade_apt') == 'true'):
_version_check_linux(['kodi'])
else:
old_version, version_installed, version_available, version_stable = _version_check()
if old_version:
upgrade_message2(version_installed, version_available, version_stable, old_version)
|