Dedicated function to check whether directory exists
This commit is contained in:
parent
cbfa41de99
commit
a258f969ab
4 changed files with 25 additions and 18 deletions
|
@ -177,7 +177,7 @@ class Artwork():
|
|||
self.logMsg("Resetting all cache data first", 1)
|
||||
# Remove all existing textures first
|
||||
path = xbmc.translatePath("special://thumbnails/").decode('utf-8')
|
||||
if xbmcvfs.exists(path):
|
||||
if utils.IfExists(path):
|
||||
allDirs, allFiles = xbmcvfs.listdir(path)
|
||||
for dir in allDirs:
|
||||
allDirs, allFiles = xbmcvfs.listdir(path+dir)
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
import json
|
||||
import os
|
||||
import sys
|
||||
import urlparse
|
||||
|
||||
import xbmc
|
||||
import xbmcaddon
|
||||
|
@ -399,7 +398,7 @@ def getThemeMedia():
|
|||
library = xbmc.translatePath(
|
||||
"special://profile/addon_data/plugin.video.plexkodiconnect/library/").decode('utf-8')
|
||||
# Create library directory
|
||||
if not xbmcvfs.exists(library):
|
||||
if not utils.IfExists(library):
|
||||
xbmcvfs.mkdir(library)
|
||||
|
||||
# Set custom path for user
|
||||
|
|
|
@ -25,6 +25,27 @@ import xbmcvfs
|
|||
addonName = xbmcaddon.Addon().getAddonInfo('name')
|
||||
|
||||
|
||||
def IfExists(path):
|
||||
"""
|
||||
Kodi's xbmcvfs.exists is broken - it caches the results for directories.
|
||||
|
||||
path: path to a directory (with a slash at the end)
|
||||
|
||||
Returns True if path exists, else false
|
||||
"""
|
||||
dummyfile = os.path.join(path, 'dummyfile.txt').encode('utf-8')
|
||||
try:
|
||||
etree.ElementTree(etree.Element('test')).write(dummyfile)
|
||||
except:
|
||||
# folder does not exist yet
|
||||
answer = False
|
||||
else:
|
||||
# Folder exists. Delete file again.
|
||||
xbmcvfs.delete(dummyfile)
|
||||
answer = True
|
||||
return answer
|
||||
|
||||
|
||||
def LogTime(func):
|
||||
"""
|
||||
Decorator for functions and methods to log the time it took to run the code
|
||||
|
|
|
@ -68,30 +68,17 @@ class VideoNodes(object):
|
|||
# KODI BUG
|
||||
# Kodi caches the result of exists for directories
|
||||
# so try creating a file
|
||||
dummyfile = ospath.join(path, 'dummyfile.txt').encode('utf-8')
|
||||
try:
|
||||
etree.ElementTree(etree.Element('test')).write(dummyfile)
|
||||
except:
|
||||
# path does not exist yet
|
||||
if utils.IfExists(path) is False:
|
||||
shutil.copytree(
|
||||
src=xbmc.translatePath("special://xbmc/system/library/video").decode('utf-8'),
|
||||
dst=xbmc.translatePath("special://profile/library/video").decode('utf-8'))
|
||||
else:
|
||||
# path exists - delete dummy file
|
||||
xbmcvfs.delete(dummyfile)
|
||||
|
||||
# Create the node directory
|
||||
if mediatype != "photo":
|
||||
dummyfile = ospath.join(nodepath, 'dummyfile.txt').encode('utf-8')
|
||||
try:
|
||||
etree.ElementTree(etree.Element('test')).write(dummyfile)
|
||||
except:
|
||||
if utils.IfExists(nodepath) is False:
|
||||
# folder does not exist yet
|
||||
self.logMsg('Creating folder %s' % nodepath, 1)
|
||||
xbmcvfs.mkdirs(nodepath.encode('utf-8'))
|
||||
else:
|
||||
# path exists - delete dummy file
|
||||
xbmcvfs.delete(dummyfile)
|
||||
if delete:
|
||||
dirs, files = xbmcvfs.listdir(nodepath.encode('utf-8'))
|
||||
for file in files:
|
||||
|
|
Loading…
Add table
Reference in a new issue