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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
import json
from django.db import models
from django.core.validators import RegexValidator, validate_email, URLValidator
from django.core.exceptions import ValidationError
from django.contrib.auth.models import User
from djeuscan.managers import PackageManager, VersionLogManager, \
EuscanResultManager
validate_category = RegexValidator("^(?:\w+?-\w+?)|virtual$")
validate_name = RegexValidator("^\S+?$")
validate_revision = RegexValidator("^r\d+?$")
validate_url = URLValidator()
class Herd(models.Model):
"""
A herd is a collection of packages
"""
herd = models.CharField(max_length=128, unique=True,
validators=[validate_name])
email = models.CharField(max_length=128, blank=True, null=True,
validators=[validate_email])
maintainers = models.ManyToManyField("Maintainer")
def __unicode__(self):
if self.email:
return '%s <%s>' % (self.herd, self.email)
return self.herd
def save(self, *args, **kwargs):
self.full_clean()
super(Herd, self).save(*args, **kwargs)
class Maintainer(models.Model):
"""
The person who maintains a package
"""
name = models.CharField(max_length=128)
email = models.CharField(max_length=128, unique=True,
validators=[validate_email])
def __unicode__(self):
return '%s <%s>' % (self.name, self.email)
def save(self, *args, **kwargs):
self.full_clean()
super(Maintainer, self).save(*args, **kwargs)
class Package(models.Model):
"""
A portage package
"""
category = models.CharField(max_length=128, validators=[validate_category])
name = models.CharField(max_length=128, validators=[validate_name])
description = models.TextField(blank=True)
homepage = models.TextField(blank=True)
herds = models.ManyToManyField(Herd, blank=True)
maintainers = models.ManyToManyField(Maintainer, blank=True)
# For performance, we keep pre-computed counters
n_versions = models.IntegerField(default=0)
n_packaged = models.IntegerField(default=0)
n_overlay = models.IntegerField(default=0)
# And we also pre-compute last versions
last_version_gentoo = models.ForeignKey(
'Version', blank=True, null=True, related_name="last_version_gentoo",
on_delete=models.SET_NULL
)
last_version_overlay = models.ForeignKey(
'Version', blank=True, null=True, related_name="last_version_overlay",
on_delete=models.SET_NULL
)
last_version_upstream = models.ForeignKey(
'Version', blank=True, null=True, related_name="last_version_upstream",
on_delete=models.SET_NULL
)
objects = PackageManager()
class Meta:
unique_together = ['category', 'name']
def cp(self):
return '%s/%s' % (self.category, self.name)
def __unicode__(self):
return self.cp()
def save(self, *args, **kwargs):
self.full_clean()
# Clean urls, accept only real urls
urls = []
for url in self.homepages:
try:
validate_url(url)
except ValidationError:
pass
else:
urls.append(url)
self.homepage = " ".join(urls)
super(Package, self).save(*args, **kwargs)
@property
def homepages(self):
return self.homepage.split(' ')
@property
def last_version(self):
from euscan.helpers import vercmp
versions = [
self.last_version_gentoo,
self.last_version_overlay,
self.last_version_upstream
]
_cmp = lambda x, y: vercmp(
unicode(self), x.version if x else "", y.version if y else ""
)
return sorted(versions, cmp=_cmp)[-1]
class Version(models.Model):
"""
Version associated to a package
"""
package = models.ForeignKey(Package)
slot = models.CharField(max_length=128, blank=True, default="")
revision = models.CharField(max_length=128)
version = models.CharField(max_length=128)
packaged = models.BooleanField()
overlay = models.CharField(max_length=128, default='gentoo', db_index=True,
validators=[validate_name], blank=True)
urls = models.TextField(blank=True)
alive = models.BooleanField(default=True, db_index=True)
vtype = models.CharField(max_length=128, blank=True)
handler = models.CharField(max_length=128, blank=True)
confidence = models.IntegerField(default=0)
ebuild_path = models.CharField(blank=True, max_length=256)
metadata_path = models.CharField(blank=True, max_length=256)
class Meta:
unique_together = ['package', 'slot', 'revision', 'version', 'overlay']
@property
def tag(self):
return '%s-%s:%s-%s' % (self.version, self.revision, self.slot,
self.overlay)
def cpv(self):
return '%s/%s-%s%s' % (
self.package.category, self.package.name, self.version,
'-' + self.revision if self.revision != '-r0' else ''
)
def __unicode__(self):
return '%s/%s-%s%s:%s [%s]' % (
self.package.category, self.package.name, self.version,
'-' + self.revision if self.revision != '-r0' else '',
self.slot, self.overlay or "<upstream>"
)
def save(self, *args, **kwargs):
self.full_clean()
super(Version, self).save(*args, **kwargs)
class VersionLog(models.Model):
VERSION_ADDED = 1
VERSION_REMOVED = 2
VERSION_ACTIONS = (
(VERSION_ADDED, 'Added'),
(VERSION_REMOVED, 'Removed')
)
package = models.ForeignKey(Package)
datetime = models.DateTimeField(auto_now_add=True)
slot = models.CharField(max_length=128, blank=True, default="")
revision = models.CharField(max_length=128)
version = models.CharField(max_length=128)
packaged = models.BooleanField()
overlay = models.CharField(max_length=128, default='gentoo',
validators=[validate_name], blank=True)
action = models.IntegerField(choices=VERSION_ACTIONS)
vtype = models.CharField(max_length=128, blank=True)
objects = VersionLogManager()
@property
def tag(self):
return '%s-%s:%s-%s' % (self.version, self.revision, self.slot,
self.overlay)
def __unicode__(self):
txt = '+ ' if self.action == self.VERSION_ADDED else '- '
txt += '%s/%s-%s-%s:%s [%s]' % (
self.package.category, self.package.name, self.version,
self.revision, self.slot,
self.overlay or '<upstream>'
)
return txt
def save(self, *args, **kwargs):
self.full_clean()
super(VersionLog, self).save(*args, **kwargs)
class EuscanResult(models.Model):
package = models.ForeignKey(Package)
datetime = models.DateTimeField()
result = models.TextField(blank=True)
scan_time = models.FloatField(null=True, blank=True)
ebuild = models.CharField(blank=True, max_length=256)
objects = EuscanResultManager()
class Meta:
get_latest_by = "datetime"
def save(self, *args, **kwargs):
self.full_clean()
super(EuscanResult, self).save(*args, **kwargs)
@property
def messages(self):
try:
result = json.loads(self.result)
except ValueError:
return self.result
if result and self.package.cp() in result:
return result[self.package.cp()]['messages']
else:
return ""
def __unicode__(self):
return '[%s] %s/%s' % (
self.datetime, self.package.category, self.package.name
)
class Category(models.Model):
name = models.CharField(max_length=128, validators=[validate_category],
unique=True)
def __unicode__(self):
return self.name
class Overlay(models.Model):
name = models.CharField(max_length=128, validators=[validate_name],
unique=True)
def __unicode__(self):
return self.name
class Log(models.Model):
"""
Model used for keeping data for charts
"""
datetime = models.DateTimeField()
# Packages up to date in the main portage tree
n_packages_gentoo = models.IntegerField(default=0)
# Packages up to date in an overlay
n_packages_overlay = models.IntegerField(default=0)
# Packages outdated
n_packages_outdated = models.IntegerField(default=0)
# Versions in the main portage tree
n_versions_gentoo = models.IntegerField(default=0)
# Versions in overlays
n_versions_overlay = models.IntegerField(default=0)
# Upstream versions, not in the main tree or overlays
n_versions_upstream = models.IntegerField(default=0)
def __unicode__(self):
return u'[%d:%d:%d] [%d:%d:%d]' % (
self.n_packages_gentoo, self.n_packages_overlay,
self.n_packages_outdated, self.n_versions_gentoo,
self.n_versions_overlay, self.n_versions_upstream
)
def save(self, *args, **kwargs):
self.full_clean()
super(Log, self).save(*args, **kwargs)
class WorldLog(Log):
def __unicode__(self):
return u'world ' + Log.__unicode__(self)
class CategoryLog(Log):
category = models.CharField(max_length=128, validators=[validate_category])
def __unicode__(self):
return u'%s %s' % (self.category, Log.__unicode__(self))
class HerdLog(Log):
herd = models.ForeignKey(Herd)
def __unicode__(self):
return u'%s %s' % (self.herd, Log.__unicode__(self))
class MaintainerLog(Log):
maintainer = models.ForeignKey(Maintainer)
def __unicode__(self):
return u'%s %s' % (self.maintainer, Log.__unicode__(self))
class RefreshPackageQuery(models.Model):
package = models.ForeignKey(Package)
priority = models.IntegerField(default=0)
users = models.ManyToManyField(User)
@property
def position(self):
ordered = RefreshPackageQuery.objects.all().order_by("-priority")
for pos, obj in enumerate(ordered, start=1):
if obj == self:
return pos
def __unicode__(self):
return u'[%d] %s' % (self.priority, self.package)
class ProblemReport(models.Model):
package = models.ForeignKey(Package)
version = models.ForeignKey(Version, null=True, blank=True)
subject = models.CharField(max_length=128)
message = models.TextField()
datetime = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
return u"[%s] %s" % (self.datetime, self.package)
|