create a empty sources.xml to work with if one does not exist

This commit is contained in:
shaun 2015-03-15 15:18:34 +11:00
parent f5f1589aa6
commit 1971eb8655

View file

@ -53,7 +53,7 @@ def checkKodiSources():
xbmcvfs.mkdir(dataPath) xbmcvfs.mkdir(dataPath)
if not xbmcvfs.exists(movieLibrary + os.sep): if not xbmcvfs.exists(movieLibrary + os.sep):
xbmcvfs.mkdir(movieLibrary) xbmcvfs.mkdir(movieLibrary)
rebootRequired = addKodiSource("mediabrowser_movies",movieLibrary,"movies") rebootRequired = addKodiSource("mediabrowser_movies",movieLibrary,"movies")
if not xbmcvfs.exists(tvLibrary + os.sep): if not xbmcvfs.exists(tvLibrary + os.sep):
xbmcvfs.mkdir(tvLibrary) xbmcvfs.mkdir(tvLibrary)
rebootRequired = addKodiSource("mediabrowser_tvshows",tvLibrary,"tvshows") rebootRequired = addKodiSource("mediabrowser_tvshows",tvLibrary,"tvshows")
@ -86,31 +86,33 @@ def addKodiSource(name, path, type):
else: else:
error = True error = True
if error: # add it to sources.xml
# if adding to the database failed, manually add it to sources.xml sourcesFile = xbmc.translatePath( "special://profile/sources.xml" )
sourcesFile = xbmc.translatePath( "special://profile/sources.xml" )
if xbmcvfs.exists(sourcesFile): # add an emply sources file to work with
tree = ET.ElementTree(file=sourcesFile) if xbmcvfs.exists(sourcesFile) == False:
root = tree.getroot() sources = Element("sources")
videosources = root.find("video") video = SubElement(sources, "video")
#remove any existing entries for this path ET.ElementTree(sources).write(sourcesFile)
allsources = videosources.findall("source")
if allsources != None: if xbmcvfs.exists(sourcesFile):
for source in allsources: tree = ET.ElementTree(file=sourcesFile)
if source.find("name").text == name: root = tree.getroot()
videosources.remove(source) videosources = root.find("video")
# add the new source #remove any existing entries for this path
source = SubElement(videosources,'source') allsources = videosources.findall("source")
SubElement(source, "name").text = name if allsources != None:
SubElement(source, "path").text = path for source in allsources:
tree.write(sourcesFile) if source.find("name").text == name:
videosources.remove(source)
# add the new source
source = SubElement(videosources,'source')
SubElement(source, "name").text = name
SubElement(source, "path").text = path
tree.write(sourcesFile)
#return bool that reboot is needed and manual add of path to kodi #return bool that reboot is needed and manual add of path to kodi
return True #return True
else:
#return false that no reboot is needed
return False
def checkAuthentication(): def checkAuthentication():
#check authentication #check authentication