~bryce/package-status/trunk-1

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python

# Retrieves X.org package versions from upstream
# and outputs a JSON data file

import re
import os
import json
import urllib2

# TODO: Use beautifulsoup instead of manually parsing the page

def readurl(url):
    try:
        fin = urllib2.urlopen(url)
        content = fin.read()
        fin.close()
        return content
    except:
        raise
        return None

def parse_xorg_top():
    '''Returns an array'''
    url = "http://xorg.freedesktop.org/releases/individual"
    page = readurl(url)
    if not page:
        return None

    re_page = re.compile('<a href="(\w+)/">', re.IGNORECASE)
    packages = {}
    for line in page.split("\n"):
        m = re_page.search(line)
        if not m:
            continue
        category = m.group(1)
        suburl = "%s/%s" %(url, category)
        new_pkgs = parse_xorg_page(suburl, category=category)
        packages.update(new_pkgs)

    return packages

def parse_xorg_page(url, category=None):
    '''Returns a dict of packages parsed from the given url'''
    package_pattern = '<a href="([\w-]+)-([\d\.]+)\.(tar\.\w+)"'
    vcs_base = 'http://cgit.freedesktop.org/xorg'

    page = readurl(url)
    if not page:
        return None
    packages = {}
    re_pkg = re.compile(package_pattern)
    for line in page.split("\n"):
        m = re_pkg.search(line)
        if not m:
            continue
        name = m.group(1)
        version = m.group(2)
        filename = "%s-%s.%s" %(m.group(1), m.group(2), m.group(3))
        pkg = {
            'name': name,
            'version': version,
            'category': category,
            'url': os.path.join(url, filename),
            'vcs': '%s/%s/%s' %(vcs_base, category, name)
            }

        # Special case to handle naming irregularities
        if name == 'xtrans':
            pkg['vcs'] = '%s/%s/%s' %(vcs_base, category, 'libxtrans')

        if name not in packages:
            packages[name] = []
        packages[name].append(pkg)

    return packages

def parse_xterm_page(category=None):
    url = 'ftp://invisible-island.net/xterm/'
    package_pattern = '(xterm)-(\d+)\.(tgz)'
    vcs_base = None

    page = readurl(url)
    if not page:
        return None
    packages = {}
    re_pkg = re.compile(package_pattern)
    for line in page.split("\n"):
        m = re_pkg.search(line)
        if not m:
            continue
        name = m.group(1)
        version = m.group(2)
        filename = "%s-%s.%s" %(m.group(1), m.group(2), m.group(3))
        pkg = {
            'name': name,
            'version': m.group(2),
            'category': category,
            'url': os.path.join(url, filename),
            'vcs': None,
            }

        if name not in packages:
            packages[name] = []
        packages[name].append(pkg)

    return packages

def parse_nvidia_page(category=None):
    url = 'ftp://download.nvidia.com/XFree86/Linux-x86'
    package_pattern = '^([\d\.]+)\s+(.*)$'

    page = readurl('%s/%s' %(url, 'latest.txt'))
    if not page:
        return None

    packages = {}
    re_pkg = re.compile(package_pattern)
    for line in page.split("\n"):
        m = re_pkg.search(line)
        if not m:
            continue
        name = 'nvidia-graphics-drivers'
        pkg = {
            'name': name,
            'version': m.group(1),
            'category': category,
            'url': '%s/%s' %(url, m.group(2)),
            'vcs': None, # TODO
            }

        if name not in packages:
            packages[name] = []
        packages[name].append(pkg)

    return packages

if __name__ == "__main__":
    data = parse_xorg_top()
    data.update(parse_nvidia_page())
    data.update(parse_xterm_page())
    data['_header'] = {
        'distro': 'Upstream',
        'series': 'X.org',
        'team':   'ubuntu-x-swat',
        }
    print json.dumps(data, indent=4)