From 9133eef9002f285b10c9a5ecb1e19c9b8c8760fb Mon Sep 17 00:00:00 2001 From: heitbaum <6086324+heitbaum@users.noreply.github.com> Date: Sun, 18 Oct 2020 17:19:28 +1100 Subject: [PATCH 1/2] [python] update xbmc.translatePath() to xbmcvfs xbmc.translatePath is deprecated and might be removed in future kodi versions. Please use xbmcvfs.translatePath instead. The reference if from: xbmc/xbmc#17735 --- lib/inputstreamhelper/kodiutils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/inputstreamhelper/kodiutils.py b/lib/inputstreamhelper/kodiutils.py index aa107c47..b2a05e71 100644 --- a/lib/inputstreamhelper/kodiutils.py +++ b/lib/inputstreamhelper/kodiutils.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, unicode_literals from contextlib import contextmanager import xbmc +import xbmcvfs import xbmcaddon from xbmcgui import DialogProgress, DialogProgressBG from .unicodes import from_unicode, to_unicode @@ -60,7 +61,7 @@ def kodi_version_major(): def translate_path(path): """Translate special xbmc paths""" - return to_unicode(xbmc.translatePath(from_unicode(path))) + return to_unicode(xbmcvfs.translatePath(from_unicode(path))) def get_addon_info(key): From a4f965bf43321ae3ec3ac01f55982e6ac7985b10 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Sun, 18 Oct 2020 13:44:56 +0200 Subject: [PATCH 2/2] Support Kodi v18, add stub xbmcvfs.translatePath --- lib/inputstreamhelper/kodiutils.py | 10 ++++++++-- tests/xbmcvfs.py | 13 +++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/inputstreamhelper/kodiutils.py b/lib/inputstreamhelper/kodiutils.py index b2a05e71..73645149 100644 --- a/lib/inputstreamhelper/kodiutils.py +++ b/lib/inputstreamhelper/kodiutils.py @@ -5,9 +5,15 @@ from __future__ import absolute_import, division, unicode_literals from contextlib import contextmanager import xbmc -import xbmcvfs import xbmcaddon from xbmcgui import DialogProgress, DialogProgressBG + +try: # Kodi v19 or newer + from xbmcvfs import translatePath +except ImportError: # Kodi v18 and older + # pylint: disable=ungrouped-imports + from xbmc import translatePath + from .unicodes import from_unicode, to_unicode # NOTE: We need to explicitly add the add-on id here! @@ -61,7 +67,7 @@ def kodi_version_major(): def translate_path(path): """Translate special xbmc paths""" - return to_unicode(xbmcvfs.translatePath(from_unicode(path))) + return to_unicode(translatePath(from_unicode(path))) def get_addon_info(key): diff --git a/tests/xbmcvfs.py b/tests/xbmcvfs.py index dd6bb8ca..cbb65edd 100644 --- a/tests/xbmcvfs.py +++ b/tests/xbmcvfs.py @@ -82,3 +82,16 @@ def mkdirs(path): def rmdir(path): """A reimplementation of the xbmcvfs rmdir() function""" return os.rmdir(path) + + +def translatePath(path): + """A stub implementation of the xbmc translatePath() function""" + if path.startswith('special://home'): + return path.replace('special://home', os.path.join(os.getcwd(), 'tests/')) + if path.startswith('special://masterprofile'): + return path.replace('special://masterprofile', os.path.join(os.getcwd(), 'tests/userdata/')) + if path.startswith('special://profile'): + return path.replace('special://profile', os.path.join(os.getcwd(), 'tests/userdata/')) + if path.startswith('special://userdata'): + return path.replace('special://userdata', os.path.join(os.getcwd(), 'tests/userdata/')) + return path