Skip to content

Commit bef0bff

Browse files
heitbaumdagwieers
andauthored
[python] update xbmc.translatePath() to xbmcvfs (#405)
* [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 * Support Kodi v18, add stub xbmcvfs.translatePath Co-authored-by: Dag Wieers <[email protected]>
1 parent a35feed commit bef0bff

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/inputstreamhelper/kodiutils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
import xbmc
88
import xbmcaddon
99
from xbmcgui import DialogProgress, DialogProgressBG
10+
11+
try: # Kodi v19 or newer
12+
from xbmcvfs import translatePath
13+
except ImportError: # Kodi v18 and older
14+
# pylint: disable=ungrouped-imports
15+
from xbmc import translatePath
16+
1017
from .unicodes import from_unicode, to_unicode
1118

1219
# NOTE: We need to explicitly add the add-on id here!
@@ -60,7 +67,7 @@ def kodi_version_major():
6067

6168
def translate_path(path):
6269
"""Translate special xbmc paths"""
63-
return to_unicode(xbmc.translatePath(from_unicode(path)))
70+
return to_unicode(translatePath(from_unicode(path)))
6471

6572

6673
def get_addon_info(key):

tests/xbmcvfs.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,16 @@ def mkdirs(path):
8282
def rmdir(path):
8383
"""A reimplementation of the xbmcvfs rmdir() function"""
8484
return os.rmdir(path)
85+
86+
87+
def translatePath(path):
88+
"""A stub implementation of the xbmc translatePath() function"""
89+
if path.startswith('special://home'):
90+
return path.replace('special://home', os.path.join(os.getcwd(), 'tests/'))
91+
if path.startswith('special://masterprofile'):
92+
return path.replace('special://masterprofile', os.path.join(os.getcwd(), 'tests/userdata/'))
93+
if path.startswith('special://profile'):
94+
return path.replace('special://profile', os.path.join(os.getcwd(), 'tests/userdata/'))
95+
if path.startswith('special://userdata'):
96+
return path.replace('special://userdata', os.path.join(os.getcwd(), 'tests/userdata/'))
97+
return path

0 commit comments

Comments
 (0)