Use xbmcvfs exists instead of os.path.exists

- Partially fixes #296
This commit is contained in:
tomkat83 2017-05-11 19:26:13 +02:00
parent 216159d96c
commit fd84d97a46
7 changed files with 60 additions and 30 deletions

View File

@ -39,16 +39,16 @@ import xml.etree.ElementTree as etree
from re import compile as re_compile, sub
from json import dumps
from urllib import urlencode, quote_plus, unquote
from os.path import basename, join, exists
from os.path import basename, join
import xbmcgui
from xbmc import sleep, executebuiltin
from xbmcvfs import mkdirs
from xbmcvfs import mkdirs, exists
import clientinfo as client
from downloadutils import DownloadUtils
from utils import window, settings, language as lang, tryDecode, tryEncode, \
DateToKodi
DateToKodi, exists_dir
from PlexFunctions import PMSHttpsEnabled
import plexdb_functions as plexdb
import variables as v
@ -2117,10 +2117,9 @@ class API():
continue
if fanartcount > maxfanarts:
break
if exists(tryEncode(entry['url'])):
allartworks['Backdrop'].append(
entry['url'].replace(' ', '%20'))
fanartcount += 1
allartworks['Backdrop'].append(
entry['url'].replace(' ', '%20'))
fanartcount += 1
return allartworks
def getSetArtwork(self, parentInfo=False):
@ -2344,7 +2343,7 @@ class API():
Returns the path to the downloaded subtitle or None
"""
if not exists(v.EXTERNAL_SUBTITLE_TEMP_PATH):
if not exists_dir(v.EXTERNAL_SUBTITLE_TEMP_PATH):
mkdirs(v.EXTERNAL_SUBTITLE_TEMP_PATH)
path = join(v.EXTERNAL_SUBTITLE_TEMP_PATH, filename)
r = DownloadUtils().downloadUrl(url, return_response=True)
@ -2547,11 +2546,17 @@ class API():
check = exists(tryEncode(path))
else:
# directories
if "\\" in path and not path.endswith('\\'):
# Add the missing backslash
check = exists(tryEncode(path + "\\"))
elif "/" in path and not path.endswith('/'):
check = exists(tryEncode(path + "/"))
if "\\" in path:
if not path.endswith('\\'):
# Add the missing backslash
check = exists_dir(tryEncode(path + "\\"))
else:
check = exists_dir(tryEncode(path))
else:
if not path.endswith('/'):
check = exists_dir(tryEncode(path + "/"))
else:
check = exists_dir(tryEncode(path))
if not check:
if forceCheck is False:

View File

@ -4,16 +4,16 @@
import logging
from json import dumps, loads
import requests
from os.path import exists
from shutil import rmtree
from urllib import quote_plus, unquote
from threading import Thread
from Queue import Queue, Empty
from xbmc import executeJSONRPC, sleep, translatePath
from xbmcvfs import exists
from utils import window, settings, language as lang, kodiSQL, tryEncode, \
ThreadMethods, ThreadMethodsAdditionalStop, dialog
ThreadMethods, ThreadMethodsAdditionalStop, dialog, exists_dir
# Disable annoying requests warnings
import requests.packages.urllib3
@ -229,7 +229,7 @@ class Artwork():
log.info("Resetting all cache data first")
# Remove all existing textures first
path = translatePath("special://thumbnails/")
if exists(path):
if exists_dir(path):
rmtree(path, ignore_errors=True)
# remove all existing data from texture DB

View File

@ -3,7 +3,7 @@
import logging
from shutil import copyfile
from os import walk
from os.path import basename, join, exists
from os.path import basename, join
from sys import argv
from urllib import urlencode
@ -13,7 +13,7 @@ from xbmcgui import ListItem
from xbmcvfs import mkdirs
from utils import window, settings, language as lang, dialog, tryEncode, \
CatchExceptions, JSONRPC
CatchExceptions, JSONRPC, exists_dir
import downloadutils
from PlexFunctions import GetPlexMetadata, GetPlexSectionResults, \
@ -499,7 +499,7 @@ def getVideoFiles(plexId, params):
path = path.replace('\\', '\\\\')
# Directory only, get rid of filename
path = path.replace(basename(path), '')
if exists(path):
if exists_dir(path):
for root, dirs, files in walk(path):
for directory in dirs:
item_path = join(root, directory)
@ -514,6 +514,7 @@ def getVideoFiles(plexId, params):
xbmcplugin.addDirectoryItem(handle=HANDLE,
url=file,
listitem=li)
break
else:
log.error('Kodi cannot access folder %s' % path)
xbmcplugin.endOfDirectory(HANDLE)
@ -537,7 +538,7 @@ def getExtraFanArt(plexid, plexPath):
# We need to store the images locally for this to work
# because of the caching system in xbmc
fanartDir = translatePath("special://thumbnails/plex/%s/" % plexid)
if not exists(fanartDir):
if not exists_dir(fanartDir):
# Download the images to the cache directory
mkdirs(fanartDir)
xml = GetPlexMetadata(plexid)

View File

@ -4,10 +4,10 @@ import logging
from threading import Thread
import Queue
from random import shuffle
from os.path import exists
import xbmc
import xbmcgui
from xbmcvfs import exists
from utils import window, settings, getUnixTimestamp, sourcesXML,\
ThreadMethods, ThreadMethodsAdditionalStop, LogTime, getScreensaver,\

View File

@ -3,11 +3,11 @@
###############################################################################
import logging
import threading
from os.path import exists
import xbmc
import xbmcgui
import xbmcaddon
from xbmcvfs import exists
from utils import window, settings, language as lang, ThreadMethods, \

View File

@ -21,10 +21,10 @@ from urllib import quote_plus
import xbmc
import xbmcaddon
import xbmcgui
from xbmcvfs import exists as kodi_exists, mkdirs
from xbmcvfs import exists, mkdirs, delete
from variables import DB_VIDEO_PATH, DB_MUSIC_PATH, DB_TEXTURE_PATH, \
DB_PLEX_PATH, KODI_PROFILE
DB_PLEX_PATH, KODI_PROFILE, KODIVERSION
###############################################################################
@ -92,6 +92,30 @@ def settings(setting, value=None):
return tryDecode(addon.getSetting(setting))
def exists_dir(path):
"""
Safe way to check whether the directory path exists already (broken in Kodi
<17)
Feed with encoded string
"""
if KODIVERSION >= 17:
answ = exists(path)
else:
dummyfile = join(path, 'dummyfile.txt')
try:
with open(dummyfile, 'w') as f:
f.write('text')
except IOError:
# folder does not exist yet
answ = 0
else:
# Folder exists. Delete file again.
delete(dummyfile)
answ = 1
return answ
def language(stringid):
# Central string retrieval
return ADDON.getLocalizedString(stringid)

View File

@ -4,13 +4,13 @@ import logging
from shutil import copytree
import xml.etree.ElementTree as etree
from os import remove, listdir
from os.path import exists, isfile, join
from os.path import isfile, join
import xbmc
from xbmcvfs import mkdirs
from xbmcvfs import mkdirs, exists
from utils import window, settings, language as lang, tryEncode, indent, \
normalize_nodes
normalize_nodes, exists_dir
import variables as v
###############################################################################
@ -75,14 +75,14 @@ class VideoNodes(object):
return
# Verify the video directory
if exists(path) is False:
if exists_dir(path) is False:
copytree(
src=xbmc.translatePath("special://xbmc/system/library/video"),
dst=xbmc.translatePath("special://profile/library/video"))
# Create the node directory
if mediatype != "photos":
if exists(nodepath) is False:
if exists_dir(nodepath) is False:
# folder does not exist yet
log.debug('Creating folder %s' % nodepath)
mkdirs(nodepath)
@ -388,7 +388,7 @@ class VideoNodes(object):
windowpath = "ActivateWindow(Video,%s,return)" % path
# Create the video node directory
if not exists(nodepath):
if not exists_dir(nodepath):
# We need to copy over the default items
copytree(
src=xbmc.translatePath("special://xbmc/system/library/video"),