get_nwjs.py 1.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
import os
import sys
import shutil
import urllib

VERSION="v0.12.3"

nwjsfile = {
    "win64": "nwjs-%s-win-x64.zip",
    "osx64": "nwjs-%s-osx-x64.zip",
    "linux64": "nwjs-%s-linux-x64.tar.gz",
    "win32": "nwjs-%s-win-ia32.zip",
    "osx32" : "nwjs-%s-osx-ia32.zip",
    "linux32": "nwjs-%s-linux-ia32.tar.gz",
}

def main():
    os.chdir(os.path.dirname(os.path.realpath(__file__)))

    if len(sys.argv) < 2:
        print "Select one of: %s" % " ".join(nwjsfile.keys())
        exit(1)

    osarg = sys.argv[1]
    filename = nwjsfile[osarg] % VERSION
    url = "http://dl.nwjs.io/%s/%s" % (VERSION, filename)

    print "Will first download nwjs."
    target = "agkyra/resources/nwjs"
    if os.path.isdir(target):
        print "Warning: cleaning up %s." % target
        shutil.rmtree(target)
    elif os.path.exists(target):
        print "%s exists and is not a dir; aborting." % target
        exit(1)

    print "Retrieving %s" % url
    urllib.urlretrieve(url, filename)

    print "Extracting %s" % filename
    if osarg.startswith("linux"):
        toplevel = filename.strip('.tar.gz')
        os.system("tar xzf %s" % filename)
        print "Renaming %s to %s" % (toplevel, target)
        os.rename(toplevel, target)
    else:
        toplevel = filename.strip('.zip')
        if osarg.startswith('osx'):
            os.system("unzip %s" % filename)
        else:  # Windows has no unzip command
            import zipfile
            with zipfile.ZipFile(filename, "r") as z:
                z.extractall('.')
        print "Renaming %s to %s" % (toplevel, target)
        os.rename(toplevel, target)

    print "Deleting %s" % filename
    os.unlink(filename)


if __name__ == "__main__":
    main()