Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit 3142df8755475e5069cafb8d4bfb3ac8f0cb31af
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Fri Nov 27 12:17:32 2015 +0100
[python] added method to create new projects through ClientV2
---------------------------------------------------------------
python/copr/client_v2/client.py | 1 -
python/copr/client_v2/entities.py | 9 ++++++-
python/copr/client_v2/handlers.py | 26 +++++++++++++++++++-
python/copr/client_v2/net_client.py | 6 ++++
python/copr/client_v2/schemas.py | 6 ++++
python/docs/client_v2/resource_info/build_task.rst | 2 +-
6 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/python/copr/client_v2/client.py b/python/copr/client_v2/client.py
index 696f98e..fb1123e 100644
--- a/python/copr/client_v2/client.py
+++ b/python/copr/client_v2/client.py
@@ -176,7 +176,6 @@ class CoprClient(UnicodeMixin, HandlersProvider):
client.post_init()
return client
-
@classmethod
def create_from_file_config(cls, filepath=None, ignore_error=False):
"""
diff --git a/python/copr/client_v2/entities.py b/python/copr/client_v2/entities.py
index a4e54ea..9750338 100644
--- a/python/copr/client_v2/entities.py
+++ b/python/copr/client_v2/entities.py
@@ -1,7 +1,8 @@
# coding: utf-8
from ..util import UnicodeMixin
-from .schemas import ProjectSchema, EmptySchema, ProjectChrootSchema, BuildSchema,
BuildTaskSchema, MockChrootSchema
+from .schemas import ProjectSchema, EmptySchema, ProjectChrootSchema, BuildSchema,
BuildTaskSchema, MockChrootSchema, \
+ ProjectCreateSchema
class Link(UnicodeMixin):
@@ -48,6 +49,12 @@ class ProjectEntity(Entity):
return "<Project #{}: {}/{}>".format(self.id, self.owner,
self.name)
+class ProjectCreateEntity(Entity):
+ _schema = ProjectCreateSchema(strict=True)
+
+ def __unicode__(self):
+ return "<New project {}/{}>".format(self.owner, self.name)
+
class ProjectChrootEntity(Entity):
_schema = ProjectChrootSchema(strict=True)
diff --git a/python/copr/client_v2/handlers.py b/python/copr/client_v2/handlers.py
index b9afddb..f8f1062 100644
--- a/python/copr/client_v2/handlers.py
+++ b/python/copr/client_v2/handlers.py
@@ -4,7 +4,8 @@ import json
import os
from copr.client_v2.net_client import RequestError, MultiPartTuple
-from .entities import ProjectChrootEntity
+from copr.client_v2.schemas import ProjectCreateSchema
+from .entities import ProjectChrootEntity, ProjectEntity, ProjectCreateEntity
from .resources import Project, OperationResult, ProjectList, ProjectChroot,
ProjectChrootList, Build, BuildList, \
MockChroot, MockChrootList, BuildTask, BuildTaskList
@@ -317,6 +318,29 @@ class ProjectHandle(AbstractHandle):
options=query_params
)
+ def create(
+ self, name, owner, chroots, description=None, instructions=None,
+ homepage=None, contact=None, disable_createrepo=None, build_enable_net=None,
+ repos=None,
+ ):
+
+ new_entity = ProjectCreateEntity(
+ owner=owner,
+ name=name,
+ chroots=chroots,
+ description=description,
+ instructions=instructions,
+ homepage=homepage,
+ contact=contact,
+ disable_createrepo=disable_createrepo,
+ build_enable_net=build_enable_net,
+ repos=repos
+ )
+
+ url = self.get_base_url()
+ response = self.nc.request(url, method="post",
data=new_entity.to_json(), do_auth=True)
+ return OperationResult(self, response)
+
def update(self, project_entity):
""" Updates project.
diff --git a/python/copr/client_v2/net_client.py b/python/copr/client_v2/net_client.py
index 4e68100..f44073d 100644
--- a/python/copr/client_v2/net_client.py
+++ b/python/copr/client_v2/net_client.py
@@ -122,6 +122,12 @@ class NetClient(object):
def request(self, url, method=None, query_params=None, data=None, do_auth=False,
headers=None):
"""
+ :param str method: what HTTP method to use, default is GET, allowed methods: GET,
POST, PUT, DELETE
+ :param dict query_params: HTTP query parameters
+ :param str data: serialized data, when present set default content type to
application/json
+ :param dict headers: dict with headers, takes priority over implicit ones
+ :param bool do_auth: sends auth headers when enabled
+
:raises: RequestError
"""
diff --git a/python/copr/client_v2/schemas.py b/python/copr/client_v2/schemas.py
index 3204cf2..a05f8ab 100644
--- a/python/copr/client_v2/schemas.py
+++ b/python/copr/client_v2/schemas.py
@@ -35,6 +35,12 @@ class ProjectSchema(Schema):
repos = fields.List(fields.Str())
+class ProjectCreateSchema(ProjectSchema):
+
+ id = fields.Int(allow_none=True)
+ chroots = fields.List(fields.Str())
+
+
class ProjectChrootSchema(Schema):
name = fields.Str()
diff --git a/python/docs/client_v2/resource_info/build_task.rst
b/python/docs/client_v2/resource_info/build_task.rst
index 3c2f13f..8058309 100644
--- a/python/docs/client_v2/resource_info/build_task.rst
+++ b/python/docs/client_v2/resource_info/build_task.rst
@@ -7,7 +7,7 @@ Build task represents information about individual build tasks. One task
is resp
Access to the build tasks is done through
:py:meth:`~copr.client_v2.client.CoprClient.build_tasks`.
property of initialized :py:class:`~copr.client_v2.client.CoprClient`. That property is
an instance of
-:py:class:`~copr.client_v2.handlers.BuildTasksHandle`.
+:py:class:`~copr.client_v2.handlers.BuildTaskHandle`.
It may be more convenient to access build tasks in context of a build