Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import xml.dom.minidom
- import os, sys, tarfile, urllib, hashlib, ctypes
- ADDON_DIR = '/tmp'
- if len(sys.argv) > 2: ADDON_DIR = sys.argv[-1]
- print('addon path', ADDON_DIR )
- IS32BIT = (ctypes.sizeof(ctypes.c_void_p)==4) #http://stackoverflow.com/questions/1405913/how-do-i-determine-if-my-python-shell-is-executing-in-32bit-or-64bit-mode
- _linux_types = 'ubuntu debian fedora suse maemo'.split()
- def _guess_subplatform():
- if os.name == 'posix':
- sysname, nodename, release, version, machine = os.uname()
- for linuxtype in _linux_types:
- if linuxtype in version.lower(): return linuxtype
- return 'ubuntu' # default to ubuntu
- return ''
- def download( url, md5=None, path='' ):
- print('downloading', url )
- assert not path.startswith('../') # do not allow outside of REXADDONS
- data = urllib.urlopen( url ).read()
- if md5: assert hashlib.md5sum( data ).hexdigest() == md5
- tmp = '/tmp/%s' %os.path.split( url )[-1]
- f = open( tmp, 'wb' ); f.write( data ); f.close()
- if url.endswith('.tar.gz') or url.endswith('.tgz') or url.endswith('.tar.bz2') or url.endswith('.tar'):
- print( 'untarring', tmp )
- tar = tarfile.TarFile.open( tmp, 'r:*' )
- fpath = os.path.join(ADDON_DIR,path)
- if not os.path.isdir(fpath): os.makedirs( fpath )
- print( 'extracting to:', fpath )
- tar.extractall( path=fpath )
- def install_addon( url, PATH='/tmp/addontest' ):
- doc = xml.dom.minidom.parse( url )
- platforms = doc.documentElement.getAttribute('platforms')
- if not platforms: print('warning: this addon did not describe what platforms it can run on')
- elif platforms == 'all': print('addon runs on all platforms')
- else:
- print('addon only supports the following platforms:')
- for plat in platforms.split(','): print( plat )
- ## extract simple archives ##
- for ar in doc.getElementsByTagName('archive'):
- url = ar.getAttribute('url')
- download( url, md5=ar.getAttribute('md5'), path=ar.getAttribute('path') )
- for library in doc.getElementsByTagName('library'):
- libs = []
- if sys.platform == 'linux2':
- for lib in library.getElementsByTagName('linux'):
- if IS32BIT and lib.getAttribute('bits')=='32': libs.append( lib )
- elif not IS32BIT and lib.getAttribute('bits')=='64': libs.append( lib )
- elif sys.platform.startswith('win'):
- for lib in library.getElementsByTagName('windows'):
- if IS32BIT and lib.getAttribute('bits')=='32': libs.append( lib )
- elif not IS32BIT and lib.getAttribute('bits')=='64': libs.append( lib )
- elif sys.platform == 'darwin':
- for lib in library.getElementsByTagName('osx'):
- if IS32BIT and lib.getAttribute('bits')=='32': libs.append( lib )
- elif not IS32BIT and lib.getAttribute('bits')=='64': libs.append( lib )
- if not libs:
- if library.getAttribute('required')=='True': print('error: this library is required %s' %library.getAttribute('name'))
- print('no precompiled library for your OS')
- sources = library.getElementsByTagName('source')
- for src in sources:
- print('source is available here:')
- print( src.getAttribute('url') )
- print( src.getAttribute('notes') )
- for lib in libs:
- url = lib.getAttribute('url')
- download( url, md5=lib.getAttribute('md5'), path=lib.getAttribute('path') )
- configs = {}
- for cfg in doc.getElementsByTagName('config'): # embeded config files
- name = cfg.getAttribute('name')
- assert name
- configs[ name ] = cfg.firstChild.nodeValue # must be a text node
- open( os.path.join( ADDON_DIR, name ), 'wb' ).write( cfg.firstChild.nodeValue )
- print configs
- return configs # installer-manager needs to keep track of ini-files to enable/disable the addon
- if __name__ == '__main__':
- install_addon( sys.argv[1] )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement