Gentoo Archives: gentoo-commits

From: Slava Bacherikov <slava@××××××××××××××.ua>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/apps/packages/templatetags/, ...
Date: Wed, 27 Jun 2012 22:53:09
Message-Id: 1340837555.2b8d34a766395927b86fb0f358442927b6fd6036.bacher09@gentoo
1 commit: 2b8d34a766395927b86fb0f358442927b6fd6036
2 Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
3 AuthorDate: Wed Jun 27 22:52:35 2012 +0000
4 Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
5 CommitDate: Wed Jun 27 22:52:35 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=2b8d34a7
7
8 Add keywords table.
9
10 ---
11 gpackages/apps/packages/keywords.py | 25 ++++++++++++
12 gpackages/apps/packages/models.py | 43 ++++++++++++++++++++-
13 gpackages/apps/packages/templatetags/packages.py | 4 ++
14 gpackages/templates/ebuilds.html | 44 +--------------------
15 gpackages/templates/keywords_table.html | 27 +++++++++++++
16 gpackages/templates/packages.html | 46 +---------------------
17 6 files changed, 102 insertions(+), 87 deletions(-)
18
19 diff --git a/gpackages/apps/packages/keywords.py b/gpackages/apps/packages/keywords.py
20 new file mode 100644
21 index 0000000..0ab1e87
22 --- /dev/null
23 +++ b/gpackages/apps/packages/keywords.py
24 @@ -0,0 +1,25 @@
25 +from functools import total_ordering
26 +from package_info.generic import ToStrMixin
27 +
28 +class KeywordRepr(ToStrMixin):
29 +
30 + __slots__ = ('status', 'arch')
31 +
32 + status_repr_list = ('', '+', '~','-')
33 + status_class_list = ('blank', 'stable', 'unstable', 'hardmask')
34 +
35 + def __init__(self, arch, status):
36 + self.arch = arch
37 + self.status = status
38 +
39 + @property
40 + def status_repr(self):
41 + return self.status_repr_list[self.status + 1]
42 +
43 + @property
44 + def status_class(self):
45 + return self.status_class_list[self.status + 1]
46 +
47 + def __unicode__(self):
48 + return unicode(self.status_repr + self.arch)
49 +
50
51 diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
52 index 290516c..187088e 100644
53 --- a/gpackages/apps/packages/models.py
54 +++ b/gpackages/apps/packages/models.py
55 @@ -1,10 +1,11 @@
56 from django.db import models
57 -
58 from package_info.abstract import AbstractCategory, AbstarctPackage, \
59 AbstractEbuild
60 import managers
61 from package_info.generic import get_from_kwargs_and_del
62 from package_info.repo_info import REPOS_TYPE
63 +# relative
64 +from .keywords import KeywordRepr
65
66 from django.core.validators import URLValidator, validate_email
67 from django.core.exceptions import ValidationError
68 @@ -305,6 +306,13 @@ class PackageModel(AbstractDateTimeModel):
69 self.metadata_hash = package.metadata_sha1
70 self.description = package.description
71
72 + def get_ebuilds_and_keywords(self, arch_list):
73 + l = []
74 + for ebuild in self.ebuildmodel_set.order_by('-version', '-revision'):
75 + l.extend(ebuild.get_ebuilds_and_keywords(arch_list))
76 + return l
77 +
78 +
79 class Meta:
80 unique_together = ('virtual_package', 'repository')
81 ordering = ('-updated_datetime',)
82 @@ -438,6 +446,39 @@ class EbuildModel(AbstractDateTimeModel):
83 def fullversion(self):
84 return '%s%s' % (self.version, ('-'+ self.revision if self.revision else ''))
85
86 + def get_keywords(self, arch_list):
87 + keywords_dict = self.get_keywords_dict(arch_list)
88 + return (KeywordRepr(arch, keywords_dict[arch]) for arch in arch_list)
89 +
90 + def get_keywords_dict(self, arch_list):
91 + arch_set = set(arch_list)
92 + keywords_list = self.load_keywords(arch_set)
93 + keywords_cache_dict = {}
94 + for keyword in keywords_list:
95 + keywords_cache_dict[keyword.arch.name] = keyword
96 +
97 + keywords_dict = {}
98 + keyword_wild = keywords_cache_dict.get('*')
99 + for arch in arch_list:
100 + keyword_obj = keywords_cache_dict.get(arch)
101 + status = -1
102 + if keyword_obj is not None:
103 + status = keyword_obj.status
104 + elif keyword_wild is not None:
105 + status = keyword_wild.status
106 + keywords_dict[arch] = status
107 +
108 + return keywords_dict
109 +
110 + def load_keywords(self, arch_set):
111 + arch_set.add('*')
112 + return self.keyword_set.filter(arch__name__in = arch_set).select_related('arch')
113 +
114 + def get_ebuilds_and_keywords(self, arch_list):
115 + # Maybe copy object ? !!
116 + self.keywords = self.get_keywords(arch_list)
117 + return (self, )
118 +
119 class Meta:
120 unique_together = ('package', 'version', 'revision')
121 ordering = ('-updated_datetime',)
122
123 diff --git a/gpackages/apps/packages/templatetags/packages.py b/gpackages/apps/packages/templatetags/packages.py
124 index 80fe826..45c756d 100644
125 --- a/gpackages/apps/packages/templatetags/packages.py
126 +++ b/gpackages/apps/packages/templatetags/packages.py
127 @@ -10,6 +10,10 @@ def last_updated():
128 l = RepositoryModel.objects.only('updated_datetime').latest('updated_datetime')
129 return {'last_updated': l.updated_datetime}
130
131 +@××××××××.inclusion_tag('keywords_table.html')
132 +def render_keywords_table(obj, *arch_list):
133 + ebuilds = obj.get_ebuilds_and_keywords(arch_list)
134 + return {'arches': arch_list, 'ebuilds' : ebuilds}
135
136 def text_sincode(text):
137 text_l = map(lambda x: '&#%s;' % ord(x), text)
138
139 diff --git a/gpackages/templates/ebuilds.html b/gpackages/templates/ebuilds.html
140 index 81ca0b8..ef51a43 100644
141 --- a/gpackages/templates/ebuilds.html
142 +++ b/gpackages/templates/ebuilds.html
143 @@ -1,4 +1,5 @@
144 {% extends "base.html" %}
145 +{% load packages %}
146
147 {% block content %}
148 {% for ebuild in ebuilds %}
149 @@ -8,48 +9,7 @@
150 <span class="package_update_datetime">{{ ebuild.updated_datetime }}</span>
151 </div>
152 <div style="padding-bottom: 10px; margin 10px;">{{ ebuild.description }}</div>
153 - <table class="keywords table table-bordered table-condensed">
154 - <colgroup>
155 - <col class="span2">
156 - <col class="span1">
157 - <col class="span1">
158 - <col class="span1">
159 - <col class="span1">
160 - <col class="span1">
161 - <col class="span1">
162 - <col class="span1">
163 - <col class="span1">
164 - <col class="span1">
165 - </colgroup>
166 - <thead>
167 - <tr class="">
168 - <th class=""></th>
169 - <th class="">alpha</th>
170 - <th class="">amd64</th>
171 - <th class="">arm</th>
172 - <th class="">hppa</th>
173 - <th class="">ia64</th>
174 - <th class="">ppc</th>
175 - <th class="">ppc64</th>
176 - <th class="">sparc</th>
177 - <th class="">x86</th>
178 - </tr>
179 - </thead>
180 - <tbody>
181 - <tr>
182 - <td class="ebuild">{{ ebuild.fullversion }}</td>
183 - <td class="blank"></td>
184 - <td class="unstable">~</td>
185 - <td class="blank"></td>
186 - <td class="blank"></td>
187 - <td class="blank"></td>
188 - <td class="blank"></td>
189 - <td class="blank"></td>
190 - <td class="blank"></td>
191 - <td class="unstable">~</td>
192 - </tr>
193 - </tbody>
194 - </table>
195 + {% render_keywords_table ebuild 'alpha' 'amd64' 'arm' 'hppa' 'ia64' 'ppc' 'ppc64' 'sparc' 'x86' %}
196 </div>
197 {% endfor %}
198 {% include 'paginator.html' %}
199
200 diff --git a/gpackages/templates/keywords_table.html b/gpackages/templates/keywords_table.html
201 new file mode 100644
202 index 0000000..38cba68
203 --- /dev/null
204 +++ b/gpackages/templates/keywords_table.html
205 @@ -0,0 +1,27 @@
206 +<table class="keywords table table-bordered table-condensed">
207 + <colgroup>
208 + <col class="span2">
209 + {% for arch in arches %}
210 + <col class="span1">
211 + {% endfor %}
212 +
213 + </colgroup>
214 + <thead>
215 + <tr class="">
216 + <th class=""></th>
217 + {% for arch in arches %}
218 + <th class="">{{ arch }}</th>
219 + {% endfor %}
220 + </tr>
221 + </thead>
222 + <tbody>
223 + {% for ebuild in ebuilds %}
224 + <tr>
225 + <td class="ebuild">{{ ebuild.fullversion }}</td>
226 + {% for keyword in ebuild.keywords %}
227 + <td class="{{ keyword.status_class }}">{{ keyword.status_repr }}</td>
228 + {% endfor %}
229 + </tr>
230 + {% endfor %}
231 + </tbody>
232 +</table>
233
234 diff --git a/gpackages/templates/packages.html b/gpackages/templates/packages.html
235 index adead16..b6600dc 100644
236 --- a/gpackages/templates/packages.html
237 +++ b/gpackages/templates/packages.html
238 @@ -1,4 +1,5 @@
239 {% extends "base.html" %}
240 +{% load packages %}
241
242 {% block content %}
243 {% for package in packages %}
244 @@ -10,50 +11,7 @@
245 {% if package.description %}
246 <div style="padding-bottom: 10px; margin 10px;">{{ package.description }}</div>
247 {% endif %}
248 - <table class="keywords table table-bordered table-condensed">
249 - <colgroup>
250 - <col class="span2">
251 - <col class="span1">
252 - <col class="span1">
253 - <col class="span1">
254 - <col class="span1">
255 - <col class="span1">
256 - <col class="span1">
257 - <col class="span1">
258 - <col class="span1">
259 - <col class="span1">
260 - </colgroup>
261 - <thead>
262 - <tr class="">
263 - <th class=""></th>
264 - <th class="">alpha</th>
265 - <th class="">amd64</th>
266 - <th class="">arm</th>
267 - <th class="">hppa</th>
268 - <th class="">ia64</th>
269 - <th class="">ppc</th>
270 - <th class="">ppc64</th>
271 - <th class="">sparc</th>
272 - <th class="">x86</th>
273 - </tr>
274 - </thead>
275 - <tbody>
276 - {% for ebuild in package.ebuildmodel_set.all_by_numbers %}
277 - <tr>
278 - <td class="ebuild">{{ ebuild.fullversion }}</td>
279 - <td class="blank"></td>
280 - <td class="unstable">~</td>
281 - <td class="blank"></td>
282 - <td class="blank"></td>
283 - <td class="blank"></td>
284 - <td class="blank"></td>
285 - <td class="blank"></td>
286 - <td class="blank"></td>
287 - <td class="unstable">~</td>
288 - </tr>
289 - {% endfor %}
290 - </tbody>
291 - </table>
292 + {% render_keywords_table package 'alpha' 'amd64' 'arm' 'hppa' 'ia64' 'ppc' 'ppc64' 'sparc' 'x86' %}
293 </div>
294 {% endfor %}
295 {% include 'paginator.html' %}