]>
Commit | Line | Data |
---|---|---|
f6e6ff79 MT |
1 | #!/usr/bin/python |
2 | ||
3 | import base | |
4 | import builds | |
5 | import distribution | |
6 | ||
7 | class Updates(base.Object): | |
8 | def __init__(self, pakfire): | |
9 | base.Object.__init__(self, pakfire) | |
10 | ||
11 | def get(self, type, distro=None, limit=None, offset=None): | |
12 | assert type in ("stable", "unstable", "testing") | |
13 | ||
14 | query = "SELECT * FROM repositories_builds \ | |
15 | JOIN builds ON builds.id = repositories_builds.build_id \ | |
16 | WHERE builds.type = 'release' AND \ | |
17 | repositories_builds.repo_id IN \ | |
18 | (SELECT id FROM repositories WHERE type = %s)" | |
19 | args = [type,] | |
20 | ||
21 | if distro: | |
22 | query += " AND builds.distro_id = %s" | |
23 | args.append(distro.id) | |
24 | ||
25 | query += " ORDER BY time_added DESC" | |
26 | ||
27 | if limit: | |
28 | if offset: | |
29 | query += " LIMIT %s,%s" | |
30 | args += [offset, limit] | |
31 | else: | |
32 | query += " LIMIT %s" | |
33 | args.append(limit) | |
34 | ||
35 | updates = [] | |
36 | for row in self.db.query(query, *args): | |
37 | update = Update(self.pakfire, row) | |
38 | updates.append(update) | |
39 | ||
40 | return updates | |
41 | ||
42 | def get_latest(self, type): | |
43 | return self.get(type=type, limit=5) | |
44 | ||
45 | ||
46 | ||
47 | class Update(base.Object): | |
48 | def __init__(self, pakfire, data): | |
49 | base.Object.__init__(self, pakfire) | |
50 | ||
51 | self.data = data | |
52 | ||
53 | self._build = None | |
54 | ||
55 | @property | |
56 | def build(self): | |
57 | if self._build is None: | |
58 | self._build = self.pakfire.builds.get_by_id(self.data.build_id) | |
59 | assert self._build | |
60 | ||
61 | return self._build | |
62 | ||
63 | @property | |
64 | def name(self): | |
65 | return self.build.name | |
66 | ||
67 | @property | |
68 | def description(self): | |
69 | return self.build.message | |
70 | ||
71 | @property | |
72 | def summary(self): | |
73 | line = None | |
74 | for line in self.description.splitlines(): | |
75 | if not line: | |
76 | continue | |
77 | ||
78 | break | |
79 | ||
80 | if len(line) >= 60: | |
81 | line = "%s..." % line[:60] | |
82 | ||
83 | return line | |
84 | ||
85 | @property | |
86 | def severity(self): | |
87 | return self.build.severity | |
88 | ||
89 | @property | |
90 | def distro(self): | |
91 | return self.build.distro | |
92 | ||
93 | @property | |
94 | def score(self): | |
95 | return self.build.score | |
96 | ||
97 | @property | |
98 | def when(self): | |
99 | return self.data.time_added |