Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nikromen committed Nov 19, 2023
1 parent 8f81962 commit 08d46a7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import flask
from flask_restx import Namespace, Resource
from coprs.views.misc import api_login_required
from coprs.views.misc import api_login_required, get_from_payload
from coprs.views.apiv3_ns import apiv3_ns, api, rename_fields_helper
from coprs.views.apiv3_ns.schema import (
from coprs.views.apiv3_ns.schema.schemas import (
project_chroot_model,
project_chroot_build_config_model,
project_chroot_parser,
project_chroot_get_input_model,
)
from coprs.logic.complex_logic import ComplexLogic, BuildConfigLogic
from coprs.exceptions import ObjectNotFound, InvalidForm
Expand Down Expand Up @@ -75,35 +75,35 @@ def rename_fields(input_dict):

@apiv3_project_chroots_ns.route("/")
class ProjectChroot(Resource):
parser = project_chroot_parser()

@apiv3_project_chroots_ns.expect(parser)
@apiv3_project_chroots_ns.expect(project_chroot_get_input_model)
@apiv3_project_chroots_ns.marshal_with(project_chroot_model)
def get(self):
"""
Get a project chroot
Get settings for a single project chroot.
"""
args = self.parser.parse_args()
copr = get_copr(args.ownername, args.projectname)
chroot = ComplexLogic.get_copr_chroot_safe(copr, args.chrootname)
ownername, projectname, chrootname = get_from_payload(
apiv3_project_chroots_ns.payload, "ownername", "projectname", "chrootname"
)
copr = get_copr(ownername, projectname)
chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname)
return to_dict(chroot)


@apiv3_project_chroots_ns.route("/build-config")
class BuildConfig(Resource):
parser = project_chroot_parser()

@apiv3_project_chroots_ns.expect(parser)
@apiv3_project_chroots_ns.expect(project_chroot_get_input_model)
@apiv3_project_chroots_ns.marshal_with(project_chroot_build_config_model)
def get(self):
"""
Get a build config
Generate a build config based on a project chroot settings.
"""
args = self.parser.parse_args()
copr = get_copr(args.ownername, args.projectname)
chroot = ComplexLogic.get_copr_chroot_safe(copr, args.chrootname)
ownername, projectname, chrootname = get_from_payload(
apiv3_project_chroots_ns.payload, "ownername", "projectname", "chrootname"
)
copr = get_copr(ownername, projectname)
chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname)
if not chroot:
raise ObjectNotFound('Chroot not found.')
return to_build_config_dict(chroot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def _generate_docs(field_names, extra_fields=None):
result_dict = {}
for field_name in field_names:
result_dict[field_name] = getattr(fields, field_names)
result_dict[field_name] = getattr(fields, field_name)

if extra_fields is None:
return result_dict
Expand Down
39 changes: 29 additions & 10 deletions frontend/coprs_frontend/coprs/views/apiv3_ns/schema/fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from flask_restx.fields import String, List, Integer, Boolean, Url, Raw

# TODO: you can split these fields to some hierarchy e.g. using dataclasses but I
# don't see any hierarchy in it
# TODO: split these fields to some hierarchy e.g. using dataclasses or to some clusters

# TODO: Use some shared constants for description - a lot of it is basically copied
# description from forms
Expand All @@ -14,6 +13,12 @@
example=123,
)


build_id = Integer(
description="ID of the build",
example=123456,
)

mock_chroot = String(
description="Mock chroot",
example="fedora-rawhide-x86_64",
Expand All @@ -24,7 +29,7 @@
example="@copr",
)

fullname = String(
full_name = String(
description="Full name of the project",
example="@copr/pull-requests",
)
Expand All @@ -44,6 +49,8 @@
example="copr-cli",
)

package_name = packagename

comps_name = String(
description="Name of the comps.xml file",
)
Expand Down Expand Up @@ -128,7 +135,7 @@

# TODO We are copy-pasting descriptions from web UI to this file. This field
# is an ideal candidate for figuring out how to share the descriptions
pypi_spec_generator = String(
spec_generator = String(
description=(
"Tool for generating specfile from a PyPI package. "
"The options are full-featured pyp2rpm with cross "
Expand All @@ -138,15 +145,15 @@
example="pyp2spec",
)

pypi_spec_template = String(
spec_template = String(
description=(
"Name of the spec template. "
"This option is limited to pyp2rpm spec generator."
),
example="default",
)

pypi_versions = List(
python_versions = List(
String, # We currently return string but should this be number?
description=(
"For what python versions to build. "
Expand Down Expand Up @@ -239,22 +246,22 @@
example="hello",
)

custom_script = String(
script = String(
description="Script code to produce a SRPM package",
example="#! /bin/sh -x",
)

custom_builddeps = String(
builddeps = String(
description="URL to additional yum repos, which can be used during build.",
example="copr://@copr/copr",
)

custom_resultdir = String(
resultdir = String(
description="Directory where SCRIPT generates sources",
example="./_build",
)

custom_chroot = String(
chroot = String(
description="What chroot to run the script in",
example="fedora-latest-x86_64",
)
Expand Down Expand Up @@ -400,3 +407,15 @@
multilib = Boolean

verify = Boolean

priority = Integer

# TODO: specify those only in Repo schema?

baseurl = Url

url = String

version = String

webhook_rebuild = Boolean
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# somewhere - CLI, Frontend and backend shares these data with each other


from abc import ABC
from dataclasses import dataclass, fields, asdict, MISSING
from typing import Any

Expand All @@ -18,7 +17,7 @@


@dataclass
class Schema(ABC):
class Schema:
@classmethod
def schema_from_fields(cls) -> dict[str, Any]:
result_schema = {}
Expand All @@ -41,7 +40,7 @@ def model(self):
return api.model(self.__class__.__name__, self.to_dict())


class InputSchema(ABC, Schema):
class InputSchema(Schema):
@property
def get_required_attrs(self) -> list:
"""
Expand Down Expand Up @@ -100,7 +99,7 @@ def get_required_attrs(self) -> list:

@dataclass
class Repo(Schema):
baseurl: String
baseurl: Url
module_hotfixes: Boolean
priority: Integer
id: String = String(example="copr_base")
Expand Down Expand Up @@ -309,6 +308,7 @@ class ProjectGet(InputSchema):
build_model = _build_model
package_builds_model = _package_builds_model
project_model = Project.get_cls().model()
package_model = Package.get_cls().model()


# INPUT MODELS
Expand Down

0 comments on commit 08d46a7

Please sign in to comment.