models.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2013 The Distro Tracker Developers
  3. # See the COPYRIGHT file at the top-level directory of this distribution and
  4. # at http://deb.li/DTAuthors
  5. #
  6. # This file is part of Distro Tracker. It is subject to the license terms
  7. # in the LICENSE file found in the top-level directory of this
  8. # distribution and at http://deb.li/DTLicense. No part of Distro Tracker,
  9. # including this file, may be copied, modified, propagated, or distributed
  10. # except according to the terms contained in the LICENSE file.
  11. """
  12. Debian-specific models.
  13. """
  14. from __future__ import unicode_literals
  15. from django.db import models
  16. from django.utils.encoding import python_2_unicode_compatible
  17. from distro_tracker.core.utils import SpaceDelimitedTextField
  18. from distro_tracker.core.utils import get_or_none
  19. from distro_tracker.core.models import PackageName
  20. from distro_tracker.core.models import SourcePackageName
  21. from jsonfield import JSONField
  22. import re
  23. @python_2_unicode_compatible
  24. class DebianContributor(models.Model):
  25. """
  26. Model containing additional Debian-specific information about contributors.
  27. """
  28. email = models.OneToOneField('django_email_accounts.UserEmail')
  29. agree_with_low_threshold_nmu = models.BooleanField(default=False)
  30. is_debian_maintainer = models.BooleanField(default=False)
  31. allowed_packages = SpaceDelimitedTextField(blank=True)
  32. def __str__(self):
  33. return 'Debian contributor <{email}>'.format(email=self.email)
  34. @python_2_unicode_compatible
  35. class LintianStats(models.Model):
  36. """
  37. Model for lintian stats of packages.
  38. """
  39. package = models.OneToOneField(PackageName, related_name='lintian_stats')
  40. stats = JSONField()
  41. def __str__(self):
  42. return 'Lintian stats for package {package}'.format(
  43. package=self.package)
  44. def get_lintian_url(self, full=False):
  45. """
  46. Returns the lintian URL for the package matching the
  47. :class:`LintianStats
  48. <distro_tracker.vendor.debian.models.LintianStats>`.
  49. :param full: Whether the URL should include the full lintian report or
  50. only the errors and warnings.
  51. :type full: Boolean
  52. """
  53. package = get_or_none(SourcePackageName, pk=self.package.pk)
  54. if not package:
  55. return ''
  56. maintainer_email = ''
  57. if package.main_version:
  58. maintainer = package.main_version.maintainer
  59. if maintainer:
  60. maintainer_email = maintainer.email
  61. # Adapt the maintainer URL to the form expected by lintian.debian.org
  62. lintian_maintainer_email = re.sub(
  63. r"""[àáèéëêòöøîìùñ~/\(\)" ']""",
  64. '_',
  65. maintainer_email)
  66. report = 'full' if full else 'maintainer'
  67. return (
  68. 'https://lintian.debian.org/{report}/'
  69. '{maintainer}.html#{pkg}'.format(
  70. report=report,
  71. maintainer=lintian_maintainer_email,
  72. pkg=self.package)
  73. )
  74. @python_2_unicode_compatible
  75. class PackageTransition(models.Model):
  76. package = models.ForeignKey(PackageName, related_name='package_transitions')
  77. transition_name = models.CharField(max_length=50)
  78. status = models.CharField(max_length=50, blank=True, null=True)
  79. reject = models.BooleanField(default=False)
  80. def __str__(self):
  81. return "Transition {name} ({status}) for package {pkg}".format(
  82. name=self.transition_name, status=self.status, pkg=self.package)
  83. @python_2_unicode_compatible
  84. class PackageExcuses(models.Model):
  85. package = models.OneToOneField(PackageName, related_name='excuses')
  86. excuses = JSONField()
  87. def __str__(self):
  88. return "Excuses for the package {pkg}".format(pkg=self.package)
  89. @python_2_unicode_compatible
  90. class BuildLogCheckStats(models.Model):
  91. package = models.OneToOneField(
  92. SourcePackageName,
  93. related_name='build_logcheck_stats')
  94. stats = JSONField()
  95. def __str__(self):
  96. return "Build logcheck stats for {pkg}".format(pkg=self.package)
  97. @python_2_unicode_compatible
  98. class UbuntuPackage(models.Model):
  99. package = models.OneToOneField(
  100. PackageName,
  101. related_name='ubuntu_package')
  102. version = models.TextField(max_length=100)
  103. bugs = JSONField(null=True, blank=True)
  104. patch_diff = JSONField(null=True, blank=True)
  105. def __str__(self):
  106. return "Ubuntu package info for {pkg}".format(pkg=self.package)