xbmcbackup/resources/lib/guisettings.py

48 lines
1.8 KiB
Python
Raw Permalink Normal View History

2014-10-31 17:40:47 +01:00
import json
2019-11-25 22:48:42 +01:00
import xbmc
2019-08-27 21:55:22 +02:00
from . import utils as utils
2014-10-31 17:40:47 +01:00
class GuiSettingsManager:
filename = 'kodi_settings.json'
systemSettings = None
2019-11-25 22:33:34 +01:00
def __init__(self):
# get all of the current Kodi settings
json_response = json.loads(xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.GetSettings","params":{"level":"expert"}}'))
2019-11-25 22:33:34 +01:00
self.systemSettings = json_response['result']['settings']
2019-11-25 22:33:34 +01:00
def backup(self):
utils.log('Backing up Kodi settings')
2019-11-25 22:33:34 +01:00
# return all current settings
return self.systemSettings
2019-11-25 22:33:34 +01:00
def restore(self, restoreSettings):
utils.log('Restoring Kodi settings')
2019-11-25 22:33:34 +01:00
updateJson = {"jsonrpc": "2.0", "id": 1, "method": "Settings.SetSettingValue", "params": {"setting": "", "value": ""}}
2019-11-25 22:33:34 +01:00
# create a setting=value dict of the current settings
settingsDict = {}
for aSetting in self.systemSettings:
# ignore action types, no value
if(aSetting['type'] != 'action'):
settingsDict[aSetting['id']] = aSetting['value']
2019-11-25 22:33:34 +01:00
restoreCount = 0
for aSetting in restoreSettings:
# only update a setting if its different than the current (action types have no value)
if(aSetting['type'] != 'action' and settingsDict[aSetting['id']] != aSetting['value']):
if(utils.getSettingBool('verbose_logging')):
utils.log('%s different than current: %s' % (aSetting['id'], str(aSetting['value'])))
2019-11-25 22:33:34 +01:00
updateJson['params']['setting'] = aSetting['id']
updateJson['params']['value'] = aSetting['value']
2019-11-25 22:33:34 +01:00
xbmc.executeJSONRPC(json.dumps(updateJson))
restoreCount = restoreCount + 1
2019-11-25 22:33:34 +01:00
utils.log('Update %d settings' % restoreCount)