mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-12-22 14:05:23 +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)
|
||||
gui_settings = GuiSettingsManager('special://home/userdata/guisettings.xml')
|
||||
gui_settings = GuiSettingsManager()
|
||||
gui_settings.run()
|
||||
|
||||
#call update addons to refresh everything
|
||||
|
@ -6,49 +6,59 @@ import xbmc,xbmcvfs
|
||||
|
||||
|
||||
class GuiSettingsManager:
|
||||
settingsFile = None
|
||||
doc = None
|
||||
|
||||
def __init__(self,settingsFile):
|
||||
self._readFile(xbmc.translatePath(settingsFile))
|
||||
def __init__(self):
|
||||
#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):
|
||||
#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"}}'))
|
||||
|
||||
settings = json_response['result']['settings']
|
||||
settingsAllowed = []
|
||||
currentSettings = {}
|
||||
|
||||
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
|
||||
updateSettings = self.__parseNodes(self.doc.getElementsByTagName('setting'))
|
||||
#parse the existing xml file and get all the settings we need to restore
|
||||
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
|
||||
for aSetting in updateSettings:
|
||||
if(aSetting.name in settingsAllowed):
|
||||
utils.log("updating: " + aSetting.name + ", value: " + aSetting.value)
|
||||
jsonObj = {"jsonrpc":"2.0","id":1,"method":"Settings.SetSettingValue","params":{"setting":"","value":""}}
|
||||
for anId, aValue in updateSettings.items():
|
||||
utils.log("updating: " + anId + ", value: " + str(aValue))
|
||||
|
||||
jsonObj['params']['setting'] = anId
|
||||
jsonObj['params']['value'] = aValue
|
||||
|
||||
#check for boolean and numeric values
|
||||
if(aSetting.value.isdigit() or (aSetting.value == 'true' or aSetting.value == 'false')):
|
||||
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
|
||||
xbmcvfs.copy(self.settingsFile, xbmc.translatePath("special://home/userdata/guisettings.xml.restored"))
|
||||
xbmc.executeJSONRPC(json.dumps(jsonObj))
|
||||
|
||||
def __parseNodes(self,nodeList):
|
||||
result = []
|
||||
result = {}
|
||||
|
||||
for node in nodeList:
|
||||
#only add if it's not a default setting
|
||||
if('default' not in node.attributes.keys()):
|
||||
aSetting = SettingNode(node.getAttribute('id'),node.firstChild.nodeValue)
|
||||
aSetting.isDefault = False
|
||||
|
||||
result.append(aSetting)
|
||||
nodeValue = ''
|
||||
if(node.firstChild != None):
|
||||
nodeValue = node.firstChild.nodeValue
|
||||
|
||||
#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
|
||||
|
||||
@ -57,23 +67,7 @@ class GuiSettingsManager:
|
||||
if(xbmcvfs.exists(fileLoc)):
|
||||
try:
|
||||
self.doc = minidom.parse(fileLoc)
|
||||
self.settingsFile = fileLoc
|
||||
except ExpatError:
|
||||
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