mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-14 20:35:48 +01:00
completely changed this class, default no longer matters. Just restore settings that differ from current, ignore default flags closes #154
This commit is contained in:
parent
1f6324b2d5
commit
a4bb3f3feb
@ -323,7 +323,7 @@ class XbmcBackup:
|
|||||||
|
|
||||||
|
|
||||||
#update the guisettings information (or what we can from it)
|
#update the guisettings information (or what we can from it)
|
||||||
gui_settings = GuiSettingsManager('special://home/userdata/guisettings.xml')
|
gui_settings = GuiSettingsManager()
|
||||||
gui_settings.run()
|
gui_settings.run()
|
||||||
|
|
||||||
#call update addons to refresh everything
|
#call update addons to refresh everything
|
||||||
|
@ -6,49 +6,59 @@ import xbmc,xbmcvfs
|
|||||||
|
|
||||||
|
|
||||||
class GuiSettingsManager:
|
class GuiSettingsManager:
|
||||||
settingsFile = None
|
|
||||||
doc = None
|
doc = None
|
||||||
|
|
||||||
def __init__(self,settingsFile):
|
def __init__(self):
|
||||||
self._readFile(xbmc.translatePath(settingsFile))
|
#first make a copy of the file
|
||||||
|
xbmcvfs.copy(xbmc.translatePath('special://home/userdata/guisettings.xml'), xbmc.translatePath("special://home/userdata/guisettings.xml.restored"))
|
||||||
|
|
||||||
|
#read in the copy
|
||||||
|
self._readFile(xbmc.translatePath('special://home/userdata/guisettings.xml.restored'))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
#get a list of all the settings we can manipulate via json
|
#get a list of all the settings we can manipulate via json
|
||||||
json_response = json.loads(xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.GetSettings","params":{"level":"advanced"}}'))
|
json_response = json.loads(xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.GetSettings","params":{"level":"advanced"}}'))
|
||||||
|
|
||||||
settings = json_response['result']['settings']
|
settings = json_response['result']['settings']
|
||||||
settingsAllowed = []
|
currentSettings = {}
|
||||||
|
|
||||||
for aSetting in settings:
|
for aSetting in settings:
|
||||||
settingsAllowed.append(aSetting['id'])
|
if('value' in aSetting):
|
||||||
|
currentSettings[aSetting['id']] = aSetting['value']
|
||||||
|
|
||||||
#parse the existing xml file and get all the settings we need to update
|
#parse the existing xml file and get all the settings we need to restore
|
||||||
updateSettings = self.__parseNodes(self.doc.getElementsByTagName('setting'))
|
restoreSettings = self.__parseNodes(self.doc.getElementsByTagName('setting'))
|
||||||
|
|
||||||
|
#get a list where the restore setting value != the current value
|
||||||
|
updateSettings = {k: v for k, v in restoreSettings.items() if (k in currentSettings and currentSettings[k] != v)}
|
||||||
|
|
||||||
#go through all the found settings and update them
|
#go through all the found settings and update them
|
||||||
for aSetting in updateSettings:
|
jsonObj = {"jsonrpc":"2.0","id":1,"method":"Settings.SetSettingValue","params":{"setting":"","value":""}}
|
||||||
if(aSetting.name in settingsAllowed):
|
for anId, aValue in updateSettings.items():
|
||||||
utils.log("updating: " + aSetting.name + ", value: " + aSetting.value)
|
utils.log("updating: " + anId + ", value: " + str(aValue))
|
||||||
|
|
||||||
#check for boolean and numeric values
|
jsonObj['params']['setting'] = anId
|
||||||
if(aSetting.value.isdigit() or (aSetting.value == 'true' or aSetting.value == 'false')):
|
jsonObj['params']['value'] = aValue
|
||||||
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.SetSettingValue","params":{"setting":"' + aSetting.name + '","value":' + aSetting.value + '}}')
|
|
||||||
else:
|
|
||||||
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.SetSettingValue","params":{"setting":"' + aSetting.name + '","value":"' + utils.encode(aSetting.value) + '"}}')
|
|
||||||
|
|
||||||
#make a copy of the guisettings file to make user based restores easier
|
xbmc.executeJSONRPC(json.dumps(jsonObj))
|
||||||
xbmcvfs.copy(self.settingsFile, xbmc.translatePath("special://home/userdata/guisettings.xml.restored"))
|
|
||||||
|
|
||||||
def __parseNodes(self,nodeList):
|
def __parseNodes(self,nodeList):
|
||||||
result = []
|
result = {}
|
||||||
|
|
||||||
for node in nodeList:
|
for node in nodeList:
|
||||||
#only add if it's not a default setting
|
nodeValue = ''
|
||||||
if('default' not in node.attributes.keys()):
|
if(node.firstChild != None):
|
||||||
aSetting = SettingNode(node.getAttribute('id'),node.firstChild.nodeValue)
|
nodeValue = node.firstChild.nodeValue
|
||||||
aSetting.isDefault = False
|
|
||||||
|
|
||||||
result.append(aSetting)
|
#check for numbers and booleans
|
||||||
|
if(nodeValue.isdigit()):
|
||||||
|
nodeValue = int(nodeValue)
|
||||||
|
elif(nodeValue == 'true'):
|
||||||
|
nodeValue = True
|
||||||
|
elif(nodeValue == 'false'):
|
||||||
|
nodeValue = False
|
||||||
|
|
||||||
|
result[node.getAttribute('id')] = nodeValue
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -57,23 +67,7 @@ class GuiSettingsManager:
|
|||||||
if(xbmcvfs.exists(fileLoc)):
|
if(xbmcvfs.exists(fileLoc)):
|
||||||
try:
|
try:
|
||||||
self.doc = minidom.parse(fileLoc)
|
self.doc = minidom.parse(fileLoc)
|
||||||
self.settingsFile = fileLoc
|
|
||||||
except ExpatError:
|
except ExpatError:
|
||||||
utils.log("Can't read " + fileLoc)
|
utils.log("Can't read " + fileLoc)
|
||||||
|
|
||||||
class SettingNode:
|
|
||||||
name = ''
|
|
||||||
value = ''
|
|
||||||
isDefault = True
|
|
||||||
|
|
||||||
def __init__(self,name,value):
|
|
||||||
self.name = name
|
|
||||||
self.value= value
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return "%s : %s" % (self.name,self.value)
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return self.__str__()
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user