added ability to export/save settings as json using GetSettings

This commit is contained in:
Rob Weber
2020-11-30 13:44:35 -06:00
parent b470412b4f
commit ed43e1a0d3
3 changed files with 23 additions and 1 deletions

View File

@@ -160,6 +160,15 @@ class XbmcBackup:
if(not shouldContinue): if(not shouldContinue):
return 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 orig_base_path = self.remote_vfs.root_path
# backup all the files # backup all the files

View File

@@ -7,6 +7,7 @@ from xml.parsers.expat import ExpatError
class GuiSettingsManager: class GuiSettingsManager:
filename = 'kodi_settings.json'
doc = None doc = None
def __init__(self): def __init__(self):
@@ -16,8 +17,18 @@ class GuiSettingsManager:
# read in the copy # read in the copy
self._readFile(xbmcvfs.translatePath('special://home/userdata/guisettings.xml.restored')) 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): 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"}}')) 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']

View File

@@ -21,6 +21,8 @@
<setting id="remove_auth_button" type="action" label="30093" action="RunScript(special://home/addons/script.xbmcbackup/launcher.py,action=remove_auth)" visible="gt(-9,1)"/> <setting id="remove_auth_button" type="action" label="30093" action="RunScript(special://home/addons/script.xbmcbackup/launcher.py,action=remove_auth)" visible="gt(-9,1)"/>
</category> </category>
<category id="selection" label="30012"> <category id="selection" label="30012">
<setting id="backup_copy_settings" type="bool" label="Save Kodi Settings" default="true" />
<setting type="sep" />
<setting id="backup_selection_type" type="enum" lvalues="30014|30015" default="0" label="30023" /> <setting id="backup_selection_type" type="enum" lvalues="30014|30015" default="0" label="30023" />
<setting id="backup_addon_data" type="bool" label="30031" default="false" visible="eq(-1,0)"/> <setting id="backup_addon_data" type="bool" label="30031" default="false" visible="eq(-1,0)"/>
<setting id="backup_config" type="bool" label="30035" default="true" visible="eq(-2,0)"/> <setting id="backup_config" type="bool" label="30035" default="true" visible="eq(-2,0)"/>