From ed43e1a0d3b0316b21558ca51d08ff02331974e9 Mon Sep 17 00:00:00 2001 From: Rob Weber Date: Mon, 30 Nov 2020 13:44:35 -0600 Subject: [PATCH] added ability to export/save settings as json using GetSettings --- resources/lib/backup.py | 9 +++++++++ resources/lib/guisettings.py | 13 ++++++++++++- resources/settings.xml | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/resources/lib/backup.py b/resources/lib/backup.py index fec25fd..b6e95f0 100644 --- a/resources/lib/backup.py +++ b/resources/lib/backup.py @@ -160,6 +160,15 @@ class XbmcBackup: if(not shouldContinue): return + # check if Kodi settings should also be dumped + if(utils.getSettingBool('backup_copy_settings')): + utils.log('Backing up Kodi settings') + gui_settings = GuiSettingsManager() + gui_settings.backup() + + # add this file to the backup + self.remote_vfs.put(xbmcvfs.translatePath(utils.data_dir() + gui_settings.filename), self.remote_vfs.root_path + gui_settings.filename) + orig_base_path = self.remote_vfs.root_path # backup all the files diff --git a/resources/lib/guisettings.py b/resources/lib/guisettings.py index 3af795e..4d05561 100644 --- a/resources/lib/guisettings.py +++ b/resources/lib/guisettings.py @@ -7,6 +7,7 @@ from xml.parsers.expat import ExpatError class GuiSettingsManager: + filename = 'kodi_settings.json' doc = None def __init__(self): @@ -16,8 +17,18 @@ class GuiSettingsManager: # read in the copy self._readFile(xbmcvfs.translatePath('special://home/userdata/guisettings.xml.restored')) + def backup(self): + # get all of the current Kodi settings + json_response = json.loads(xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.GetSettings","params":{"level":"advanced"}}')) + + # write the settings as a json object to the addon data directory + sFile = xbmcvfs.File(xbmcvfs.translatePath(utils.data_dir() + self.filename), 'w') + sFile.write(json.dumps(json_response['result']['settings'])) + sFile.write("") + sFile.close() + def run(self): - # get a list of all the settings we can manipulate via json + # get all of the current Kodi settings json_response = json.loads(xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.GetSettings","params":{"level":"advanced"}}')) settings = json_response['result']['settings'] diff --git a/resources/settings.xml b/resources/settings.xml index 7e19f0c..054263b 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -21,6 +21,8 @@ + +