~bryce/package-status/trunk-1

« back to all changes in this revision

Viewing changes to bin/upstream-xorg.py

  • Committer: Bryce Harrington
  • Date: 2013-01-29 01:22:14 UTC
  • Revision ID: bryce@canonical.com-20130129012214-jvz83d1gogleqs02
Finish implementing page parsing functionality

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
        raise
21
21
        return None
22
22
 
23
 
def parse_xorg_top(url):
 
23
def parse_xorg_top():
24
24
    '''Returns an array'''
 
25
    url = "http://xorg.freedesktop.org/releases/individual"
25
26
    page = readurl(url)
26
27
    if not page:
27
28
        return None
41
42
 
42
43
def parse_xorg_page(url, category=None):
43
44
    '''Returns a dict of packages parsed from the given url'''
 
45
    package_pattern = '<a href="([\w-]+)-([\d\.]+)\.(tar\.\w+)"'
 
46
    vcs_base = 'http://cgit.freedesktop.org/xorg'
 
47
 
44
48
    page = readurl(url)
45
49
    if not page:
46
50
        return None
47
 
 
48
51
    packages = {}
49
 
    re_pkg = re.compile('<a href="([\w-]+)-([\d\.]+)\.(tar\.\w+)"')
 
52
    re_pkg = re.compile(package_pattern)
50
53
    for line in page.split("\n"):
51
54
        m = re_pkg.search(line)
52
55
        if not m:
54
57
        name = m.group(1)
55
58
        version = m.group(2)
56
59
        filename = "%s-%s.%s" %(m.group(1), m.group(2), m.group(3))
57
 
        # TODO: Merge separate .bz2 and .gz entries into a single record.  urls?
58
60
        pkg = {
59
61
            'name': name,
60
62
            'version': version,
61
63
            'category': category,
62
 
            'url': os.path.join(url, filename)
63
 
            }
64
 
        if name not in packages:
65
 
            packages[name] = []
66
 
        packages[name].append(pkg)
67
 
 
68
 
    return packages
69
 
 
70
 
 
71
 
xorg_top_url = "http://xorg.freedesktop.org/releases/individual"
 
64
            'url': os.path.join(url, filename),
 
65
            'vcs': '%s/%s/%s' %(vcs_base, category, name)
 
66
            }
 
67
 
 
68
        # Special case to handle naming irregularities
 
69
        if name == 'xtrans':
 
70
            pkg['vcs'] = '%s/%s/%s' %(vcs_base, category, 'libxtrans')
 
71
 
 
72
        if name not in packages:
 
73
            packages[name] = []
 
74
        packages[name].append(pkg)
 
75
 
 
76
    return packages
 
77
 
 
78
def parse_xterm_page(category=None):
 
79
    url = 'ftp://invisible-island.net/xterm/'
 
80
    package_pattern = '(xterm)-(\d+)\.(tgz)'
 
81
    vcs_base = None
 
82
 
 
83
    page = readurl(url)
 
84
    if not page:
 
85
        return None
 
86
    packages = {}
 
87
    re_pkg = re.compile(package_pattern)
 
88
    for line in page.split("\n"):
 
89
        m = re_pkg.search(line)
 
90
        if not m:
 
91
            continue
 
92
        name = m.group(1)
 
93
        version = m.group(2)
 
94
        filename = "%s-%s.%s" %(m.group(1), m.group(2), m.group(3))
 
95
        pkg = {
 
96
            'name': name,
 
97
            'version': m.group(2),
 
98
            'category': category,
 
99
            'url': os.path.join(url, filename),
 
100
            'vcs': None,
 
101
            }
 
102
 
 
103
        if name not in packages:
 
104
            packages[name] = []
 
105
        packages[name].append(pkg)
 
106
 
 
107
    return packages
 
108
 
 
109
def parse_nvidia_page(category=None):
 
110
    url = 'ftp://download.nvidia.com/XFree86/Linux-x86'
 
111
    package_pattern = '^([\d\.]+)\s+(.*)$'
 
112
 
 
113
    page = readurl('%s/%s' %(url, 'latest.txt'))
 
114
    if not page:
 
115
        return None
 
116
 
 
117
    packages = {}
 
118
    re_pkg = re.compile(package_pattern)
 
119
    for line in page.split("\n"):
 
120
        m = re_pkg.search(line)
 
121
        if not m:
 
122
            continue
 
123
        name = 'nvidia-graphics-drivers'
 
124
        pkg = {
 
125
            'name': name,
 
126
            'version': m.group(1),
 
127
            'category': category,
 
128
            'url': '%s/%s' %(url, m.group(2)),
 
129
            'vcs': None, # TODO
 
130
            }
 
131
 
 
132
        if name not in packages:
 
133
            packages[name] = []
 
134
        packages[name].append(pkg)
 
135
 
 
136
    return packages
72
137
 
73
138
if __name__ == "__main__":
74
 
    data = parse_xorg_top(xorg_top_url)
 
139
    data = parse_xorg_top()
 
140
    data.update(parse_nvidia_page())
 
141
    data.update(parse_xterm_page())
 
142
    data['_header'] = {
 
143
        'distro': 'Upstream',
 
144
        'series': 'X.org',
 
145
        'team':   'ubuntu-x-swat',
 
146
        }
75
147
    print json.dumps(data, indent=4)
76
148
 
77
149