Created
July 30, 2013 13:09
-
-
Save mattyclarkson/6112747 to your computer and use it in GitHub Desktop.
Gets the mingw-builds archive URL
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 | |
# encoding: UTF-8 | |
try: | |
import urllib.request as urlrequest | |
except ImportError: | |
import urllib as urlrequest | |
def get_mingw_versions(repo_url = 'http://downloads.sourceforge.net/project/' | |
'mingwbuilds/host-windows/repository.txt'): | |
try: | |
socket = urlrequest.urlopen(repo_url) | |
repo = socket.read().decode() | |
finally: | |
socket.close() | |
versions = {} | |
for entry in repo.split('\n')[:-1]: | |
value = entry.split('|') | |
version = versions.setdefault(value[0].strip(), {}) | |
arch = version.setdefault(value[1].strip(), {}) | |
threading = arch.setdefault(value[2].strip(), {}) | |
exceptions = threading.setdefault(value[3].strip(), {}) | |
revision = exceptions.setdefault(value[4].strip(), | |
value[5].strip().replace( | |
'http://sourceforge.net/projects/mingwbuilds/files', | |
'http://downloads.sourceforge.net/project/mingwbuilds')) | |
return versions | |
def get_mingw_archive_url(arch, threading, exceptions, version = 'latest', | |
revision = 'latest'): | |
versions = get_mingw_versions() | |
if version == 'latest': | |
version = max(versions.keys(), | |
key = lambda x: tuple([int(n) for n in x.split('.')])) | |
if revision == 'latest': | |
revision = max(versions[version][arch][threading][exceptions].keys(), | |
key = lambda x: int(x[3:])) | |
return versions[version][arch][threading][exceptions][revision] | |
print(get_mingw_archive_url('x64', 'posix', 'sjlj')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment