Unverified Commit d8b8f55a authored by David Runge's avatar David Runge
Browse files

Correct and extend models and defaults

repo_management/defaults.py:
Add the IntEnum `RepoDbType` to be able to identify/address the
different types of binary database files (e.g. .db vs. .files).
Change the %LICENSE% entry in `DESC_JSON` to not track the name in
plural (use "license" instead of "licenses") to stay in line with the
naming of the original variable.

repo_management/models.py:
Change the `License` model to track an optional list of license
identifiers using the singular term ("license" instead of "licenses") to
have more predictable and coherent naming of variables and attributes.
Add `Base` to `OutputPackageBase` as this way the model is more complete
and it becomes much easier to use it, without having to also pass the
pkgbase alongside it.
Add the convenience method `get_packages_as_models()` to
`OutputPackageBase` which returns the list of packages as tuples of
`PackageDesc` and `Files`.
parent e34e019b
......@@ -8,6 +8,21 @@ class RepoDbMemberType(IntEnum):
FILES = 2
class RepoDbType(IntEnum):
"""An IntEnum to distinguish types of binary repository database files
Attributes
----------
DEFAULT: int
Use this to identify .db files
FILES: int
Use this to identify .files files
"""
DEFAULT = 0
FILES = 2
class FieldType(IntEnum):
STRING = 0
INT = 1
......@@ -30,7 +45,7 @@ DESC_JSON: Dict[str, Dict[str, Union[str, FieldType]]] = {
"%SHA256SUM%": {"name": "sha256sum", "type": FieldType.STRING},
"%PGPSIG%": {"name": "pgpsig", "type": FieldType.STRING},
"%URL%": {"name": "url", "type": FieldType.STRING},
"%LICENSE%": {"name": "licenses", "type": FieldType.STRING_LIST},
"%LICENSE%": {"name": "license", "type": FieldType.STRING_LIST},
"%ARCH%": {"name": "arch", "type": FieldType.STRING},
"%BUILDDATE%": {"name": "builddate", "type": FieldType.INT},
"%PACKAGER%": {"name": "packager", "type": FieldType.STRING},
......
import io
from typing import List, Optional
from typing import List, Optional, Tuple
from pydantic import BaseModel
......@@ -108,7 +108,7 @@ class License(BaseModel):
"""A model describing the %LICENSE% header in a 'desc' file, which type it represents and whether it is required or
not"""
licenses: List[str]
license: Optional[List[str]]
class Arch(BaseModel):
......@@ -264,6 +264,7 @@ class OutputPackage(
class OutputPackageBase(
Base,
MakeDepends,
Packager,
Version,
......@@ -273,3 +274,47 @@ class OutputPackageBase(
"""
packages: List[OutputPackage]
def get_packages_as_models(self) -> List[Tuple[PackageDesc, Files]]:
"""Return the list of packages as tuples of PackageDesc and Files models
Returns
-------
List[Tuple[PackageDesc, Files]]
A list of tuples with one PackageDesc and one Files each
"""
return [
(
PackageDesc(
arch=package.arch,
backup=package.backup,
base=self.base,
builddate=package.builddate,
checkdepends=package.checkdepends,
conflicts=package.conflicts,
csize=package.csize,
depends=package.depends,
desc=package.desc,
filename=package.filename,
groups=package.groups,
isize=package.isize,
license=package.license,
makedepends=self.makedepends,
md5sum=package.md5sum,
name=package.name,
optdepends=package.optdepends,
packager=self.packager,
pgpsig=package.pgpsig,
provides=package.provides,
replaces=package.replaces,
sha256sum=package.sha256sum,
url=package.url,
version=self.version,
),
Files(
files=package.files
),
)
for package in self.packages
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment