~medibuntu-maintainers/medibuntu/pkgstatus

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
150
151
152
153
154
155
156
157
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright © 2009 Gauvain Pocentek <gpocentek@linutop.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import datetime
import urllib
import sys

DEFAULT_COMP = 'free'
BASE_URL = 'http://packages.medibuntu.org:8080/'
repos = [
         'lucid', 'lucid-staging',
         'oneiric', 'oneiric-staging',
         'precise', 'precise-staging',
         'quantal', 'quantal-staging'
        ]

pkgs = {}
style = 'light'
now = datetime.datetime.utcnow()
date = now.strftime("%Y-%m-%d %I:%M:%S %p UTC")

def download_sources(repo, comp):
    url = '%s/dists/%s/%s/source/Sources' % (BASE_URL, repo, comp)
    ret = urllib.urlretrieve(url)
    if not ret:
        return None
    return ret[0]

def get_packages(repo, comp):
    where = download_sources(repo, comp)
    if not where:
        print 'Unable to get the Sources file'
        return None

    pkgs = {}
    cur_pkg = None
    f = open(where, 'r')
    line = f.readline()
    while line:
        line = line[:-1]
        if line.startswith('Package: '):
            cur_pkg = line.split(' ', 1)[1]
            pkgs[cur_pkg] = {}
            line = f.readline()

        elif line:
            s = line.split(' ', 1)
            key = s[0][:-1]
            if s[1] == '':
                a = []
                line = f.readline()
                while line.startswith(' '):
                    a.append(line[1:-1])
                    line = f.readline()
                pkgs[cur_pkg][key] = a
            else:
                pkgs[cur_pkg][key] = s[1]
                line = f.readline()

        else: line = f.readline()

    return pkgs

def get_html_row(pkgname, pkg):
    global repos
    global style
    if style == 'light':
        style = 'dark'
    else:
        style = 'light'
    ret = """
<tr class="%s">
  <td><b>%s</b></td>\n""" % (style, pkgname)

    for repo in repos:
        try:
            version = pkg[repo]['Version']

            # if the repo is -staging, compare the version with the stable one
            if repo.endswith('-staging'):
                stable_repo = repo[:-8]
                try:
                    stable_version = pkg[stable_repo]['Version']
                    if stable_version != version:
                        version = '<b>%s</b>' % version
                except:
                    stable_version = None

            binary = pkg[repo]['Binary']
            directory = pkg[repo]['Directory']
            dsc = pkg[repo]['Files'][0].split(' ')[2]
            url = '%s/%s/%s' % (BASE_URL, directory, dsc)
            ret += '  <td><a href="%s">%s</a><br />' % (url, version)
            ret += '<div style="font-size: 10px;">(%s)</div></td>\n''' % binary
        except:
            ret += '<td></td>\n'

    ret += '</tr>'
    return ret


if len(sys.argv) < 2:
    comp = DEFAULT_COMP
else:
    comp = sys.argv[1]

tmp = {}
for repo in repos:
    tmp[repo] = get_packages(repo, comp)
    for pkg in tmp[repo].keys():
        if not pkgs.has_key(pkg):
            pkgs[pkg] = {}
        pkgs[pkg][repo] = tmp[repo][pkg]

print """
<html>
<head>
    <title>Packages status: %s</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="expires" content="0">
    <link rel="stylesheet" href="style2.css" type="text/css">
</head>
<body>
<p>Last updated: %s</p>
<table class="merges">
<tr><th>Package</th>""" % (comp, date),
for repo in repos:
    print '<th>%s</th>' % repo,
print '</tr>'

keys = pkgs.keys()
keys.sort()
for k in keys:
    print get_html_row(k, pkgs[k])

#for pkg in pkgs:
#    print get_html_row(pkg, pkgs[pkg])

print """
</table>
</html>
"""