Skip to content

Commit

Permalink
Add model fields for Package type
Browse files Browse the repository at this point in the history
  • Loading branch information
dralley committed May 3, 2018
1 parent 95d6d00 commit 4dc2beb
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 14 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ python:
- "3.5"
- "3.6"
env:
- DB=sqlite
- DB=postgres
addons:
# postgres versions provided by el7 RHSCL (lowest supportable version)
Expand Down
24 changes: 24 additions & 0 deletions pulp_rpm/app/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from types import SimpleNamespace

CHECKSUM_TYPES = SimpleNamespace(
UNKNOWN='unknown',
MD5='md5',
SHA='sha1', # compatibility nickname from original createrepo
SHA1='sha1',
SHA224='sha224',
SHA256='sha256',
SHA384='sha384',
SHA512='sha512'
)

# The same as above, but in a format that choice fields can use
CHECKSUM_CHOICES = (
(CHECKSUM_TYPES.UNKNOWN, CHECKSUM_TYPES.UNKNOWN),
(CHECKSUM_TYPES.MD5, CHECKSUM_TYPES.MD5),
(CHECKSUM_TYPES.SHA, CHECKSUM_TYPES.SHA),
(CHECKSUM_TYPES.SHA1, CHECKSUM_TYPES.SHA1),
(CHECKSUM_TYPES.SHA224, CHECKSUM_TYPES.SHA224),
(CHECKSUM_TYPES.SHA256, CHECKSUM_TYPES.SHA256),
(CHECKSUM_TYPES.SHA384, CHECKSUM_TYPES.SHA384),
(CHECKSUM_TYPES.SHA512, CHECKSUM_TYPES.SHA512)
)
196 changes: 183 additions & 13 deletions pulp_rpm/app/models.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,203 @@
from logging import getLogger

from django.db import models
from pulpcore.plugin.models import Content, Remote, Publisher

from pulp_rpm.app.constants import CHECKSUM_CHOICES


log = getLogger(__name__)


class RpmContent(Content):
"""
The "rpm" content type.
The "rpm" content type. Maps directly to the fields provided by createrepo_c
Description of the content type.
https://github.com/rpm-software-management/createrepo_c/
Fields:
field1 (type): Description of the field1
field2 (type): Description of the field2
...
name (Text):
Name of the package
epoch (Text):
The package's epoch
version (Text):
The version of the package. For example, '2.8.0'
release (Text):
The release of a particular version of the package. Although this field
can technically be anything, packaging guidelines usually require it to
be an integer followed by the platform, e.g. '1.el7' or '3.f24'. This field
is incremented by the packager whenever a new release of the same version
is created.
arch (Text):
The target architecture for a package. For example, 'x86_64', 'i686', or 'noarch'.
pkgId (Text):
Checksum of the package file
checksum_type (Text):
Type of checksum, e.g. 'sha256', 'md5'
summary (Text):
Short description of the packaged software
description (Text):
In-depth description of the packaged software
url (Text):
URL with more information about the packaged software. This could be the project's
website or its code repository.
changelogs (Text):
Changelogs that package contains - see comments below
files (Text):
Files that package contains - see comments below
requires (Text):
Capabilities the package requires - see comments below
provides (Text):
Capabilities the package provides - see comments below
conflicts (Text):
Capabilities the package conflicts with - see comments below
obsoletes (Text):
Capabilities the package obsoletes - see comments below
suggests (Text):
Capabilities the package suggests - see comments below
enhances (Text):
Capabilities the package enhances - see comments below
recommends (Text):
Capabilities the package recommends - see comments below
supplements (Text):
Capabilities the package supplements - see comments below
location_base (Text):
Base location of this package
location_href (Text):
Relative location of package to the repodata
rpm_buildhost (Text):
Hostname of the system that built the package
rpm_group (Text):
RPM group (See: http://fedoraproject.org/wiki/RPMGroups)
rpm_header_end (Text):
Last byte of the header
rpm_header_start (Text):
First byte of the header
rpm_license (Text):
License term applicable to the package software (GPLv2, etc.)
rpm_packager (Text):
Person or persons responsible for creating the package
rpm_sourcerpm (Text):
Name of the source package (srpm) the package was built from
rpm_vendor (Text):
Name of the organization that produced the package
size_archive (BigInteger):
Size, in bytes, of the archive portion of the original package file
size_installed (BigInteger):
Total size, in bytes, of every file installed by this package
size_package (BigInteger):
Size, in bytes, of the package
time_build (BigInteger):
Time the package was built in seconds since the epoch.
time_file (BigInteger):
The mtime of the package file in seconds since the epoch; this is the 'file' time
attribute in the primary XML.
"""
TYPE = 'type'
TYPE = 'rpm'

