(2014-04-30, 23:07)Samu-rai Wrote: I'm trying to write a script that will call a specific restore, and can see from the readme on github this is possible.
I'm very new to coding, and struggling to understand how to implement this.
Would you be so kind as to get me started?
Can I do this with python, or will I have to use JSON, and how do I locate the 'Archive' number?
Are you writing something that will run within XBMC or an external script? That will somewhat determine what methods might be available. The archive parameter is the name of the folder you wish to restore. The addon will still use your directory settings like normal, so you only need to pass in the folder name, not its full path. If within another XBMC addon on the same box as the one you want to restore to you can use the example as seen on the README:
Code:
import xbmc
xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "Addons.ExecuteAddon","params":{"addonid":"script.xbmcbackup","params":{"mode":"restore","archive":"201405010000"}}, "id": 1 }')
If you are trying to do this from an external script, or perhaps using a script on one xbmc instance to perform a restore on another you'll still need to use JSON, but you'll have to do a full request over http
Code:
import json
import urllib2
import base64
data = '{ "jsonrpc" : "2.0" , "method" : "Addons.ExecuteAddon" , "params" : {"addonid":"script.xbmcbackup","params":{"mode":"restore","archive":"201405010000"}}, "id":1 }'
clen = len(data)
hostdetails = "http://" +xbmc_address + ":" + json_port + "/jsonrpc"
req = urllib2.Request(hostdetails, data, {'Content-Type': 'application/json', 'Content-Length': clen})
#you only need this if you password protect your xbmc web server
if password != '':
base64string = base64.encodestring('%s:%s' % (user, password))[:-1]
authheader = "Basic %s" % base64string
req.add_header("Authorization", authheader)
try:
f = urllib2.urlopen(req)
response = json.loads(f.read())
f.close()
if(response.has_key('result')):
result = response['result']
except:
pass
As far as getting a list of the archives, that will be a bit harder. It may be useful for me to just provide this as a "mode" that returns a list of archives. The only other way right now would be to poll the directory you are storing the backups in manually. The folder name is the backup archive.
In my SendTo addon I have some python classes I called the CommsManager that abstracts some of this for easy use. The idea is that there is a Local and Remote Comms manager that extend the same object. It's under an MIT license so grab whatever might help you out.
https://github.com/robweber/script.sendt...manager.py