Kodi Community Forum

Full Version: [REQUEST] The self-updating skin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I'm starting to try and make sense of this python thing, and I've already run into a few snags.

Here's the code I've got started:

Code:
import urllib, os,re,urllib2
import xbmc,xbmcgui

path = os.getcwd()[:-1]+"\\"


def DownloaderClass(url,dest):
    dp = xbmcgui.DialogProgress()
    dp.create("My Script","Downloading File",url)
    urllib.urlretrieve(url,dest,lambda nb, bs, fs, url=url: _pbhook(nb,bs,fs,url,dp))

def _pbhook(numblocks, blocksize, filesize, url=None,dp=None):
    try:
        percent = min((numblocks*blocksize*100)/filesize, 100)
        print percent
        dp.update(percent)
    except:
        percent = 100
        dp.update(percent)
    if dp.iscanceled():
        print "DOWNLOAD CANCELLED" # need to get this part working
        dp.close()
        
url ='http://www.iamkizer.net/xbmc/serenity/ccounter/click.php?id=8'
DownloaderClass(url,"special://xbmc/skin/serenity.rar")
executebuiltin('extract(path/serenity.rar,path)')


My problem comes from the last line. I don't quite understand how I would get an absolute path to tell executebuiltin() where my skin folder is...or how exactly you'd change it either way.

Other stuff maybe somebody could help me with is as follows:

1. Pulling a string out of an RSS stream to determine if the currently installed version is up-to-date. I see from the new code examples that it's possible to read/write to a notepad file...I was thinking that if I could parse the RSS stream, I could just write the rev number to a txt file, and then check against that in the future.

2. SVN. This is most likely beyond the scope of my programming abilities ATM, but I'm still curious. Ideally, I'd like to be able to just look at the svn on googlecode, and if stuff is changed, update the changed files.


So, if you can answer these questions AND/OR are possibly willing to help me make this script a reality, I would be greatly, greatly appreciative. Wink
Example code of determining the path of the skin:
Code:
# load xbmc module
import xbmc
# get current (active) skin dir
currentSkin = xbmc.getSkinDir()
# create the path variable
path = 'special://xbmc/skin/'+currentSkin

# insert rest of code here...

In order to parse RSS or some sort XML based feed/source to check for new revisions I would recommend the elementtree package, you can probably also find a more compatible version on the Google code project page of XBMC scripts, in one of the script resources in the trunk.

Still I'm wondering how you are planning on replacing/updating the skin while it's running, doubt it will let you modify files while there being used, for example the the textures.xpr.

Anyway hoped this helped you some more into the right direction, like to see this happen, really like your idea!
this path = os.getcwd()[:-1]+"\\" obsolete, just use path = os.getcwd(), then when joining paths, use os.path.join(path1, path2, etc)

When using special:// stuff to access the file system, you need to use translatePath('special://xbmc/')

Also I suggest you download the rar file to a temporary location (special://temp) and then extract it to the skin directory. Also beware that builtin rar handling is failing on xbox when it's low on memory.
you'll also need to find a way to switch to another skin while updating. as mentioned previously, xbmc won't let you overwrite files while they're being used.

there may be a builtin, or there may not be. if not, it is worth a feature request.

EDIT - using real svn would be possible on everything but xbox. alternatively you can fake it svn repo installer style.
Thanks for all the information, guys. I'll play around using your suggestions, and report back as to what level of success I achieve.

Looking at the WIKI, it does not appear that there is a built-in function to allow me to switch the skin. What about the possibility of changing the contents of guisettings.xml so that the skin string in there is changed, then resetting the system...hmmm...

I guess I was under the impression that I could just overwrite the files. This is how I do it when developing...just edit/save the desired xml file and reload the skin. Never had an error telling me I couldn't overwrite. Is this something on XBMC's side of things?