# Required metadata
name = models.TextField()
epoch = models.TextField()
version = models.TextField()
release = models.TextField()
arch = models.TextField()

pkgId = models.TextField() # formerly "checksum"
checksum_type = models.TextField(choices=CHECKSUM_CHOICES)

# Optional metadata
summary = models.TextField(blank=True)
description = models.TextField(blank=True)
url = models.TextField(blank=True)

# A string containing a JSON-encoded list of dictionaries, each of which represents a single
# changelog. Each changelog dict contains the following fields:
#
# date (int): date of changelog - seconds since epoch
# author (str): author of the changelog
# changelog (str: changelog text
changelogs = models.TextField(default='[]', blank=True)

# field1 = models.TextField(blank=False, null=False)
# field2 = models.TextField(blank=False, null=False)
# A string containing a JSON-encoded list of files, each of which represents a single file.
# Each file dict contains the following fields:
#
# type (str): one of "" (regular file), "dir", "ghost"
# path (str): path to file
# name (str): filename
files = models.TextField(default='[]', blank=True)

# class Meta:
# unique_together = (
# 'field1',
# 'field2'
# )
# Each of these is a string containing a JSON-encoded list of dictionaries, each of which
# represents a dependency. Each dependency dict contains the following fields.
#
# name (str): name
# flags (str): flags
# epoch (str): epoch
# version (str): version
# release (str): release
# pre (bool): preinstall
requires = models.TextField(default='[]', blank=True)
provides = models.TextField(default='[]', blank=True)
conflicts = models.TextField(default='[]', blank=True)
obsoletes = models.TextField(default='[]', blank=True)
suggests = models.TextField(default='[]', blank=True)
enhances = models.TextField(default='[]', blank=True)
recommends = models.TextField(default='[]', blank=True)
supplements = models.TextField(default='[]', blank=True)

location_base = models.TextField(blank=True)
location_href = models.TextField(blank=True)

rpm_buildhost = models.TextField(blank=True)
rpm_group = models.TextField(blank=True)
rpm_license = models.TextField(blank=True)
rpm_packager = models.TextField(blank=True)
rpm_sourcerpm = models.TextField(blank=True)
rpm_vendor = models.TextField(blank=True)
rpm_header_start = models.BigIntegerField(null=True, blank=True)
rpm_header_end = models.BigIntegerField(null=True, blank=True)

size_archive = models.BigIntegerField(null=True, blank=True)
size_installed = models.BigIntegerField(null=True, blank=True)
size_package = models.BigIntegerField(null=True, blank=True)

time_build = models.BigIntegerField(null=True, blank=True)
time_file = models.BigIntegerField(null=True, blank=True)

@property
def nevra(self):
""" Package NEVRA string (Name-Epoch-Version-Release-Architecture)
"""
return "{n}-{e}:{v}-{r}.{a}".format(
n=self.name, e=self.epoch, v=self.version, r=self.release, a=self.arch)

@property
def nvra(self):
""" Package NVRA string (Name-Version-Release-Architecture)
"""
return "{n}-{v}-{r}.{a}".format(
n=self.name, v=self.version, r=self.release, a=self.arch)

class Meta:
unique_together = (
'name', 'epoch', 'version', 'release', 'arch', 'checksumtype', 'checksum'
)


class SrpmContent(RpmContent):
"""
The "srpm" content type
(same as the "rpm" content type)
"""
TYPE = 'rpm'


class RpmRemote(Remote):
Expand Down

0 comments on commit 4dc2beb

Please sign in to comment.