Created
July 23, 2011 23:02
-
-
Save sigmaris/1101979 to your computer and use it in GitHub Desktop.
Upgrade/Install script for devkitARM, libnds, etc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import feedparser | |
import json | |
import re | |
import urllib | |
import tempfile | |
import subprocess | |
import os | |
LIBS = ['libnds','filesystem','libfat','dswifi','maxmod','default_arm7'] | |
if os.environ.has_key('DEVKITPRO'): | |
ROOTDIR = os.environ['DEVKITPRO'] | |
else: | |
ROOTDIR = '/usr/local/devkitPRO' | |
LIBDIR = ROOTDIR + '/libnds' | |
if(not os.path.exists(LIBDIR)): | |
os.makedirs(LIBDIR) | |
def extractversion(regex,entries): | |
latestversion = 0 | |
link = u'' | |
latestversiontext = '' | |
for entry in entries: | |
match = regex.search(entry.title) | |
if match: | |
versionnumber = 0; | |
versiontext = '' | |
for grp in match.groups(): | |
if(grp): | |
versiontext += grp | |
versiontext += '.' | |
versionnumber *= 100 | |
versionnumber += int(grp) | |
if latestversion < versionnumber: | |
latestversion = versionnumber | |
link = entry.link | |
latestversiontext = versiontext | |
return (latestversion,link,latestversiontext) | |
def downloadtemp(url): | |
"""Copy the contents of a file from a given URL | |
to a local temp file. | |
""" | |
webFile = urllib.urlopen(url) | |
temp = tempfile.mkstemp('.tar.bz2'); | |
localFile = os.fdopen(temp[0],'w') | |
print 'downloading',url,'to temp file',temp[1] | |
localFile.write(webFile.read()) | |
webFile.close() | |
localFile.close() | |
return temp[1] | |
def upgrade(link, dir): | |
temp = downloadtemp(link) | |
print 'extracting in',dir | |
p = subprocess.call(args=['tar','-xjf',temp],cwd=dir) | |
if(p > 0): | |
print 'tar failed with error code', p | |
os.unlink(temp) | |
devkitpro = feedparser.parse("http://sourceforge.net/api/file/index/project-id/114505/mtime/desc/rss") | |
versions = {} | |
libndspat = re.compile(r'^/libnds/libnds-(?:(\d+)\.)(?:(\d+)\.)?(?:(\d+)\.)?(?:(\d+)\.)?') | |
versions['libnds'] = extractversion(libndspat,devkitpro.entries) | |
dkapat = re.compile(r'^/devkitARM/devkitARM_r(\d+)-osx') | |
versions['devkitarm'] = extractversion(dkapat,devkitpro.entries) | |
libfspat = re.compile(r'^/filesystem/libfilesystem-(?:(\d+)\.)(?:(\d+)\.)?(?:(\d+)\.)?(?:(\d+)\.)?') | |
versions['filesystem'] = extractversion(libfspat,devkitpro.entries) | |
libfatpat = re.compile(r'^/libfat/libfat-nds-(?:(\d+)\.)(?:(\d+)\.)?(?:(\d+)\.)?(?:(\d+)\.)?') | |
versions['libfat'] = extractversion(libfatpat,devkitpro.entries) | |
dswifipat = re.compile(r'^/dswifi/dswifi-(?:(\d+)\.)(?:(\d+)\.)?(?:(\d+)\.)?(?:(\d+)\.)?') | |
versions['dswifi'] = extractversion(dswifipat,devkitpro.entries) | |
maxmodpat = re.compile(r'^/maxmod/maxmod-nds-(?:(\d+)\.)(?:(\d+)\.)?(?:(\d+)\.)?(?:(\d+)\.)?') | |
versions['maxmod'] = extractversion(maxmodpat,devkitpro.entries) | |
defaultarm7pat = re.compile(r'^/default arm7/default_arm7-(?:(\d+)\.)(?:(\d+)\.)?(?:(\d+)\.)?(?:(\d+)\.)?') | |
versions['default_arm7'] = extractversion(defaultarm7pat,devkitpro.entries) | |
oldversions = {} | |
if os.path.exists(ROOTDIR+'/.updater_versions'): | |
try: | |
versionfile = open((ROOTDIR+'/.updater_versions'),mode='r') | |
try: | |
oldversions = json.load(versionfile) | |
except TypeError: | |
print TypeError | |
finally: | |
versionfile.close() | |
except IOError, (ErrorNumber, ErrorMessage): | |
print ErrorMessage | |
if (not oldversions.has_key('devkitarm')) or (oldversions['devkitarm'][0] < versions['devkitarm'][0]): | |
print 'devkitARM has been updated to version',versions['devkitarm'][2] | |
upgrade(versions['devkitarm'][1],ROOTDIR) | |
else: | |
print 'devkitARM is at version',versions['devkitarm'][2],'no update necessary.' | |
for lib in LIBS: | |
if (not oldversions.has_key(lib)) or (oldversions[lib][0] < versions[lib][0]): | |
print lib,'has been updated to version',versions[lib][2] | |
upgrade(versions[lib][1],LIBDIR) | |
else: | |
print lib,'is at version',versions[lib][2],'no update necessary.' | |
try: | |
versionfile = open((ROOTDIR+'/.updater_versions'),mode='w') | |
try: | |
json.dump(versions,versionfile,indent=2) | |
except TypeError: | |
print TypeError | |
finally: | |
versionfile.close() | |
except IOError, (ErrorNumber, ErrorMessage): | |
print ErrorMessage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment