Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/inputstreamhelper/kodiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
import xbmc
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!
Expand Down Expand Up @@ -60,7 +67,7 @@ def kodi_version_major():

def translate_path(path):
"""Translate special xbmc paths"""
return to_unicode(xbmc.translatePath(from_unicode(path)))
return to_unicode(translatePath(from_unicode(path)))


def get_addon_info(key):
Expand Down
13 changes: 13 additions & 0 deletions tests/xbmcvfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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