-
Notifications
You must be signed in to change notification settings - Fork 49
Closed
Labels
Description
Probably in a new contrib/
module as a django_models.py
:
from django.db import models
class PackageURLMixin(models.Model):
"""
Abstract Model for Package URL "purl" fields support.
"""
type = models.CharField(
max_length=16,
blank=True,
null=True,
help_text=_(
'A short code to identify the type of this package. '
'For example: gem for a Rubygem, docker for a container, '
'pypi for a Python Wheel or Egg, maven for a Maven Jar, '
'deb for a Debian package, etc.'
)
)
namespace = models.CharField(
max_length=255,
blank=True,
null=True,
help_text=_(
'Package name prefix, such as Maven groupid, Docker image owner, '
'GitHub user or organization, etc.'
),
)
name = models.CharField(
max_length=100,
blank=True,
null=True,
help_text=_('Name of the package.'),
)
version = models.CharField(
max_length=50,
blank=True,
null=True,
help_text=_('Version of the package.'),
)
qualifiers = models.CharField(
max_length=1024,
blank=True,
null=True,
help_text=_(
'Extra qualifying data for a package such as the name of an OS, '
'architecture, distro, etc.'
),
)
subpath = models.CharField(
max_length=200,
blank=True,
null=True,
help_text=_(
'Extra subpath within a package, relative to the package root.'
),
)
class Meta:
abstract = True
@property
def package_url(self):
"""
Return a compact Package URL "purl" string.
"""
try:
purl = PackageURL(
self.type, self.namespace, self.name,
self.version, self.qualifiers, self.subpath
)
except ValueError:
return ''
return str(purl)
Signed-off-by: Thomas Druez tdruez@nexb.com