Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit 3d0fa27f363e9534b4f6ec4ca1130313858d439c
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Mon Aug 24 15:45:32 2015 +0200
[frontend][api2] Added {Build,Copr}Chroot[List]R resources
---------------------------------------------------------------
frontend/coprs_frontend/coprs/models.py | 17 ++----
frontend/coprs_frontend/coprs/rest_api/__init__.py | 10 +++-
.../coprs/rest_api/resources/build.py | 5 +-
.../coprs/rest_api/resources/build_chroot.py | 53 ++++++++++++++++++++
.../coprs/rest_api/resources/project.py | 5 +-
.../coprs/rest_api/resources/project_chroot.py | 40 +++++++++++++--
frontend/coprs_frontend/coprs/rest_api/schemas.py | 26 +++++++--
7 files changed, 129 insertions(+), 27 deletions(-)
diff --git a/frontend/coprs_frontend/coprs/models.py
b/frontend/coprs_frontend/coprs/models.py
index cae3155..d23434b 100644
--- a/frontend/coprs_frontend/coprs/models.py
+++ b/frontend/coprs_frontend/coprs/models.py
@@ -171,17 +171,8 @@ class Copr(db.Model, helpers.Serializer):
}
@property
- def yum_repos(self):
- return {}
- # todo: add config option to set backen results base url
- # release_tmpl =
"{chroot.os_release}-{chroot.os_version}-{chroot.arch}"
- # result = {}
- # for chroot in repo.active_chroots:
- # release = release_tmpl.format(chroot=chroot)
- # url = fix_protocol_for_backend(urlparse.urljoin(
- # app.config["BACKEND_RESULTS_BASE_URL"], release +
'/'))
- # result[release] = url
- # return result
+ def owner_name(self):
+ return self.owner.name
@property
def repos_list(self):
@@ -622,6 +613,10 @@ class CoprChroot(db.Model, helpers.Serializer):
comps_name = db.Column(db.String(127), nullable=True)
@property
+ def buildroot_pkgs_list(self):
+ return self.buildroot_pkgs.split()
+
+ @property
def comps(self):
if self.comps_zlib:
return zlib.decompress(self.comps_zlib).decode("utf-8")
diff --git a/frontend/coprs_frontend/coprs/rest_api/__init__.py
b/frontend/coprs_frontend/coprs/rest_api/__init__.py
index cfe3930..7c05d40 100644
--- a/frontend/coprs_frontend/coprs/rest_api/__init__.py
+++ b/frontend/coprs_frontend/coprs/rest_api/__init__.py
@@ -4,9 +4,10 @@ from flask_restful import Resource, Api
from coprs.rest_api.exceptions import ApiError
from coprs.rest_api.resources.build import BuildListR, BuildR
+from coprs.rest_api.resources.build_chroot import BuildChrootListR, BuildChrootR
from coprs.rest_api.resources.mock_chroot import MockChrootListR, MockChrootR
from coprs.rest_api.resources.project import ProjectListR, ProjectR
-
+from coprs.rest_api.resources.project_chroot import ProjectChrootListR, ProjectChrootR
URL_PREFIX = "/api_2"
@@ -52,6 +53,13 @@ api.add_resource(MockChrootR, "/mock_chroots/<name>")
api.add_resource(BuildListR, "/builds")
api.add_resource(BuildR, "/builds/<int:build_id>")
+api.add_resource(ProjectChrootListR,
"/projects/<int:project_id>/chroots")
+api.add_resource(ProjectChrootR,
"/projects/<int:project_id>/chroots/<name>")
+
+api.add_resource(BuildChrootListR, "/builds/<int:build_id>/chroots")
+api.add_resource(BuildChrootR,
"/builds/<int:build_id>/chroots/<name>")
+
+
# app.register_blueprint(rest_api_bp, url_prefix=URL_PREFIX)
diff --git a/frontend/coprs_frontend/coprs/rest_api/resources/build.py
b/frontend/coprs_frontend/coprs/rest_api/resources/build.py
index 982a790..01f274e 100644
--- a/frontend/coprs_frontend/coprs/rest_api/resources/build.py
+++ b/frontend/coprs_frontend/coprs/rest_api/resources/build.py
@@ -81,8 +81,9 @@ class BuildR(Resource):
return {
"build": BuildSchema().dump(build)[0],
"_links": {
- "self": url_for(".buildr", build_id=build_id),
- "project": url_for(".projectr",
project_id=build.copr_id),
+ "self": {"href": url_for(".buildr",
build_id=build_id)},
+ "project": {"href": url_for(".projectr",
project_id=build.copr_id)},
+ "chroots": {"href":
url_for(".buildchrootlistr", build_id=build_id)}
}
}
diff --git a/frontend/coprs_frontend/coprs/rest_api/resources/build_chroot.py
b/frontend/coprs_frontend/coprs/rest_api/resources/build_chroot.py
index 3117685..9baf263 100644
--- a/frontend/coprs_frontend/coprs/rest_api/resources/build_chroot.py
+++ b/frontend/coprs_frontend/coprs/rest_api/resources/build_chroot.py
@@ -1,2 +1,55 @@
# coding: utf-8
+import json
+import flask
+from flask import url_for
+from flask_restful import Resource, reqparse
+
+from marshmallow import Schema, fields, pprint
+from coprs.logic.builds_logic import BuildsLogic
+from coprs.rest_api.schemas import MockChrootSchema, CoprChrootSchema, BuildChrootSchema
+
+from coprs.views.misc import api_login_required
+from coprs.logic.coprs_logic import MockChrootsLogic, CoprChrootsLogic, CoprsLogic
+
+from ..util import get_one_safe, json_loads_safe, mm_deserialize, mm_serialize_one
+
+
+class BuildChrootListR(Resource):
+ def get(self, build_id):
+ build = get_one_safe(BuildsLogic.get(build_id),
+ "Not found build with id: {}".format(build_id))
+
+ return {
+ "chroots": [
+ {
+ "chroot": mm_serialize_one(BuildChrootSchema, chroot),
+ "_links": {
+ "project": {"href":
url_for(".projectr", project_id=build.copr_id)},
+ "self": {"href":
url_for(".buildchrootr",
+ build_id=build.id,
+ name=chroot.name)},
+ }
+ } for chroot in build.build_chroots
+ ],
+ "_links": {
+ "self": {"href":
url_for(".buildchrootlistr", build_id=build_id)}
+ }
+ }
+
+
+class BuildChrootR(Resource):
+ pass
+ # def get(self, project_id, name):
+ # copr = get_one_safe(CoprsLogic.get_by_id(int(project_id)))
+ # chroot = CoprChrootsLogic.get_by_name_safe(copr, name)
+ #
+ # return {
+ # "chroot": mm_serialize_one(CoprChrootSchema, chroot),
+ # "_links": {
+ # "project": {"href": url_for(".projectr",
project_id=copr.id)},
+ # "self": {"href":
url_for(".projectchrootr",
+ # project_id=project_id,
+ # name=chroot.name)},
+ # }
+ # }
diff --git a/frontend/coprs_frontend/coprs/rest_api/resources/project.py
b/frontend/coprs_frontend/coprs/rest_api/resources/project.py
index 61f1665..720f01f 100644
--- a/frontend/coprs_frontend/coprs/rest_api/resources/project.py
+++ b/frontend/coprs_frontend/coprs/rest_api/resources/project.py
@@ -162,9 +162,8 @@ class ProjectR(Resource):
"copr": ProjectSchema().dump(copr)[0],
"_links": {
"self": {"href": url_for(".projectr",
project_id=copr.id)},
- #"chroots": bp_url_for(ChrootListR.endpoint,
- # )
- "builds": {"href": url_for(".buildlistr",
project_id=copr.id)}
+ "builds": {"href": url_for(".buildlistr",
project_id=copr.id)},
+ "chroots": {"href":
url_for(".projectchrootlistr", project_id=copr.id)}
},
# "allowed_methods": [
# render_allowed_method("GET", "Get single copr",
require_auth=False),
diff --git a/frontend/coprs_frontend/coprs/rest_api/resources/project_chroot.py
b/frontend/coprs_frontend/coprs/rest_api/resources/project_chroot.py
index 12c6aef..1041c49 100644
--- a/frontend/coprs_frontend/coprs/rest_api/resources/project_chroot.py
+++ b/frontend/coprs_frontend/coprs/rest_api/resources/project_chroot.py
@@ -6,17 +6,49 @@ from flask import url_for
from flask_restful import Resource, reqparse
from marshmallow import Schema, fields, pprint
-from coprs.rest_api.schemas import MockChrootSchema
+from coprs.rest_api.schemas import MockChrootSchema, CoprChrootSchema
from coprs.views.misc import api_login_required
from coprs.logic.coprs_logic import MockChrootsLogic, CoprChrootsLogic, CoprsLogic
-from ..util import get_one_safe, json_loads_safe, mm_deserialize
+from ..util import get_one_safe, json_loads_safe, mm_deserialize, mm_serialize_one
class ProjectChrootListR(Resource):
- pass
+
+ def get(self, project_id):
+ copr = get_one_safe(CoprsLogic.get_by_id(int(project_id)))
+
+ return {
+ "chroots": [
+ {
+ "chroot": mm_serialize_one(CoprChrootSchema, chroot),
+ "_links": {
+ "project": {"href":
url_for(".projectr", project_id=copr.id)},
+ "self": {"href":
url_for(".projectchrootr",
+ project_id=project_id,
+ name=chroot.name)},
+ }
+ } for chroot in copr.copr_chroots
+ ],
+ "_links": {
+ "self": {"href":
url_for(".projectchrootlistr", project_id=project_id)}
+ }
+ }
class ProjectChrootR(Resource):
- pass
+
+ def get(self, project_id, name):
+ copr = get_one_safe(CoprsLogic.get_by_id(int(project_id)))
+ chroot = CoprChrootsLogic.get_by_name_safe(copr, name)
+
+ return {
+ "chroot": mm_serialize_one(CoprChrootSchema, chroot),
+ "_links": {
+ "project": {"href": url_for(".projectr",
project_id=copr.id)},
+ "self": {"href":
url_for(".projectchrootr",
+ project_id=project_id,
+ name=chroot.name)},
+ }
+ }
diff --git a/frontend/coprs_frontend/coprs/rest_api/schemas.py
b/frontend/coprs_frontend/coprs/rest_api/schemas.py
index 631b489..4cd0912 100644
--- a/frontend/coprs_frontend/coprs/rest_api/schemas.py
+++ b/frontend/coprs_frontend/coprs/rest_api/schemas.py
@@ -17,18 +17,22 @@ class MockChrootSchema(Schema):
class ProjectSchema(Schema):
name = fields.Str(required=True)
+
+ owner = fields.Str(attribute="owner_name", dump_only=True)
description = fields.Str()
instructions = fields.Str()
+ homepage = fields.Str()
+ contact = fields.Str()
auto_createrepo = fields.Bool()
build_enable_net = fields.Bool()
last_modified = fields.DateTime()
- additional_repos = fields.List(fields.Str, dump_only=True,
attribute="repos_list")
- # yum_repos = fields.List()
+ additional_repos = fields.List(fields.Str(), dump_only=True,
attribute="repos_list")
# used only for creation
- chroots_to_enable = fields.List(fields.Str, load_only=True)
+ chroots_to_enable = fields.List(fields.Str(), load_only=True)
+ additional_repos_input = fields.Str(name="additional_repos",
load_only=True)
_keys_to_make_object = [
"description",
@@ -51,12 +55,22 @@ class ProjectSchema(Schema):
return kwargs
+class CoprChrootSchema(Schema):
+
+ buildroot_pkgs = fields.List(fields.Str(),
attribute="buildroot_pkgs_list")
+ name = fields.Str(dump_only=True)
+
+ comps = fields.Str(dump_only=True)
+ comps_name = fields.Str()
+ comps_len = fields.Int(dump_only=True)
+
+
class BuildChrootSchema(Schema):
# used only for presentation
state = fields.Str()
- started_on = fields.Int()
- ended_on = fields.Int()
- git_hash = fields.Str()
+ started_on = fields.Int(dump_only=True)
+ ended_on = fields.Int(dump_only=True)
+ git_hash = fields.Str(dump_only=True)
class BuildSchema(Schema):