summaryrefslogtreecommitdiffstats
path: root/get_releases.py
blob: c8e067d88e6469937a01ccd22c554880b251a09c (plain)
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
import re
from urlgrabber import urlread
from urlgrabber.grabber import URLGrabError

FEDORA_RELEASES = 'http://dl.fedoraproject.org/pub/fedora/linux/releases/'
ARCHES = ('i386', 'i686', 'x86_64')

def get_fedora_releases():
    releases = []
    html = urlread(FEDORA_RELEASES)
    for release in re.findall(r'<a href="(\d+)/">', html)[-2:][::-1]:
        for arch in ARCHES:
            arch_url = FEDORA_RELEASES + '%s/Live/%s/' % (release, arch)
            try:
                files = urlread(arch_url)
            except URLGrabError:
                continue
            for link in re.findall(r'<a href="(.*)">', files):
                if link.endswith('-CHECKSUM'):
                    checksum = urlread(arch_url + link)
                    for line in checksum.split('\n'):
                        try:
                            sha256, filename = line.split()
                            if filename[0] != '*':
                                continue
                            filename = filename[1:]
                            chunks = filename[:-4].split('-')
                            chunks.remove('Live')
                            name = ' '.join(chunks)
                            releases.append(dict(
                                name = name,
                                url = arch_url + filename,
                                sha256 = sha256,
                                ))
                        except ValueError:
                            pass
    return releases


from pprint import pprint
pprint(get_fedora_releases())