[copr] master: we need six >= 1.9.0 (7852b59)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 7852b596f29cc0f527806a1d226221d417d5c634
Author: Miroslav Such�� <msuchy(a)redhat.com>
Date: Mon Nov 23 14:38:51 2015 +0100
we need six >= 1.9.0
>---------------------------------------------------------------
python/python-copr.spec | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/python/python-copr.spec b/python/python-copr.spec
index dbaa0c7..6d84ddd 100644
--- a/python/python-copr.spec
+++ b/python/python-copr.spec
@@ -30,7 +30,7 @@ BuildRequires: python-setuptools
BuildRequires: python-requests
BuildRequires: python-requests-toolbelt
BuildRequires: python-marshmallow
-BuildRequires: python-six
+BuildRequires: python-six >= 1.9.0
BuildRequires: python-mock
BuildRequires: pytest
BuildRequires: python2-devel
@@ -39,7 +39,7 @@ BuildRequires: python-sphinx
BuildRequires: python-docutils
Requires: python-setuptools
-Requires: python-six
+Requires: python-six >= 1.9.0
Requires: python-requests
Requires: python-requests-toolbelt
Requires: python-marshmallow
8 years, 5 months
[copr] master: add function only for Pg (7b3bfb4)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 7b3bfb44bdea939089948975927bc456cf272620
Author: Miroslav Such�� <msuchy(a)redhat.com>
Date: Fri Nov 20 14:06:31 2015 +0100
add function only for Pg
>---------------------------------------------------------------
.../19ca0c14096e_status_to_order_function.py | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/frontend/coprs_frontend/alembic/versions/19ca0c14096e_status_to_order_function.py b/frontend/coprs_frontend/alembic/versions/19ca0c14096e_status_to_order_function.py
index 6db6ad5..97f0be0 100644
--- a/frontend/coprs_frontend/alembic/versions/19ca0c14096e_status_to_order_function.py
+++ b/frontend/coprs_frontend/alembic/versions/19ca0c14096e_status_to_order_function.py
@@ -42,11 +42,13 @@ RETURNS integer AS $$ BEGIN
END; END;
$$ LANGUAGE plpgsql;
"""
- op.execute(sa.text(query_functions))
+ if op.get_bind().dialect.name == "postgresql":
+ op.execute(sa.text(query_functions))
def downgrade():
query = """DROP FUNCTION status_to_order (x integer);
DROP FUNCTION order_to_status (x integer);
"""
- op.execute(sa.text(query))
+ if op.get_bind().dialect.name == "postgresql":
+ op.execute(sa.text(query))
8 years, 5 months
[copr] master: [frontend] fix bug in the psql stored procedure (status order) (2ce77b8)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 2ce77b8c920db9699712aa3634027f975cc9c2e2
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Fri Nov 20 12:18:34 2015 +0100
[frontend] fix bug in the psql stored procedure (status order)
>---------------------------------------------------------------
...94e2b5_fix_stored_procudure_status_order_bug.py | 78 ++++++++++++++++++++
1 files changed, 78 insertions(+), 0 deletions(-)
diff --git a/frontend/coprs_frontend/alembic/versions/4b57794e2b5_fix_stored_procudure_status_order_bug.py b/frontend/coprs_frontend/alembic/versions/4b57794e2b5_fix_stored_procudure_status_order_bug.py
new file mode 100644
index 0000000..8c145d6
--- /dev/null
+++ b/frontend/coprs_frontend/alembic/versions/4b57794e2b5_fix_stored_procudure_status_order_bug.py
@@ -0,0 +1,78 @@
+"""fix stored procudure (status order) bug
+
+Revision ID: 4b57794e2b5
+Revises: 19ca0c14096e
+Create Date: 2015-11-20 11:57:25.079854
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '4b57794e2b5'
+down_revision = '19ca0c14096e'
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+ query_functions = """
+CREATE OR REPLACE FUNCTION status_to_order (x integer)
+RETURNS integer AS $$ BEGIN
+ RETURN CASE WHEN x = 0 THEN 0
+ WHEN x = 3 THEN 1
+ WHEN x = 6 THEN 2
+ WHEN x = 7 THEN 3
+ WHEN x = 4 THEN 4
+ WHEN x = 1 THEN 5
+ WHEN x = 5 THEN 6
+ WHEN x = 2 THEN 7
+ ELSE x
+ END; END;
+ $$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION order_to_status (x integer)
+RETURNS integer AS $$ BEGIN
+ RETURN CASE WHEN x = 0 THEN 0
+ WHEN x = 1 THEN 3
+ WHEN x = 2 THEN 6
+ WHEN x = 3 THEN 7
+ WHEN x = 4 THEN 4
+ WHEN x = 5 THEN 1
+ WHEN x = 6 THEN 5
+ WHEN x = 7 THEN 2
+ ELSE x
+ END; END;
+ $$ LANGUAGE plpgsql;
+"""
+ op.execute(sa.text(query_functions))
+
+
+def downgrade():
+ query_functions = """
+CREATE OR REPLACE FUNCTION status_to_order (x integer)
+RETURNS integer AS $$ BEGIN
+ RETURN CASE WHEN x = 0 THEN 0
+ WHEN x = 3 THEN 1
+ WHEN x = 6 THEN 2
+ WHEN x = 7 THEN 3
+ WHEN x = 4 THEN 4
+ WHEN x = 1 THEN 5
+ WHEN x = 5 THEN 6
+ ELSE 1000
+ END; END;
+ $$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION order_to_status (x integer)
+RETURNS integer AS $$ BEGIN
+ RETURN CASE WHEN x = 0 THEN 0
+ WHEN x = 1 THEN 3
+ WHEN x = 2 THEN 6
+ WHEN x = 3 THEN 7
+ WHEN x = 4 THEN 4
+ WHEN x = 5 THEN 1
+ WHEN x = 6 THEN 5
+ ELSE 1000
+ END; END;
+ $$ LANGUAGE plpgsql;
+"""
+ op.execute(sa.text(query_functions))
8 years, 5 months
[copr] master: [python] added support for BuildTask and update docs (2b35ce8)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 2b35ce82aba874f441d0ff8b5b647bd0ddca61c8
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Thu Nov 19 17:46:26 2015 +0100
[python] added support for BuildTask and update docs
>---------------------------------------------------------------
python/copr/client_v2/client.py | 30 ++-
python/copr/client_v2/common.py | 24 ++
python/copr/client_v2/entities.py | 30 +--
python/copr/client_v2/handlers.py | 71 ++++++-
python/copr/client_v2/resources.py | 236 +++++++++++++++-----
python/copr/client_v2/schemas.py | 16 +-
python/docs/client_v2/general.rst | 5 +-
python/docs/client_v2/handlers.rst | 4 +-
python/docs/client_v2/resource_info/build.rst | 3 +
python/docs/client_v2/resource_info/build_task.rst | 89 ++++++++-
python/docs/client_v2/resource_info/project.rst | 2 +
.../client_v2/resource_info/project_chroot.rst | 3 +
python/docs/client_v2/resources.rst | 10 +
python/docs/conf.py | 6 +-
14 files changed, 423 insertions(+), 106 deletions(-)
diff --git a/python/copr/client_v2/client.py b/python/copr/client_v2/client.py
index db92133..696f98e 100644
--- a/python/copr/client_v2/client.py
+++ b/python/copr/client_v2/client.py
@@ -15,10 +15,8 @@ import six
from six import with_metaclass
from six.moves import configparser
-# from requests_toolbelt.multipart.encoder import MultipartEncoder
-
from .resources import Root
-from .handlers import ProjectHandle, ProjectChrootHandle, BuildHandle, MockChrootHandle
+from .handlers import ProjectHandle, ProjectChrootHandle, BuildHandle, MockChrootHandle, BuildTaskHandle
from .net_client import NetClient
if sys.version_info < (2, 7):
@@ -58,9 +56,12 @@ class HandlersProvider(object, with_metaclass(ABCMeta)):
"""
pass
- # @abstractproperty
- # def build_tasks(self):
- # pass
+ @abstractproperty
+ def build_tasks(self):
+ """
+ :rtype: BuildTaskHandle
+ """
+ pass
@abstractproperty
def mock_chroots(self):
@@ -94,13 +95,12 @@ class CoprClient(UnicodeMixin, HandlersProvider):
self.no_config = no_config
self._post_init_done = False
- self._main_resources = None
-
self.root = None
self._projects = None
self._project_chroots = None
self._builds = None
+ self._build_tasks = None
self._mock_chroots = None
def _check_client_init(self):
@@ -133,6 +133,14 @@ class CoprClient(UnicodeMixin, HandlersProvider):
return self._builds
@property
+ def build_tasks(self):
+ """
+ :rtype: :py:class:`~copr.client_v2.handlers.BuildTaskHandle`
+ """
+ self._check_client_init()
+ return self._build_tasks
+
+ @property
def mock_chroots(self):
"""
:rtype: :py:class:`~copr.client_v2.handlers.MockChrootHandle`
@@ -236,7 +244,11 @@ class CoprClient(UnicodeMixin, HandlersProvider):
self._builds = BuildHandle(
weakref.proxy(self), self.nc, root_url=self.root_url,
builds_href=self.root.get_href_by_name(u"builds"),)
- # self._build_chroots = BuildTaskHandle()
+
+ self._build_tasks = BuildTaskHandle(
+ weakref.proxy(self), self.nc, root_url=self.root_url,
+ build_tasks_href=self.root.get_href_by_name("build_tasks")
+ )
self._mock_chroots = MockChrootHandle(
weakref.proxy(self), self.nc, root_url=self.root_url,
diff --git a/python/copr/client_v2/common.py b/python/copr/client_v2/common.py
index 615ca6a..2ccd3ec 100644
--- a/python/copr/client_v2/common.py
+++ b/python/copr/client_v2/common.py
@@ -20,3 +20,27 @@ class BuiltPackage(UnicodeMixin):
def __unicode__(self):
return u"{} {}".format(self.name, self.version)
+
+
+class BuildStateValues(object):
+ FAILED = "failed"
+ SUCCEEDED = "succeeded"
+ CANCELED = "canceled"
+ RUNNING = "running"
+ PENDING = "pending"
+ SKIPPED = "skipped"
+ STARTING = "starting"
+ IMPORTING = "importing"
+ UNKNOWN = "unknown"
+
+ALLOWED_BUILD_STATES = {
+ BuildStateValues.FAILED,
+ BuildStateValues.SUCCEEDED,
+ BuildStateValues.CANCELED,
+ BuildStateValues.RUNNING,
+ BuildStateValues.PENDING,
+ BuildStateValues.SKIPPED,
+ BuildStateValues.STARTING,
+ BuildStateValues.IMPORTING,
+ BuildStateValues.UNKNOWN,
+}
diff --git a/python/copr/client_v2/entities.py b/python/copr/client_v2/entities.py
index e62c91e..a4e54ea 100644
--- a/python/copr/client_v2/entities.py
+++ b/python/copr/client_v2/entities.py
@@ -14,24 +14,6 @@ class Link(UnicodeMixin):
@classmethod
def from_dict(cls, data_dict):
- """
- {
- "self": {
- "href": "/api_2/projects/2482?show_builds=True&show_chroots=True"
- },
- "chroots": {
- "href": "/api_2/projects/2482/chroots"
- },
- "builds": {
- "href": "/api_2/builds?project_id=2482"
- }
- }
-
- return
- {
- <role> -> Link()
- }
- """
return {
role_name:
cls(role_name, definition["href"])
@@ -82,14 +64,16 @@ class BuildEntity(Entity):
return "<Build #{} state: {}>".format(self.id, self.state)
def is_finished(self):
- if self.state in [
+ """
+ Check is the build was finished
+
+ :rtype: bool
+ """
+ return self.state in [
"failed",
"skipped",
"succeeded"
- ]:
- return True
- else:
- return False
+ ]
class BuildTaskEntity(Entity):
diff --git a/python/copr/client_v2/handlers.py b/python/copr/client_v2/handlers.py
index 146772b..b9afddb 100644
--- a/python/copr/client_v2/handlers.py
+++ b/python/copr/client_v2/handlers.py
@@ -6,7 +6,7 @@ import os
from copr.client_v2.net_client import RequestError, MultiPartTuple
from .entities import ProjectChrootEntity
from .resources import Project, OperationResult, ProjectList, ProjectChroot, ProjectChrootList, Build, BuildList, \
- MockChroot, MockChrootList
+ MockChroot, MockChrootList, BuildTask, BuildTaskList
class AbstractHandle(object):
@@ -200,6 +200,69 @@ class BuildHandle(AbstractHandle):
)
return parts, response
+ def get_build_tasks_handle(self):
+ """
+ :rtype: BuildTasksHandle
+ """
+ return self.client.build_tasks
+
+class BuildTaskHandle(AbstractHandle):
+
+ def __init__(self, client, nc, root_url, build_tasks_href):
+ super(BuildTaskHandle, self).__init__(client, nc, root_url)
+ self.build_tasks_href = build_tasks_href
+ self._base_url = "{}{}".format(self.root_url, build_tasks_href)
+
+ def get_base_url(self):
+ return self._base_url
+
+ def get_list(self, owner=None, project_id=None, build_id=None,
+ state=None, offset=None, limit=None):
+
+ """ Retrieves build tasks list according to the given parameters
+
+ :param str owner: build tasks from the project owner by this user
+ :param int project_id: get tasks only from this project,
+ when used query parameter ``owner`` is ignored
+ :param int build_id: get tasks only from this build,
+ when used query parameters ``owner`` and ``project_id`` are ignored
+ :param str state: get build tasks only with this state, allowed values:
+ ``failed``, ``succeeded``, ``canceled``, ``running``,
+ ``pending``, ``starting``, ``importing``
+ :param int limit: limit number of projects
+ :param int offset: number of projects to skip
+
+ :rtype: :py:class:`~.resources.BuildTaskList`
+ """
+ options = {
+ "owner": owner,
+ "project_id": project_id,
+ "build_id": build_id,
+ "state": state,
+ "limit": limit,
+ "offset": offset
+ }
+
+ response = self.nc.request(self.get_base_url(), query_params=options)
+ return BuildTaskList.from_response(self, response, options)
+
+ def get_one(self, build_id, chroot_name):
+ """ Retrieves single build task object
+
+
+ :param int build_id: id of the build
+ :param str chroot_name: name of the build chroot
+ :rtype: :py:class:`~.resources.BuildTask`
+ """
+
+ url = "{}/{}/{}".format(self.get_base_url(), build_id, chroot_name)
+ response = self.nc.request(url)
+ return BuildTask.from_response(
+ handle=self,
+ response=response,
+ data_dict=response.json,
+ )
+
class ProjectHandle(AbstractHandle):
@@ -283,6 +346,12 @@ class ProjectHandle(AbstractHandle):
"""
return self.client.builds
+ def get_build_tasks_handle(self):
+ """
+ :rtype: BuildTasksHandle
+ """
+ return self.client.build_tasks
+
def get_project_chroots_handle(self):
"""
:rtype: ProjectChrootHandle
diff --git a/python/copr/client_v2/resources.py b/python/copr/client_v2/resources.py
index 0134845..b4abcc4 100644
--- a/python/copr/client_v2/resources.py
+++ b/python/copr/client_v2/resources.py
@@ -5,8 +5,8 @@ from six import with_metaclass
from ..util import UnicodeMixin
-from .entities import Link, ProjectEntity, ProjectChrootEntity, BuildEntity, MockChrootEntity
-from .schemas import EmptySchema, BuildSchema, ProjectSchema, ProjectChrootSchema, MockChrootSchema
+from .entities import Link, ProjectEntity, ProjectChrootEntity, BuildEntity, MockChrootEntity, BuildTaskEntity
+from .schemas import EmptySchema, BuildSchema, ProjectSchema, ProjectChrootSchema, MockChrootSchema, BuildTaskSchema
class EntityFieldDescriptor(object):
@@ -29,6 +29,20 @@ class EntityFieldDescriptor(object):
setattr(obj._entity, self.name, val)
+class ReadOnlyFieldDescriptor(object):
+ """
+ Entity read-only Field Descriptor
+ """
+ def __init__(self, name):
+ self.name = name
+
+ def __get__(self, obj, objtype):
+ """
+ :type obj: IndividualResource
+ """
+ return getattr(obj._entity, self.name)
+
+
class EntityFieldsMetaClass(type):
"""
Magic: we take fields info from class._schema and attach EntityFieldDescriptor
@@ -39,6 +53,15 @@ class EntityFieldsMetaClass(type):
if schema:
for f_name, f in schema.fields.items():
class_attrs[f_name] = EntityFieldDescriptor(f_name)
+
+ entity_methods = []
+ for base in bases:
+ entity_methods.extend(getattr(base, "_entity_methods", []))
+ entity_methods.extend(class_attrs.get("_entity_methods", []))
+
+ for m_name in entity_methods:
+ class_attrs[m_name] = ReadOnlyFieldDescriptor(m_name)
+
return type.__new__(mcs, class_name, bases, class_attrs)
@@ -51,6 +74,11 @@ class IndividualResource(with_metaclass(EntityFieldsMetaClass, UnicodeMixin)):
"""
_schema = EmptySchema(strict=True)
+ # todo: this methods only serialize fields which can be modified by the user
+ # think about an apporach to override `load_only=True` fields in
+ # our schemas during the dump function
+ # _entity_methods = ["to_json", "to_dict"]
+
def __init__(self, entity, handle=None, response=None, links=None, embedded=None, options=None):
self._entity = entity
@@ -65,7 +93,6 @@ class IndividualResource(with_metaclass(EntityFieldsMetaClass, UnicodeMixin)):
dir(self.__class__) + list(self.__dict__.keys())
))
if self._entity:
- # res.extend([x for x in dir(self._entity) if not x.startswith("_")])
res.extend(self._schema.fields.keys())
return res
@@ -108,6 +135,7 @@ class Build(IndividualResource):
:type handle: copr.client_v2.handlers.BuildHandle
"""
_schema = BuildSchema(strict=True)
+ _entity_methods = ["is_finished"]
def __init__(self, entity, handle, **kwargs):
super(Build, self).__init__(entity=entity, handle=handle, **kwargs)
@@ -142,6 +170,43 @@ class Build(IndividualResource):
"""
return self._handle.delete(self.id)
+ def get_build_tasks(self, **query_options):
+ """ Get build tasks owned by this build
+
+ :param query_options: see :py:meth:`.handlers.BuildHandle.get_list`
+ :rtype: :py:class:`~.BuildTasksList`
+ """
+ handle = self._handle.get_build_tasks_handle()
+ return handle.get_list(build_id=self.id, **query_options)
+
+
+class BuildTask(IndividualResource):
+ """
+ :type entity: BuildTaskEntity
+ :type handle: copr.client_v2.handlers.BuildTaskHandle
+ """
+ _schema = BuildTaskSchema(strict=True)
+
+ def __init__(self, entity, handle, **kwargs):
+ super(BuildTask, self).__init__(entity=entity, handle=handle, **kwargs)
+ self._entity = entity
+ self._handle = handle
+
+ def get_self(self):
+ """ Retrieves fresh build task object from the service
+
+ :rtype: :py:class:`~.Build`
+ """
+ return self._handle.get_one(self.build_id, self.chroot_name)
+
+
+ @classmethod
+ def from_response(cls, handle, data_dict, response=None, options=None):
+ links = Link.from_dict(data_dict["_links"])
+ entity = BuildTaskEntity.from_dict(data_dict["build_task"])
+ return cls(entity=entity, handle=handle,
+ response=response, links=links, options=options)
+
class Project(IndividualResource):
"""
@@ -188,6 +253,15 @@ class Project(IndividualResource):
handle = self._handle.get_builds_handle()
return handle.get_list(project_id=self.id, **query_options)
+ def get_build_tasks(self, **query_options):
+ """ Get build tasks owned by this project
+
+ :param query_options: see :py:meth:`.handlers.BuildHandle.get_list`
+ :rtype: :py:class:`~.BuildTasksList`
+ """
+ handle = self._handle.get_build_tasks_handle()
+ return handle.get_list(project_id=self.id, **query_options)
+
def get_project_chroot(self, name):
""" Retrieves project chroot object by the given name
@@ -399,6 +473,32 @@ class CollectionResource(Iterable, UnicodeMixin):
raise NotImplementedError
+def _construct_collection(
+ resource_class, handle, response,
+ individuals, options=None, **kwargs):
+
+ """ Helper to avoid code repetition
+
+ :type resource_class: CollectionResource
+ :param handle: AbstractHandle
+ :param response: ResponseWrapper
+ :param options: dict with query options
+ :param individuals: individuals
+
+ :param kwargs: additional parameters for constructor
+
+ :rtype: CollectionResource
+ """
+ return resource_class(
+ handle,
+ response=response,
+ links=Link.from_dict(response.json["_links"]),
+ individuals=individuals,
+ options=options,
+ **kwargs
+ )
+
+
class ProjectList(CollectionResource):
"""
:type handle: copr.client_v2.handlers.ProjectHandle
@@ -423,21 +523,17 @@ class ProjectList(CollectionResource):
@classmethod
def from_response(cls, handle, response, options):
- data_dict = response.json
- result = ProjectList(
- handle,
- response=response,
- links=Link.from_dict(data_dict["_links"]),
- individuals=[
- Project.from_response(
- handle=handle,
- data_dict=dict_part,
- )
- for dict_part in data_dict["projects"]
- ],
- options=options
+ individuals = [
+ Project.from_response(
+ handle=handle,
+ data_dict=dict_part,
+ )
+ for dict_part in response.json["projects"]
+ ]
+ return _construct_collection(
+ cls, handle, response=response,
+ individuals=individuals, options=options
)
- return result
class BuildList(CollectionResource):
@@ -465,21 +561,17 @@ class BuildList(CollectionResource):
@classmethod
def from_response(cls, handle, response, options):
- data_dict = response.json
- result = BuildList(
- handle,
- response=response,
- links=Link.from_dict(data_dict["_links"]),
- individuals=[
- Build.from_response(
- handle=handle,
- data_dict=dict_part,
- )
- for dict_part in data_dict["builds"]
- ],
- options=options
+ individuals = [
+ Build.from_response(
+ handle=handle,
+ data_dict=dict_part,
+ )
+ for dict_part in response.json["builds"]
+ ]
+ return _construct_collection(
+ cls, handle, response=response,
+ individuals=individuals, options=options
)
- return result
class ProjectChrootList(CollectionResource):
@@ -511,20 +603,18 @@ class ProjectChrootList(CollectionResource):
@classmethod
def from_response(cls, handle, response, project):
- data_dict = response.json
- return ProjectChrootList(
- handle,
- project=project,
- response=response,
- links=Link.from_dict(data_dict["_links"]),
- individuals=[
- ProjectChroot.from_response(
- handle=handle,
- data_dict=dict_part,
- project=project
- )
- for dict_part in data_dict["chroots"]
- ]
+ individuals = [
+ ProjectChroot.from_response(
+ handle=handle,
+ data_dict=dict_part,
+ project=project
+ )
+ for dict_part in response.json["chroots"]
+ ]
+
+ return _construct_collection(
+ cls, handle, response=response,
+ individuals=individuals, project=project
)
@@ -548,17 +638,47 @@ class MockChrootList(CollectionResource):
@classmethod
def from_response(cls, handle, response, options):
- data_dict = response.json
- return MockChrootList(
- handle,
- response=response,
- links=Link.from_dict(data_dict["_links"]),
- individuals=[
- MockChroot.from_response(
- handle=handle,
- data_dict=dict_part,
- )
- for dict_part in data_dict["chroots"]
- ],
- options=options
+ individuals = [
+ MockChroot.from_response(
+ handle=handle,
+ data_dict=dict_part,
+ )
+ for dict_part in response.json["chroots"]
+ ]
+ return _construct_collection(
+ cls, handle, response=response,
+ options=options, individuals=individuals
+ )
+
+
+class BuildTaskList(CollectionResource):
+ """
+ List of build tasks
+
+ :type handle: copr.client_v2.handlers.BuildTaskHandle
+ """
+
+ def __init__(self, handle, **kwargs):
+ super(BuildTaskList, self).__init__(**kwargs)
+ self._handle = handle
+
+ @property
+ def build_tasks(self):
+ """
+ :rtype: list of :py:class:`~.resources.BuildTask`
+ """
+ return self._individuals
+
+ @classmethod
+ def from_response(cls, handle, response, options):
+ individuals = [
+ BuildTask.from_response(
+ handle=handle,
+ data_dict=dict_part
+ )
+ for dict_part in response.json["build_tasks"]
+ ]
+ return _construct_collection(
+ cls, handle, response=response,
+ options=options, individuals=individuals
)
diff --git a/python/copr/client_v2/schemas.py b/python/copr/client_v2/schemas.py
index ded42f6..3204cf2 100644
--- a/python/copr/client_v2/schemas.py
+++ b/python/copr/client_v2/schemas.py
@@ -1,12 +1,13 @@
# coding: utf-8
from marshmallow import Schema, fields
+from marshmallow.validate import OneOf
# todo: maybe define schemas for Link sets in each indvidual/collection
# class LinkSchema(Schema):
# href = fields.Str()
#
-from .common import BuiltPackage
+from .common import BuiltPackage, ALLOWED_BUILD_STATES
class EmptySchema(Schema):
@@ -80,14 +81,15 @@ class BuildSchema(Schema):
class BuildTaskSchema(Schema):
- state = fields.Str()
- started_on = fields.Int(load_only=True)
- ended_on = fields.Int(load_only=True)
- git_hash = fields.Str(load_only=True)
+ state = fields.Str(load_only=True, validate=[
+ OneOf(ALLOWED_BUILD_STATES)
+ ])
+ started_on = fields.Int(load_only=True, allow_none=True)
+ ended_on = fields.Int(load_only=True, allow_none=True)
+ git_hash = fields.Str(load_only=True, allow_none=True)
chroot_name = fields.Str(load_only=True)
build_id = fields.Int(load_only=True)
-
- result_dir_url = fields.Str(load_only=True)
+ result_dir_url = fields.Str(load_only=True, allow_none=True)
class MockChrootSchema(Schema):
diff --git a/python/docs/client_v2/general.rst b/python/docs/client_v2/general.rst
index 23d1001..38cda16 100644
--- a/python/docs/client_v2/general.rst
+++ b/python/docs/client_v2/general.rst
@@ -10,7 +10,8 @@ CoprClient
.. autoclass:: copr.client_v2.client.CoprClient
- :members: projects, builds, project_chroots, mock_chroots, create_from_file_config, create_from_params, post_init
- :undoc-members:
+ :members: projects, builds, build_tasks, project_chroots,
+ mock_chroots, create_from_file_config, create_from_params, post_init
+
diff --git a/python/docs/client_v2/handlers.rst b/python/docs/client_v2/handlers.rst
index 5508c67..e49e289 100644
--- a/python/docs/client_v2/handlers.rst
+++ b/python/docs/client_v2/handlers.rst
@@ -20,8 +20,8 @@ Build
Build task
----------
-.. note::
- Not implemented yet
+.. autoclass:: copr.client_v2.handlers.BuildTaskHandle
+ :members:
Mock chroot
diff --git a/python/docs/client_v2/resource_info/build.rst b/python/docs/client_v2/resource_info/build.rst
index 04880ee..03f9a05 100644
--- a/python/docs/client_v2/resource_info/build.rst
+++ b/python/docs/client_v2/resource_info/build.rst
@@ -3,6 +3,9 @@
Build
=====
+Build resource allows to submit new builds and access current build progress.
+In fact, build consists of a few tasks, one per chroot, and detailed information is available through
+:ref:`build-task-info`.
Access to the builds is done through :py:meth:`~copr.client_v2.client.CoprClient.builds`.
property of initialized :py:class:`~copr.client_v2.client.CoprClient`. That property is an instance of
diff --git a/python/docs/client_v2/resource_info/build_task.rst b/python/docs/client_v2/resource_info/build_task.rst
index f17a444..3c2f13f 100644
--- a/python/docs/client_v2/resource_info/build_task.rst
+++ b/python/docs/client_v2/resource_info/build_task.rst
@@ -3,4 +3,91 @@
Build task
==========
-.. note:: Not implement yet
+Build task represents information about individual build tasks. One task is responsible for one chroot.
+
+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`.
+
+
+It may be more convenient to access build tasks in context of a build
+using method :py:meth:`~copr.client_v2.resources.Build.get_build_tasks`
+of access build tasks in context of a project
+using method :py:meth:`~copr.client_v2.resources.Project.get_build_tasks`
+
+Build tasks are represented by
+:py:class:`~copr.client_v2.resources.BuildTask` class.
+
+.. _build-task-attributes:
+
+Build task entity attributes
+----------------------------
+
+.. copied from frontend docs, don't forget to update
+
+================== ==================== ===============
+Field Type Description
+================== ==================== ===============
+chroot_name str chroot name
+build_id int unique build identifier
+state str current build task state
+started_on int(unixtime UTC) time when the build chroot started
+ended_on int(unixtime UTC) time when the build chroot ended
+git_hash str hash of the git commit in dist-git used for the build
+result_dir_url str(URL) location of the build results
+================== ==================== ===============
+
+
+.. note::
+ Build Task doesn't currently support any modifications,
+ so all fields are read-only.
+
+
+.. note::
+ all following examples assume that we use ``cl``
+ as an instance of :py:class:`.client_v2.client.CoprClient`,
+ ``p`` as an instance of :py:class:`~copr.client_v2.resources.Project`,
+ ``b`` as an instance of :py:class:`~copr.client_v2.resources.Build`,
+
+
+Get build tasks list
+--------------------
+
+.. sourcecode:: python
+
+ >>> bt_list_1 = cl.build_tasks.get_list(state=BuildStateValues.FAILED, limit=5)
+ >>> map(str, bt_list_1)
+ ['<Build task #17-fedora-18-x86_64, state: failed>',
+ '<Build task #17-fedora-18-i386, state: failed>',
+ '<Build task #17-fedora-19-x86_64, state: failed>',
+ '<Build task #17-fedora-19-i386, state: failed>',
+ '<Build task #107850-fedora-23-x86_64, state: failed>']
+
+ # using project object
+ >>> bt_list_2 = p.get_build_tasks(limit=5)
+ >>> map(str, bt_list_2)
+ ['<Build task #86705-epel-6-i386, state: succeeded>',
+ '<Build task #86705-epel-6-x86_64, state: failed>',
+ '<Build task #86705-fedora-rawhide-x86_64, state: succeeded>',
+ '<Build task #86705-fedora-rawhide-i386, state: failed>',
+ '<Build task #86705-fedora-20-x86_64, state: succeeded>']
+
+ # using build object
+ >>> bt_list_3 = b.get_build_tasks(limit=5)
+ >>> map(str, bt_list_3)
+ ['<Build task #87165-epel-6-i386, state: failed>',
+ '<Build task #87165-epel-6-x86_64, state: failed>',
+ '<Build task #87165-fedora-rawhide-x86_64, state: succeeded>',
+ '<Build task #87165-fedora-rawhide-i386, state: succeeded>',
+ '<Build task #87165-fedora-20-x86_64, state: succeeded>']
+
+Get single build task
+---------------------
+
+
+.. sourcecode:: python
+
+ >>> bt = cl.build_tasks.get_one(106897, "epel-6-i386")
+ >>> print(bt.state, bt.result_dir_url)
+ (u'succeeded', u'http://copr-be-dev.cloud.fedoraproject.org/results/rineau/libQGLViewer-qt...')
+
diff --git a/python/docs/client_v2/resource_info/project.rst b/python/docs/client_v2/resource_info/project.rst
index 768d4bd..2d29a2c 100644
--- a/python/docs/client_v2/resource_info/project.rst
+++ b/python/docs/client_v2/resource_info/project.rst
@@ -3,6 +3,8 @@
Project
=======
+Project resource represents copr projects and operations with them.
+
Access to the projects is done through :py:meth:`~copr.client_v2.client.CoprClient.projects`.
property of initialized :py:class:`~copr.client_v2.client.CoprClient`. That property is an instance of
:py:class:`~copr.client_v2.handlers.ProjectHandle`. Projects are represented by
diff --git a/python/docs/client_v2/resource_info/project_chroot.rst b/python/docs/client_v2/resource_info/project_chroot.rst
index ae59c75..7936444 100644
--- a/python/docs/client_v2/resource_info/project_chroot.rst
+++ b/python/docs/client_v2/resource_info/project_chroot.rst
@@ -4,6 +4,9 @@
Project chroot
==============
+Projects Chroots allows to enable and disable target chroots and
+modify project settings dedicated for specific chroots.
+
Access to the project chroots is done through :py:meth:`~copr.client_v2.client.CoprClient.project_chroots`.
property of initialized :py:class:`~copr.client_v2.client.CoprClient`. That property is an instance of
:py:class:`~copr.client_v2.handlers.ProjectChrootHandle`.
diff --git a/python/docs/client_v2/resources.rst b/python/docs/client_v2/resources.rst
index 4d00934..e895256 100644
--- a/python/docs/client_v2/resources.rst
+++ b/python/docs/client_v2/resources.rst
@@ -31,6 +31,16 @@ see entity attributes at :ref:`build-attributes`.
.. autoclass:: copr.client_v2.resources.BuildList
:members:
+Build task
+----------
+see entity attributes at :ref:`build-task-attributes`.
+
+.. autoclass:: copr.client_v2.resources.BuildTask
+ :members:
+
+.. autoclass:: copr.client_v2.resources.BuildTaskList
+ :members:
+
Mock chroot
-----------
see entity attributes at :ref:`mock-chroot-attributes`.
diff --git a/python/docs/conf.py b/python/docs/conf.py
index 115f114..069a46d 100644
--- a/python/docs/conf.py
+++ b/python/docs/conf.py
@@ -50,9 +50,9 @@ copyright = u'2014, Valentin Gologuzov'
# built documents.
#
# The short X.Y version.
-version = '1.52'
+version = '1.63'
# The full version, including alpha/beta/rc tags.
-release = '1.52'
+release = '1.63'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@@ -232,7 +232,7 @@ man_pages = [
# dir menu entry, description, category)
texinfo_documents = [
('index', 'python-copr', u'python-copr Documentation',
- u'Valentin Gologuzov', 'python-copr', 'One line description of project.',
+ u'copr-devel(a)lists.fedorahosted.org', 'python-copr', 'Python client for the Copr service',
'Miscellaneous'),
]
8 years, 5 months
[copr] master: [python][WIP] documentation for ClientV2: done with MockChroot (9e27a27)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 9e27a27732d33daf5ad3d794b2fc6bb426b44a5b
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Thu Nov 19 12:52:55 2015 +0100
[python][WIP] documentation for ClientV2: done with MockChroot
>---------------------------------------------------------------
python/copr/client_v2/handlers.py | 25 ++++++++--
python/copr/client_v2/resources.py | 4 +-
python/docs/client_v2/handlers.rst | 1 -
.../docs/client_v2/resource_info/mock_chroot.rst | 51 ++++++++++++++++++++
python/docs/client_v2/resources.rst | 8 ++-
5 files changed, 80 insertions(+), 9 deletions(-)
diff --git a/python/copr/client_v2/handlers.py b/python/copr/client_v2/handlers.py
index 7d15f3b..146772b 100644
--- a/python/copr/client_v2/handlers.py
+++ b/python/copr/client_v2/handlers.py
@@ -77,7 +77,7 @@ class BuildHandle(AbstractHandle):
""" Cancels the given build
:param build_entity: build entity to delete
- :type build_entity: :py:class:`~.copr.client_v2.entities.BuildEntity
+ :type build_entity: :py:class:`~.copr.client_v2.entities.BuildEntity`
:rtype: :py:class:`.OperationResult`
"""
@@ -150,7 +150,7 @@ class BuildHandle(AbstractHandle):
chroots=None, enable_net=True):
"""
Creates new build using srpm upload, please specify
- either `file_path` or (`file_obj`, `file_name).
+ either ``file_path`` or (``file_obj``, ``file_name`` ).
:param int project_id: id of the project where we want to submit new build
@@ -400,11 +400,27 @@ class MockChrootHandle(AbstractHandle):
return self._base_url
def get_one(self, name):
+ """ Retrieves mock chroot object.
+
+ :param str name: chroot name
+
+ :rtype: :py:class:`~copr.client_v2.resources.MockChroot`
+ """
url = "{}/{}".format(self.get_base_url(), name)
response = self.nc.get(url)
- return MockChroot.from_response(self, response, response.json)
+ return MockChroot.from_response(
+ handle=self,
+ response=response,
+ data_dict=response.json,
+ )
def get_list(self, active_only=True):
+ """ Retrieves mock chroot list object.
+
+ :param bool active_only: when True, shows only chroots which can be used for builds
+
+ :rtype: :py:class:`~copr.client_v2.resources.MockChrootList`
+ """
options = dict(active_only=active_only)
response = self.nc.get(
@@ -414,4 +430,5 @@ class MockChrootHandle(AbstractHandle):
return MockChrootList.from_response(
handle=self,
response=response,
- options=options)
+ options=options
+ )
diff --git a/python/copr/client_v2/resources.py b/python/copr/client_v2/resources.py
index fdd0f16..0134845 100644
--- a/python/copr/client_v2/resources.py
+++ b/python/copr/client_v2/resources.py
@@ -541,7 +541,9 @@ class MockChrootList(CollectionResource):
@property
def chroots(self):
-
+ """
+ :rtype: list of :py:class:`~.resources.MockChroot`
+ """
return self._individuals
@classmethod
diff --git a/python/docs/client_v2/handlers.rst b/python/docs/client_v2/handlers.rst
index 0ba9293..5508c67 100644
--- a/python/docs/client_v2/handlers.rst
+++ b/python/docs/client_v2/handlers.rst
@@ -28,7 +28,6 @@ Mock chroot
-----------
.. autoclass:: copr.client_v2.handlers.MockChrootHandle
:members: get_list, get_one
- :undoc-members:
diff --git a/python/docs/client_v2/resource_info/mock_chroot.rst b/python/docs/client_v2/resource_info/mock_chroot.rst
index f7194da..9c9fcdb 100644
--- a/python/docs/client_v2/resource_info/mock_chroot.rst
+++ b/python/docs/client_v2/resource_info/mock_chroot.rst
@@ -3,4 +3,55 @@
Mock chroot
===========
+Mock chroot resources represents available chroots for builds. API provides only read-only access,
+since configuration of the build chroots is done by the service administrator.
+Access to the mock chroots is done through :py:meth:`~copr.client_v2.client.CoprClient.mock_chroots`.
+property of initialized :py:class:`~copr.client_v2.client.CoprClient`. That property is an instance of
+:py:class:`~copr.client_v2.handlers.MockChrootHandle`. Mock chroots are represented by
+:py:class:`~copr.client_v2.resources.MockChroot` class.
+
+.. _mock-chroot-attributes:
+
+Mock chroot entity attributes
+-----------------------------
+
+
+.. copied from frontend docs, don't forget to update
+
+================== ==================== ===============
+Field Type Description
+================== ==================== ===============
+name str chroot name
+os_release str name of distribution system, e.g.: epel, fedora
+os_version str version of distribution system, e.g.: 7, 22
+arch str architecture of distribution, e.g.: i386, x86_64, ppc64le
+is_active bool defines if this chroot is available for builds
+================== ==================== ===============
+
+.. note::
+ all following examples assume that we use ``cl``
+ as an instance of :py:class:`.client_v2.client.CoprClient`
+
+Get mock chroot list
+--------------------
+
+.. sourcecode:: python
+
+ >>> mlist = map(str, cl.mock_chroots.get_list(active_only=True))
+ >>> print("\n".join(map(str, mlist)))
+ <Mock chroot: epel-6-i386 is active: True>
+ <Mock chroot: epel-6-x86_64 is active: True>
+ <Mock chroot: epel-5-i386 is active: True>
+ ...
+
+Get single mock chroot
+----------------------
+
+.. sourcecode:: python
+
+ >>> mc = cl.mock_chroots.get_one("fedora-22-i386")
+ >>> print(mc)
+ <Mock chroot: fedora-22-i386 is active: True>
+ >>> print(mc.name, mc.os_release, mc.os_version, mc.arch)
+ (u'fedora-22-i386', u'fedora', u'22', u'i386')
diff --git a/python/docs/client_v2/resources.rst b/python/docs/client_v2/resources.rst
index 03abc45..4d00934 100644
--- a/python/docs/client_v2/resources.rst
+++ b/python/docs/client_v2/resources.rst
@@ -3,7 +3,7 @@ Resources
Project
-------
-see entity attributes here: :ref:`project-attributes`.
+see entity attributes at :ref:`project-attributes`.
.. autoclass:: copr.client_v2.resources.Project
:members:
@@ -13,7 +13,7 @@ see entity attributes here: :ref:`project-attributes`.
Project chroot
--------------
-see entity attributes here: :ref:`project-chroot-attributes`.
+see entity attributes at :ref:`project-chroot-attributes`.
.. autoclass:: copr.client_v2.resources.ProjectChroot
:members:
@@ -23,7 +23,7 @@ see entity attributes here: :ref:`project-chroot-attributes`.
Build
-----
-see entity attributes here: :ref:`build-attributes`.
+see entity attributes at :ref:`build-attributes`.
.. autoclass:: copr.client_v2.resources.Build
:members:
@@ -33,6 +33,8 @@ see entity attributes here: :ref:`build-attributes`.
Mock chroot
-----------
+see entity attributes at :ref:`mock-chroot-attributes`.
+
.. autoclass:: copr.client_v2.resources.MockChroot
:members:
8 years, 5 months
[copr] master: minor (999ddc9)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 999ddc9827322879e9dfb134afc46c3298e79011
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Wed Nov 18 17:50:27 2015 +0100
minor
>---------------------------------------------------------------
python/copr/client_v2/handlers.py | 5 +++--
python/docs/client_v2/resources_usage.rst | 1 +
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/python/copr/client_v2/handlers.py b/python/copr/client_v2/handlers.py
index 6f934c7..7d15f3b 100644
--- a/python/copr/client_v2/handlers.py
+++ b/python/copr/client_v2/handlers.py
@@ -237,7 +237,7 @@ class ProjectHandle(AbstractHandle):
# todo: implement: , show_builds=False, show_chroots=False):
""" Retrieves project object.
- :type project_id: int
+ :param int project_id: project identifier
:rtype: :py:class:`~.resources.Project`
"""
query_params = {
@@ -257,7 +257,8 @@ class ProjectHandle(AbstractHandle):
def update(self, project_entity):
""" Updates project.
- :type project_entity: ProjectEntity
+ :param project_entity: project entity to use for update
+ :type project_entity: :py:class:`~.ProjectEntity`
:rtype: OperationResult
"""
url = "{}/{}".format(self.get_base_url(), project_entity.id)
diff --git a/python/docs/client_v2/resources_usage.rst b/python/docs/client_v2/resources_usage.rst
index c48cf03..8039235 100644
--- a/python/docs/client_v2/resources_usage.rst
+++ b/python/docs/client_v2/resources_usage.rst
@@ -50,4 +50,5 @@ Individual resource allows to directly access entity properties and also provide
# change project description (require auth)
>>> p.description = u"Hello world!"
>>> p.update()
+ # instead of cl.projects.update(p._entity)
8 years, 5 months
[copr] master: [python][WIP] documentation for ClientV2: done with Builds (e28cfc5)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit e28cfc5af3a38746a6627bdf7ec0078a52e99f96
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Wed Nov 18 17:38:50 2015 +0100
[python][WIP] documentation for ClientV2: done with Builds
>---------------------------------------------------------------
python/copr/client_v2/handlers.py | 67 +++++++++-----
python/copr/client_v2/resources.py | 23 +++++
python/docs/ClientV2.rst | 1 +
python/docs/client_v2/resource_info/build.rst | 97 +++++++++++++++++++-
python/docs/client_v2/resource_info/build_task.rst | 6 +
python/docs/client_v2/resource_info/project.rst | 1 -
.../client_v2/resource_info/project_chroot.rst | 4 +-
python/docs/client_v2/resources.rst | 4 +
8 files changed, 175 insertions(+), 28 deletions(-)
diff --git a/python/copr/client_v2/handlers.py b/python/copr/client_v2/handlers.py
index b677946..6f934c7 100644
--- a/python/copr/client_v2/handlers.py
+++ b/python/copr/client_v2/handlers.py
@@ -37,8 +37,10 @@ class BuildHandle(AbstractHandle):
return self._base_url
def get_one(self, build_id):
- """
- :type build_id: int
+ """ Retrieves builds object
+
+ :param int build_id: id of the target build
+ :rtype: :py:class:`~.resources.Build`
"""
options = {"build_id": build_id}
@@ -52,12 +54,14 @@ class BuildHandle(AbstractHandle):
)
def get_list(self, project_id=None, owner=None, limit=None, offset=None):
- """
- :param owner:
- :param project_id:
- :param limit:
- :param offset:
- :rtype: BuildList
+ """ Retrieves builds object according to the given parameters
+
+ :param owner: name of the project owner
+ :param project_id: id of the project
+ :param limit: limit number of builds
+ :param offset: number of builds to skip
+
+ :rtype: :py:class:`~.resources.BuildList`
"""
options = {
"project_id": project_id,
@@ -70,8 +74,12 @@ class BuildHandle(AbstractHandle):
return BuildList.from_response(self, response, options)
def cancel(self, build_entity):
- """
- :type build_entity: copr.client_v2.entities.BuildEntity
+ """ Cancels the given build
+
+ :param build_entity: build entity to delete
+ :type build_entity: :py:class:`~.copr.client_v2.entities.BuildEntity
+
+ :rtype: :py:class:`.OperationResult`
"""
build_id = build_entity.id
build_entity.state = "canceled"
@@ -81,6 +89,13 @@ class BuildHandle(AbstractHandle):
return OperationResult(self, response)
def delete(self, build_id):
+ """ Deletes the given build
+
+ :param int build_id: build id to delete
+
+ :rtype: :py:class:`.OperationResult`
+ """
+
url = "{}/{}".format(self.get_base_url(), build_id)
response = self.nc.request(url, method="delete", do_auth=True)
return OperationResult(self, response, expected_status=204)
@@ -106,16 +121,15 @@ class BuildHandle(AbstractHandle):
"""
Creates new build using public url to the srpm file
- :param int project_id:
- :param str srpm_url:
- :param str file_name:
- :param list chroots:
- :param bool enable_net:
+ :param int project_id: id of the project where we want to submit new build
+ :param str srpm_url: url to the source rpm
+ :param list chroots: which chroots should be used during the build
+ :param bool enable_net: allows to disable network access during the build, default: True
+
:return: created build
- :rtype: Build
+ :rtype: :py:class:`~.resources.Build`
"""
-
chroots = map(str, chroots or list())
content = {
"project_id": int(project_id),
@@ -131,20 +145,25 @@ class BuildHandle(AbstractHandle):
return self._process_create_response(data, response)
- def create_from_file(self, project_id, file_path=None, file_obj=None, file_name=None,
+ def create_from_file(self, project_id, file_path=None,
+ file_obj=None, file_name=None,
chroots=None, enable_net=True):
"""
Creates new build using srpm upload, please specify
either `file_path` or (`file_obj`, `file_name).
- :param int project_id:
+ :param int project_id: id of the project where we want to submit new build
+
:param str file_path: path to the srpm file
- :param file like object file_obj:
- :param str file_name:
- :param list chroots:
- :param bool enable_net:
+
+ :param file file_obj: file-like object to read from
+ :param str file_name: name for the uploaded file
+
+ :param list chroots: which chroots should be used during the build
+ :param bool enable_net: allows to disable network access during the build, default: True
+
:return: created build
- :rtype: Build
+ :rtype: :py:class:`~.resources.Build`
"""
chroots = map(str, chroots or list())
diff --git a/python/copr/client_v2/resources.py b/python/copr/client_v2/resources.py
index 58a9cda..fdd0f16 100644
--- a/python/copr/client_v2/resources.py
+++ b/python/copr/client_v2/resources.py
@@ -122,12 +122,24 @@ class Build(IndividualResource):
response=response, links=links, options=options)
def get_self(self):
+ """ Retrieves fresh build object from the service
+
+ :rtype: :py:class:`~.Build`
+ """
return self._handle.get_one(self.id)
def cancel(self):
+ """ Updates the current build
+
+ :rtype: :py:class:`.OperationResult`
+ """
return self._handle.cancel(self._entity)
def delete(self):
+ """ Deletes the current build
+
+ :rtype: :py:class:`.OperationResult`
+ """
return self._handle.delete(self.id)
@@ -436,8 +448,19 @@ class BuildList(CollectionResource):
super(BuildList, self).__init__(**kwargs)
self._handle = handle
+ def next_page(self):
+ """
+ Retrieves next chunk of the Build list for the same query options
+
+ :rtype: :py:class:`.BuildList`
+ """
+ return super(BuildList, self).next_page()
+
@property
def builds(self):
+ """
+ :rtype: :py:class:`.BuildList`
+ """
return self._individuals
@classmethod
diff --git a/python/docs/ClientV2.rst b/python/docs/ClientV2.rst
index 93e80c9..7d9d36f 100644
--- a/python/docs/ClientV2.rst
+++ b/python/docs/ClientV2.rst
@@ -28,6 +28,7 @@ Resources info
client_v2/resource_info/project.rst
client_v2/resource_info/project_chroot.rst
client_v2/resource_info/build.rst
+ client_v2/resource_info/build_task.rst
client_v2/resource_info/mock_chroot.rst
Autodoc
diff --git a/python/docs/client_v2/resource_info/build.rst b/python/docs/client_v2/resource_info/build.rst
index 924dc66..04880ee 100644
--- a/python/docs/client_v2/resource_info/build.rst
+++ b/python/docs/client_v2/resource_info/build.rst
@@ -3,4 +3,99 @@
Build
=====
-pass
+
+Access to the builds is done through :py:meth:`~copr.client_v2.client.CoprClient.builds`.
+property of initialized :py:class:`~copr.client_v2.client.CoprClient`. That property is an instance of
+:py:class:`~copr.client_v2.handlers.BuildHandle`.
+
+It may be more convenient to access builds in context of a project
+using method :py:meth:`~copr.client_v2.resources.Project.get_builds`.
+
+Builds are represented by
+:py:class:`~copr.client_v2.resources.Build` class.
+
+.. _build-attributes:
+
+Build entity attributes
+-----------------------
+
+.. copied from frontend docs, don't forget to update
+
+================== ==================== ===============
+Field Type Description
+================== ==================== ===============
+id int unique build identifier
+state string current state of the build, value is aggregated from build tasks
+submitted_on int(unixtime UTC) time of the build submission
+started_on int(unixtime UTC) time when the first build task started, otherwise ``null``
+ended_on int(unixtime UTC) time when the last build task ended, otherwise ``null``
+source_type string method used for build creation
+source_metadata json object build source information
+package_version string version of the source package
+package_name string name of the source package
+enable_net bool defines if network is available during the build
+repos list of string list of additional repositories enabled during the build
+built_packages list of hash maps list of the built packages, each hash map has two keys: ``name`` and ``version``
+submitter string name of the user who submitted the build
+================== ==================== ===============
+
+.. note::
+ Only the ``state`` field is editable by the PUT method.
+ All other fields are read-only.
+
+Get builds list
+---------------
+
+.. sourcecode:: python
+
+ >>> blist_1 = cl.builds.get_list(limit=2)
+ >>> print(map(str, blist_1))
+ ['<Build #138426 state: succeeded>', '<Build #138425 state: succeeded>']
+ # using the project object
+ >>> blist_2 = p.get_builds(limit=2)
+ >>> print(map(str, blist_2))
+ ['<Build #138423 state: failed>', '<Build #138421 state: failed>']
+
+
+Get one build
+-------------
+
+.. sourcecode:: python
+
+ >>> b = cl.builds.get_one(138421)
+ >>> print(b)
+ <Build #138421 state: failed>
+
+
+Create new build
+----------------
+
+.. sourcecode:: python
+
+ # using the url to sprm
+ >>> b1 = cl.builds.create_from_url(project_id=3806, srpm_url="http://example.com/my.src.rpm")
+ # or using project object
+ >>> b2 = p.create_build_from_url("http://example.com/my.src.rpm")
+ >>> print(map(str, [b1, b2]))
+ ['<Build #138431 state: importing>', '<Build #138430 state: importing>']
+
+ # and using the file upload
+ >>> b3 = cl.builds.create_from_file(project_id=3806, file_path="/tmp/hello-2.8-1.fc20.src.rpm")
+ >>> b4 = p.create_build_from_file("/tmp/hello-2.8-1.fc20.src.rpm")
+
+
+
+Cancel build
+------------
+
+.. sourcecode:: python
+
+ >>> b1.cancel()
+
+Delete build
+------------
+
+
+.. sourcecode:: python
+
+ >>> b1.delete()
diff --git a/python/docs/client_v2/resource_info/build_task.rst b/python/docs/client_v2/resource_info/build_task.rst
new file mode 100644
index 0000000..f17a444
--- /dev/null
+++ b/python/docs/client_v2/resource_info/build_task.rst
@@ -0,0 +1,6 @@
+.. _build-task-info:
+
+Build task
+==========
+
+.. note:: Not implement yet
diff --git a/python/docs/client_v2/resource_info/project.rst b/python/docs/client_v2/resource_info/project.rst
index 76a9b14..768d4bd 100644
--- a/python/docs/client_v2/resource_info/project.rst
+++ b/python/docs/client_v2/resource_info/project.rst
@@ -1,4 +1,3 @@
-
.. _project-info:
Project
diff --git a/python/docs/client_v2/resource_info/project_chroot.rst b/python/docs/client_v2/resource_info/project_chroot.rst
index 033919d..ae59c75 100644
--- a/python/docs/client_v2/resource_info/project_chroot.rst
+++ b/python/docs/client_v2/resource_info/project_chroot.rst
@@ -18,8 +18,8 @@ Chroot are represented by
.. _project-chroot-attributes:
-Entity Attributes
------------------
+Project chroot entity attributes
+--------------------------------
.. copied from frontend docs, don't forget to update
diff --git a/python/docs/client_v2/resources.rst b/python/docs/client_v2/resources.rst
index 7e721b6..03abc45 100644
--- a/python/docs/client_v2/resources.rst
+++ b/python/docs/client_v2/resources.rst
@@ -13,6 +13,8 @@ see entity attributes here: :ref:`project-attributes`.
Project chroot
--------------
+see entity attributes here: :ref:`project-chroot-attributes`.
+
.. autoclass:: copr.client_v2.resources.ProjectChroot
:members:
@@ -21,6 +23,8 @@ Project chroot
Build
-----
+see entity attributes here: :ref:`build-attributes`.
+
.. autoclass:: copr.client_v2.resources.Build
:members:
8 years, 5 months
[copr] master: [python][WIP] documentation for ClientV2: fix requirements.txt to include marshmallow (59e9f40)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 59e9f4069f6775d623a1d1ac545c62e5ebbac37b
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Wed Nov 18 16:42:11 2015 +0100
[python][WIP] documentation for ClientV2: fix requirements.txt to include marshmallow
>---------------------------------------------------------------
python/requirements.txt | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/python/requirements.txt b/python/requirements.txt
index b8249e4..16e4be9 100644
--- a/python/requirements.txt
+++ b/python/requirements.txt
@@ -7,3 +7,4 @@ six
sphinx
requests
requests-toolbelt
+marshmallow
8 years, 5 months
[copr] master: [python][WIP] documentation for ClientV2: done with Project Chroot (d97dc9a)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit d97dc9ab65dedef19dfc5181eb9c6927e5681f68
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Wed Nov 18 16:19:48 2015 +0100
[python][WIP] documentation for ClientV2: done with Project Chroot
>---------------------------------------------------------------
python/copr/client_v2/handlers.py | 41 ++++++++---
python/copr/client_v2/resources.py | 22 ++++--
python/docs/ClientV2.rst | 2 +-
python/docs/client_v2/entities.rst | 10 +++
python/docs/client_v2/handlers.rst | 19 ++++-
python/docs/client_v2/resource_info/project.rst | 36 ++++++----
.../client_v2/resource_info/project_chroot.rst | 76 +++++++++++++++++++-
python/docs/client_v2/resources.rst | 20 +++++-
8 files changed, 187 insertions(+), 39 deletions(-)
diff --git a/python/copr/client_v2/handlers.py b/python/copr/client_v2/handlers.py
index d52653c..b677946 100644
--- a/python/copr/client_v2/handlers.py
+++ b/python/copr/client_v2/handlers.py
@@ -279,9 +279,13 @@ class ProjectChrootHandle(AbstractHandle):
return "{}{}".format(self.root_url, project.get_href_by_name("chroots"))
def get_one(self, project, name):
- """
- :type project: copr.client_v2.resources.Project
+ """ Retrieves project chroot object.
+
+ :type project: :py:class:`~copr.client_v2.resources.Project`
+ :param project: parent project for the chroot
:param str name: chroot name
+
+ :rtype: :py:class:`~copr.client_v2.resources.ProjectChroot`
"""
url = "{}/{}".format(self.get_base_url(project), name)
@@ -295,8 +299,12 @@ class ProjectChrootHandle(AbstractHandle):
)
def get_list(self, project):
- """
- :type project: copr.client_v2.resources.Project
+ """ Retrieves project chroot list object.
+
+ :type project: :py:class:`~copr.client_v2.resources.Project`
+ :param project: parent project for the chroot
+
+ :rtype: :py:class:`~copr.client_v2.resources.ProjectChrootList`
"""
response = self.nc.request(self.get_base_url(project))
return ProjectChrootList.from_response(
@@ -306,8 +314,11 @@ class ProjectChrootHandle(AbstractHandle):
)
def disable(self, project, name):
- """
- :type project: copr.client_v2.resources.Project
+ """ Disables one chroot for the project
+
+ :type project: :py:class:`~copr.client_v2.resources.Project`
+ :param project: parent project for the chroot
+
:param str name: chroot name to disable
"""
url = "{}/{}".format(self.get_base_url(project), name)
@@ -315,10 +326,17 @@ class ProjectChrootHandle(AbstractHandle):
return OperationResult(self, response)
def enable(self, project, name, buildroot_pkgs=None):
- """
- :type project: copr.client_v2.resources.Project
+ """ Enables one chroot for the project
- :rtype:
+ :type project: :py:class:`~copr.client_v2.resources.Project`
+ :param project: parent project for the chroot
+
+ :param str name: chroot name to enable
+
+ :params buildroot_pkgs: packages to add into the buildroot
+ :type buildroot_pkgs: list of str
+
+ :rtype: :py:class:`.OperationResult`
"""
new_entity = ProjectChrootEntity(
@@ -336,7 +354,10 @@ class ProjectChrootHandle(AbstractHandle):
def update(self, project, chroot_entity):
"""
:type project: copr.client_v2.resources.Project
- :type chroot_entity: copr.client_v2.entities.ProjectChrootEntity
+ :param chroot_entity: Entity to update
+ :type chroot_entity: :py:class:`.entities.ProjectChrootEntity`
+
+ :rtype: :py:class:`.OperationResult`
"""
url = "{}/{}".format(self.get_base_url(project), chroot_entity.name)
response = self.nc.request(
diff --git a/python/copr/client_v2/resources.py b/python/copr/client_v2/resources.py
index b006a39..58a9cda 100644
--- a/python/copr/client_v2/resources.py
+++ b/python/copr/client_v2/resources.py
@@ -149,21 +149,21 @@ class Project(IndividualResource):
Shortcut for for :py:meth:`.ProjectHandle.update`
- :rtype: :py:class:`~copr.client_v2.resources.OperationResult`
+ :rtype: :py:class:`.OperationResult`
"""
return self._handle.update(self._entity)
def delete(self):
""" Updates project using the current state
- :rtype: :py:class:`~copr.client_v2.resources.OperationResult`
+ :rtype: :py:class:`.OperationResult`
"""
return self._handle.delete(self.id)
def get_self(self):
""" Retrieves fresh project object from the service
- :rtype: :py:class:`~copr.client_v2.resources.Project`
+ :rtype: :py:class:`.Project`
"""
return self._handle.get_one(self.id)
@@ -180,7 +180,7 @@ class Project(IndividualResource):
""" Retrieves project chroot object by the given name
:param str name: mock chroot name
- :rtype: :py:class:`~copr.client_v2.resources.ProjectChroot`
+ :rtype: :py:class:`.ProjectChroot`
"""
handle = self._handle.get_project_chroots_handle()
return handle.get_one(self, name)
@@ -188,7 +188,7 @@ class Project(IndividualResource):
def get_project_chroot_list(self):
""" Retrieves project chroots list
- :rtype: :py:class:`~copr.client_v2.resources.ProjectChrootList`
+ :rtype: :py:class:`.ProjectChrootList`
"""
handle = self._handle.get_project_chroots_handle()
return handle.get_list(self)
@@ -197,8 +197,10 @@ class Project(IndividualResource):
"""
Enables given chroot for this project
+ Shortcut for for :py:meth:`.ProjectChrootHandle.enable`
+
:param str name: mock chroot name
- :rtype: :py:class:`~copr.client_v2.resources.OperationResult`
+ :rtype: :py:class:`.OperationResult`
"""
handle = self._handle.get_project_chroots_handle()
return handle.enable(self, name)
@@ -249,9 +251,17 @@ class ProjectChroot(IndividualResource):
response=response, links=links, options=options)
def disable(self):
+ """ Disables chroot for the bound project
+
+ :rtype: :py:class:`.OperationResult`
+ """
return self._handle.disable(self._project, self.name)
def update(self):
+ """ Updates chroot with the current entity state
+
+ :rtype: :py:class:`.OperationResult`
+ """
return self._handle.update(self._project, self._entity)
diff --git a/python/docs/ClientV2.rst b/python/docs/ClientV2.rst
index 413a070..93e80c9 100644
--- a/python/docs/ClientV2.rst
+++ b/python/docs/ClientV2.rst
@@ -30,7 +30,6 @@ Resources info
client_v2/resource_info/build.rst
client_v2/resource_info/mock_chroot.rst
-
Autodoc
-------
@@ -39,3 +38,4 @@ Autodoc
client_v2/general.rst
client_v2/handlers.rst
client_v2/resources.rst
+ client_v2/entities.rst
diff --git a/python/docs/client_v2/entities.rst b/python/docs/client_v2/entities.rst
new file mode 100644
index 0000000..0bf4d2a
--- /dev/null
+++ b/python/docs/client_v2/entities.rst
@@ -0,0 +1,10 @@
+Entities
+========
+
+Represents domain objects like project or build.
+The user of ``python-copr`` is not expected to use the directly.
+
+.. automodule:: copr.client_v2.entities
+ :members:
+ :undoc-members:
+ :show-inheritance:
diff --git a/python/docs/client_v2/handlers.rst b/python/docs/client_v2/handlers.rst
index 4df33c0..0ba9293 100644
--- a/python/docs/client_v2/handlers.rst
+++ b/python/docs/client_v2/handlers.rst
@@ -1,18 +1,31 @@
Handlers
========
+Project
+-------
.. autoclass:: copr.client_v2.handlers.ProjectHandle
:members: get_list, get_one, update, delete
- :undoc-members:
+Project chroot
+--------------
.. autoclass:: copr.client_v2.handlers.ProjectChrootHandle
- :members: get_list, get_one
- :undoc-members:
+ :members: get_list, get_one, enable, update, disable
+Build
+-----
.. autoclass:: copr.client_v2.handlers.BuildHandle
:members:
+Build task
+----------
+
+.. note::
+ Not implemented yet
+
+
+Mock chroot
+-----------
.. autoclass:: copr.client_v2.handlers.MockChrootHandle
:members: get_list, get_one
:undoc-members:
diff --git a/python/docs/client_v2/resource_info/project.rst b/python/docs/client_v2/resource_info/project.rst
index 2758c08..76a9b14 100644
--- a/python/docs/client_v2/resource_info/project.rst
+++ b/python/docs/client_v2/resource_info/project.rst
@@ -1,13 +1,18 @@
+
+.. _project-info:
+
Project
=======
-Access to project resources is done through :py:meth:`~copr.client_v2.client.CoprClient.projects`.
+Access to the projects is done through :py:meth:`~copr.client_v2.client.CoprClient.projects`.
property of initialized :py:class:`~copr.client_v2.client.CoprClient`. That property is an instance of
:py:class:`~copr.client_v2.handlers.ProjectHandle`. Projects are represented by
:py:class:`~copr.client_v2.resources.Project` class.
-Individual Attributes
----------------------
+.. _project-attributes:
+
+Project entity attributes
+-------------------------
.. copied from frontend docs, don't forget to update
@@ -34,6 +39,19 @@ repos list of string yes list of additional repositori
all following examples assume that we use ``cl``
as an instance of :py:class:`.client_v2.client.CoprClient`
+
+Get projects list
+-----------------
+
+.. sourcecode:: python
+
+ >>> plist_1 = cl.project.get_list(limit=10)
+ # filter by name
+ >>> plist_2 = cl.project.get_list(name="copr")
+ # search by string
+ >>> plist_2 = cl.project.get_list(name="copr")
+
+
Get one project
---------------
@@ -62,18 +80,6 @@ Create new project
.. note:: Not Implemented yet
-Fetch projects
---------------
-
-.. sourcecode:: python
-
- >>> plist_1 = cl.project.get_list(limit=10)
- # filter by name
- >>> plist_2 = cl.project.get_list(name="copr")
- # search by string
- >>> plist_2 = cl.project.get_list(name="copr")
-
-
Access project chroots
----------------------
.. note::
diff --git a/python/docs/client_v2/resource_info/project_chroot.rst b/python/docs/client_v2/resource_info/project_chroot.rst
index 8920b02..033919d 100644
--- a/python/docs/client_v2/resource_info/project_chroot.rst
+++ b/python/docs/client_v2/resource_info/project_chroot.rst
@@ -4,6 +4,80 @@
Project chroot
==============
-foobar
+Access to the project chroots is done through :py:meth:`~copr.client_v2.client.CoprClient.project_chroots`.
+property of initialized :py:class:`~copr.client_v2.client.CoprClient`. That property is an instance of
+:py:class:`~copr.client_v2.handlers.ProjectChrootHandle`.
+
+However it's usually more convenient to access project chroots
+from an instance of :py:class:`~copr.client_v2.resources.Project`
+using methods :py:meth:`~copr.client_v2.resources.Project.get_project_chroot_list` or
+:py:meth:`~copr.client_v2.resources.Project.get_project_chroot`.
+
+Chroot are represented by
+:py:class:`~copr.client_v2.resources.ProjectChroot` class.
+
+.. _project-chroot-attributes:
+
+Entity Attributes
+-----------------
+
+.. copied from frontend docs, don't forget to update
+
+================== ==================== ========= ===============
+Field Type Can edit? Description
+================== ==================== ========= ===============
+name string no chroot name
+buildroot_pkgs list of strings yes packages to be installed into the buildroot
+comps string yes content of the `comps.xml`_
+comps_name string yes name of the uploaded comps file
+comps_len int no size of the uploaded comps file (bytes)
+================== ==================== ========= ===============
+
+.. note::
+ all following examples assume that we use ``cl``
+ as an instance of :py:class:`.client_v2.client.CoprClient`
+ and ``p`` as an instance of :py:class:`~copr.client_v2.resources.Project`
+
+Get project chroots list
+------------------------
+
+.. sourcecode:: python
+
+ >>> pc_list = cl.project_chroots.get_list(project=p)
+ # or more simple
+ >>> pc_list = p.get_project_chroot_list()
+ >>> map(str, pc_list)
+ ['<Project chroot: fedora-21-x86_64, additional packages: [], comps size if any: 0>',
+ '<Project chroot: epel-7-x86_64, additional packages: [], comps size if any: 0>']
+
+
+Get one project chroot
+----------------------
+
+.. sourcecode:: python
+
+
+ >>> pc = cl.project_chroots.get_one(project=p, name="fedora-23-x86_64")
+ # or
+ >>> pc = p.get_project_chroot("fedora-23-x86_64")
+ >>> print(pc)
+ <Project chroot: fedora-23-x86_64, additional packages: [], comps size if any: 0>
+
+Modify project chroot
+---------------------
+
+.. sourcecode:: python
+
+ >>> pc.buildroot_pkgs = ["scl-utils",]
+ >>> pc.update()
+
+Disable project chroot
+----------------------
+.. sourcecode:: python
+
+ >>> pc.disable()
+
+
+.. _comps.xml: https://fedorahosted.org/comps/
diff --git a/python/docs/client_v2/resources.rst b/python/docs/client_v2/resources.rst
index f19c5fc..7e721b6 100644
--- a/python/docs/client_v2/resources.rst
+++ b/python/docs/client_v2/resources.rst
@@ -1,28 +1,42 @@
Resources
=========
+Project
+-------
+see entity attributes here: :ref:`project-attributes`.
+
.. autoclass:: copr.client_v2.resources.Project
:members:
.. autoclass:: copr.client_v2.resources.ProjectList
:members:
+Project chroot
+--------------
.. autoclass:: copr.client_v2.resources.ProjectChroot
:members:
-
.. autoclass:: copr.client_v2.resources.ProjectChrootList
:members:
+Build
+-----
+.. autoclass:: copr.client_v2.resources.Build
+ :members:
-.. autoclass:: copr.client_v2.resources.MockChroot
+.. autoclass:: copr.client_v2.resources.BuildList
:members:
+Mock chroot
+-----------
+.. autoclass:: copr.client_v2.resources.MockChroot
+ :members:
.. autoclass:: copr.client_v2.resources.MockChrootList
:members:
-
+Operation result
+----------------
.. autoclass:: copr.client_v2.resources.OperationResult
:members:
8 years, 5 months
[copr] master: [python][WIP] documentation for ClientV2: mainly done with Project (2319f3d)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 2319f3da282a3d4d8f9d113053fa79d7cbb09290
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Wed Nov 18 15:07:49 2015 +0100
[python][WIP] documentation for ClientV2: mainly done with Project
>---------------------------------------------------------------
python/copr/client_v2/client.py | 2 +-
python/copr/client_v2/handlers.py | 20 ++++-
python/copr/client_v2/resources.py | 102 +++++++++++++++++---
python/docs/ClientV2.rst | 12 ++-
python/docs/client_v2/handlers.rst | 3 +-
python/docs/client_v2/resource_info/build.rst | 6 +
.../docs/client_v2/resource_info/mock_chroot.rst | 6 +
.../docs/client_v2/{ => resource_info}/project.rst | 71 ++++++++++----
.../client_v2/resource_info/project_chroot.rst | 9 ++
python/docs/client_v2/resources.rst | 27 +++++-
python/docs/client_v2/resources_usage.rst | 4 +-
python/docs/conf.py | 8 +-
python/docs/index.rst | 12 ++-
13 files changed, 233 insertions(+), 49 deletions(-)
diff --git a/python/copr/client_v2/client.py b/python/copr/client_v2/client.py
index 95ff21c..db92133 100644
--- a/python/copr/client_v2/client.py
+++ b/python/copr/client_v2/client.py
@@ -216,7 +216,7 @@ class CoprClient(UnicodeMixin, HandlersProvider):
return client
def post_init(self):
- """ Finalizes client initialization be querying API root info
+ """ Finalizes client initialization by querying API root info
"""
log.debug("Getting root resources")
diff --git a/python/copr/client_v2/handlers.py b/python/copr/client_v2/handlers.py
index 9978ace..d52653c 100644
--- a/python/copr/client_v2/handlers.py
+++ b/python/copr/client_v2/handlers.py
@@ -5,7 +5,7 @@ import os
from copr.client_v2.net_client import RequestError, MultiPartTuple
from .entities import ProjectChrootEntity
-from .resources import Project, OperationResult, ProjectsList, ProjectChroot, ProjectChrootList, Build, BuildList, \
+from .resources import Project, OperationResult, ProjectList, ProjectChroot, ProjectChrootList, Build, BuildList, \
MockChroot, MockChrootList
@@ -103,6 +103,19 @@ class BuildHandle(AbstractHandle):
def create_from_url(self, project_id, srpm_url,
chroots=None, enable_net=True):
+ """
+ Creates new build using public url to the srpm file
+
+ :param int project_id:
+ :param str srpm_url:
+ :param str file_name:
+ :param list chroots:
+ :param bool enable_net:
+ :return: created build
+ :rtype: Build
+ """
+
+
chroots = map(str, chroots or list())
content = {
"project_id": int(project_id),
@@ -181,13 +194,14 @@ class ProjectHandle(AbstractHandle):
def get_list(self, search_query=None, owner=None, name=None, limit=None, offset=None):
""" Retrieves projects object according to the given parameters
+
:param str search_query: search projects with such string
:param str owner: owner username
:param str name: project name
:param int limit: limit number of projects
:param int offset: number of projects to skip
- :rtype: :py:class:`~.resources.ProjectsList`
+ :rtype: :py:class:`~.resources.ProjectList`
"""
options = {
"search_query": search_query,
@@ -198,7 +212,7 @@ class ProjectHandle(AbstractHandle):
}
response = self.nc.request(self.get_base_url(), query_params=options)
- return ProjectsList.from_response(self, response, options)
+ return ProjectList.from_response(self, response, options)
def get_one(self, project_id):
# todo: implement: , show_builds=False, show_chroots=False):
diff --git a/python/copr/client_v2/resources.py b/python/copr/client_v2/resources.py
index 2bbd963..b006a39 100644
--- a/python/copr/client_v2/resources.py
+++ b/python/copr/client_v2/resources.py
@@ -50,8 +50,6 @@ class IndividualResource(with_metaclass(EntityFieldsMetaClass, UnicodeMixin)):
:type links: (dict of (str, Link)) or None
"""
_schema = EmptySchema(strict=True)
- # PY2 compatibility
- #__metaclass__ = EntityFieldsMetaClass
def __init__(self, entity, handle=None, response=None, links=None, embedded=None, options=None):
@@ -67,7 +65,8 @@ class IndividualResource(with_metaclass(EntityFieldsMetaClass, UnicodeMixin)):
dir(self.__class__) + list(self.__dict__.keys())
))
if self._entity:
- res.extend([x for x in dir(self._entity) if not x.startswith("_")])
+ # res.extend([x for x in dir(self._entity) if not x.startswith("_")])
+ res.extend(self._schema.fields.keys())
return res
def __unicode__(self):
@@ -88,7 +87,7 @@ class Root(IndividualResource):
def get_resource_base_url(self, resource_name):
"""
- :type entity_type: client_v2.common.EntityTypes
+ :param str resource_name:
"""
return "{}{}".format(self.root_url, self.get_href_by_name(resource_name))
@@ -141,7 +140,7 @@ class Project(IndividualResource):
def __init__(self, entity, handle, **kwargs):
super(Project, self).__init__(entity=entity, handle=handle, **kwargs)
- # import ipdb; ipdb.set_trace()
+
self._entity = entity
self._handle = handle
@@ -162,32 +161,64 @@ class Project(IndividualResource):
return self._handle.delete(self.id)
def get_self(self):
+ """ Retrieves fresh project object from the service
+
+ :rtype: :py:class:`~copr.client_v2.resources.Project`
+ """
return self._handle.get_one(self.id)
+ def get_builds(self, **query_options):
+ """ Get builds owned by this project
+
+ :param query_options: see :py:meth:`.handlers.BuildHandle.get_list`
+ :rtype: :py:class:`~.BuildsList`
+ """
+ handle = self._handle.get_builds_handle()
+ return handle.get_list(project_id=self.id, **query_options)
+
def get_project_chroot(self, name):
+ """ Retrieves project chroot object by the given name
+
+ :param str name: mock chroot name
+ :rtype: :py:class:`~copr.client_v2.resources.ProjectChroot`
+ """
handle = self._handle.get_project_chroots_handle()
return handle.get_one(self, name)
def get_project_chroot_list(self):
+ """ Retrieves project chroots list
+
+ :rtype: :py:class:`~copr.client_v2.resources.ProjectChrootList`
+ """
handle = self._handle.get_project_chroots_handle()
return handle.get_list(self)
def enable_project_chroot(self, name):
"""
+ Enables given chroot for this project
+
:param str name: mock chroot name
:rtype: :py:class:`~copr.client_v2.resources.OperationResult`
"""
handle = self._handle.get_project_chroots_handle()
return handle.enable(self, name)
- # TODO: remove proxy methods on the handle classes
def create_build_from_file(self, *args, **kwargs):
"""
- See additional options `:py:method:BuildHandle.create_from_file:`
+ Shortcut for :py:meth:`.BuildHandle.create_from_file`
+ (here you don't need to specify project_id)
"""
builds = self._handle.get_builds_handle()
return builds.create_from_file(self.id, *args, **kwargs)
+ def create_build_from_url(self, *args, **kwargs):
+ """
+ Shortcut for :py:meth:`.BuildHandle.create_from_file`
+ (here you don't need to specify project_id)
+ """
+ builds = self._handle.get_builds_handle()
+ return builds.create_from_url(self.id, *args, **kwargs)
+
@classmethod
def from_response(cls, handle, data_dict, response=None, options=None):
links = Link.from_dict(data_dict["_links"])
@@ -248,15 +279,22 @@ class MockChroot(IndividualResource):
class OperationResult(IndividualResource):
+ """ Fake resource to represent results of the requested operation
- # TODO: app param expected_status=200 and method is_successful() which would compare
- # obtained status with expected one
+ """
def __init__(self, handle, response=None, entity=None, options=None, expected_status=200):
super(OperationResult, self).__init__(handle=handle, response=response, entity=entity, options=options)
self._expected_status = expected_status
@property
def new_location(self):
+ """ Contains an url to the new location produced by an operation
+ If operation doesn't produce a new location would contain None
+
+ :rtype: str
+ """
+ # todo: Create sub-class for results which contains `new_location`
+
if self._response and \
self._response.headers and \
"location" in self._response.headers:
@@ -265,6 +303,11 @@ class OperationResult(IndividualResource):
return None
def is_successful(self):
+ """ Performs check if status code is equal to the expected value
+ of particular request.
+
+ :rtype: bool
+ """
if self._response and self._response.status_code == self._expected_status:
return True
else:
@@ -317,22 +360,40 @@ class CollectionResource(Iterable, UnicodeMixin):
"""
return iter(self._individuals)
+ def __len__(self):
+ if self._individuals is None:
+ raise RuntimeError(u"Collection resource is missing self._individuals")
+
+ return len(self._individuals)
+
+ def __getitem__(self, item):
+ if self._individuals is None:
+ raise RuntimeError(u"Collection resource is missing self._individuals")
+
+ return self._individuals[item]
+
@classmethod
def from_response(cls, handle, response, options):
raise NotImplementedError
- # todo: add classmethod from response
-
-class ProjectsList(CollectionResource):
+class ProjectList(CollectionResource):
"""
:type handle: copr.client_v2.handlers.ProjectHandle
"""
def __init__(self, handle, **kwargs):
- super(ProjectsList, self).__init__(**kwargs)
+ super(ProjectList, self).__init__(**kwargs)
self._handle = handle
+ def next_page(self):
+ """
+ Retrieves next chunk of the Project list for the same query options
+
+ :rtype: :py:class:`.ProjectList`
+ """
+ return super(ProjectList, self).next_page()
+
@property
def projects(self):
""" :rtype: list of :py:class:`~.resources.Project` """
@@ -341,7 +402,7 @@ class ProjectsList(CollectionResource):
@classmethod
def from_response(cls, handle, response, options):
data_dict = response.json
- result = ProjectsList(
+ result = ProjectList(
handle,
response=response,
links=Link.from_dict(data_dict["_links"]),
@@ -390,6 +451,8 @@ class BuildList(CollectionResource):
class ProjectChrootList(CollectionResource):
"""
+ List of the :class:`~.ProjectChroot` in the one Project.
+
:type handle: copr.client_v2.handlers.ProjectChrootHandle
"""
@@ -400,9 +463,17 @@ class ProjectChrootList(CollectionResource):
@property
def chroots(self):
+ """
+ :rtype: list of :py:class:`~.resources.ProjectChroot`
+ """
return self._individuals
def enable(self, name):
+ """
+ Enables mock chroot for the current project
+
+ :rtype: :py:class:`~.OperationResult`
+ """
return self._handle.enable(self._project, name)
@classmethod
@@ -426,6 +497,8 @@ class ProjectChrootList(CollectionResource):
class MockChrootList(CollectionResource):
"""
+ List of the mock chroots supported by the service
+
:type handle: copr.client_v2.handlers.MockChrootHandle
"""
@@ -435,6 +508,7 @@ class MockChrootList(CollectionResource):
@property
def chroots(self):
+
return self._individuals
@classmethod
diff --git a/python/docs/ClientV2.rst b/python/docs/ClientV2.rst
index 8925854..413a070 100644
--- a/python/docs/ClientV2.rst
+++ b/python/docs/ClientV2.rst
@@ -18,7 +18,17 @@ of retrieved objects.
client_v2/initialization.rst
client_v2/resources_usage.rst
client_v2/errors.rst
- client_v2/project.rst
+
+Resources info
+--------------
+
+.. toctree::
+ :maxdepth: 1
+
+ client_v2/resource_info/project.rst
+ client_v2/resource_info/project_chroot.rst
+ client_v2/resource_info/build.rst
+ client_v2/resource_info/mock_chroot.rst
Autodoc
diff --git a/python/docs/client_v2/handlers.rst b/python/docs/client_v2/handlers.rst
index e830dc1..4df33c0 100644
--- a/python/docs/client_v2/handlers.rst
+++ b/python/docs/client_v2/handlers.rst
@@ -11,8 +11,7 @@ Handlers
.. autoclass:: copr.client_v2.handlers.BuildHandle
- :members: get_list, get_one
- :undoc-members:
+ :members:
.. autoclass:: copr.client_v2.handlers.MockChrootHandle
:members: get_list, get_one
diff --git a/python/docs/client_v2/resource_info/build.rst b/python/docs/client_v2/resource_info/build.rst
new file mode 100644
index 0000000..924dc66
--- /dev/null
+++ b/python/docs/client_v2/resource_info/build.rst
@@ -0,0 +1,6 @@
+.. _build-info:
+
+Build
+=====
+
+pass
diff --git a/python/docs/client_v2/resource_info/mock_chroot.rst b/python/docs/client_v2/resource_info/mock_chroot.rst
new file mode 100644
index 0000000..f7194da
--- /dev/null
+++ b/python/docs/client_v2/resource_info/mock_chroot.rst
@@ -0,0 +1,6 @@
+.. _`mock-chroot-info`:
+
+Mock chroot
+===========
+
+
diff --git a/python/docs/client_v2/project.rst b/python/docs/client_v2/resource_info/project.rst
similarity index 54%
rename from python/docs/client_v2/project.rst
rename to python/docs/client_v2/resource_info/project.rst
index 9d3cb48..2758c08 100644
--- a/python/docs/client_v2/project.rst
+++ b/python/docs/client_v2/resource_info/project.rst
@@ -2,7 +2,9 @@ Project
=======
Access to project resources is done through :py:meth:`~copr.client_v2.client.CoprClient.projects`.
-property of initialized :py:class:`~copr.client_v2.client.CoprClient`.
+property of initialized :py:class:`~copr.client_v2.client.CoprClient`. That property is an instance of
+:py:class:`~copr.client_v2.handlers.ProjectHandle`. Projects are represented by
+:py:class:`~copr.client_v2.resources.Project` class.
Individual Attributes
---------------------
@@ -23,50 +25,85 @@ instructions string yes installation instructions
homepage string(URL) yes project homepage URL
contact string(URL or email) yes contact with the project maintainer
disable_createrepo bool yes disables automatic repository metadata generation
-build_enable_net bool yes set default value for new builds option `enable_net`
+build_enable_net bool yes set default value for new builds option ``enable_net``
repos list of string yes list of additional repositories to be enabled during the build
================== ==================== ========= =================================================================================
-.. note:: all following examples assume that we use `cl` as an instance of :py:class:`.client_v2.client.CoprClient`
+.. note::
+ all following examples assume that we use ``cl``
+ as an instance of :py:class:`.client_v2.client.CoprClient`
Get one project
---------------
- .. sourcecode:: python
+.. sourcecode:: python
- >>> p = cl.projects.get_one(1835)
+ >>> p = cl.projects.get_one(1835)
Modify project parameters
-------------------------
- .. sourcecode:: python
+.. sourcecode:: python
- >>> p.description = "Nothing"
- >>> p.update()
+ >>> p.description = "Nothing"
+ >>> p.update()
Delete project
--------------
- .. sourcecode:: python
+.. sourcecode:: python
- >>> p.delete()
+ >>> p.delete()
Create new project
------------------
- .. todo:: Not Implemented yet
+.. note:: Not Implemented yet
Fetch projects
--------------
- .. sourcecode:: python
+.. sourcecode:: python
- >>> plist_1 = cl.project.get_list(limit=10)
- # filter by name
- >>> plist_2 = cl.project.get_list(name="copr")
- # search by string
- >>> plist_2 = cl.project.get_list(name="copr")
+ >>> plist_1 = cl.project.get_list(limit=10)
+ # filter by name
+ >>> plist_2 = cl.project.get_list(name="copr")
+ # search by string
+ >>> plist_2 = cl.project.get_list(name="copr")
+Access project chroots
+----------------------
+.. note::
+ see also :ref:`project-chroot-info`
+
+
+.. sourcecode:: python
+
+ # get all lists
+ >>> chroots = p.get_project_chroot_list()
+ >>> print("\n".join(map(str, chroots)))
+ <Project chroot: fedora-21-x86_64, additional packages: [], comps size if any: 0>
+ <Project chroot: fedora-21-i386, additional packages: [], comps size if any: 0>
+ # get one chroot
+ >>> chroot_1 = p.get_project_chroot("fedora-22-i386")
+ # enable chroot for project
+ >>> p.enable_project_chroot("fedora-22-x86_64)
+
+Access project builds
+---------------------
+.. note::
+ see also :ref:`build-info`
+
+.. sourcecode:: python
+
+ >>> p.get_builds(limit=5)
+ >>> pbuilds = p.get_builds(limit=5)
+ >>> print(pbuilds[3])
+ <Build #138414 state: failed>
+
+ # submit new builds
+ >>> p.create_build_from_url(srpm_url="http://example.com/my.src.rpm")
+ >>> p.create_build_from_file(file_path="/tmp/my.src.rpm")
diff --git a/python/docs/client_v2/resource_info/project_chroot.rst b/python/docs/client_v2/resource_info/project_chroot.rst
new file mode 100644
index 0000000..8920b02
--- /dev/null
+++ b/python/docs/client_v2/resource_info/project_chroot.rst
@@ -0,0 +1,9 @@
+
+.. _project-chroot-info:
+
+Project chroot
+==============
+
+foobar
+
+
diff --git a/python/docs/client_v2/resources.rst b/python/docs/client_v2/resources.rst
index 3693426..f19c5fc 100644
--- a/python/docs/client_v2/resources.rst
+++ b/python/docs/client_v2/resources.rst
@@ -2,8 +2,29 @@ Resources
=========
.. autoclass:: copr.client_v2.resources.Project
- :members: update, delete
- :undoc-members:
+ :members:
+
+.. autoclass:: copr.client_v2.resources.ProjectList
+ :members:
+
+.. autoclass:: copr.client_v2.resources.ProjectChroot
+ :members:
+
+
+.. autoclass:: copr.client_v2.resources.ProjectChrootList
+ :members:
+
-.. autoclass:: copr.client_v2.resources.ProjectsList
+.. autoclass:: copr.client_v2.resources.MockChroot
:members:
+
+
+.. autoclass:: copr.client_v2.resources.MockChrootList
+ :members:
+
+
+.. autoclass:: copr.client_v2.resources.OperationResult
+ :members:
+
+
+
diff --git a/python/docs/client_v2/resources_usage.rst b/python/docs/client_v2/resources_usage.rst
index dc95fa2..c48cf03 100644
--- a/python/docs/client_v2/resources_usage.rst
+++ b/python/docs/client_v2/resources_usage.rst
@@ -2,7 +2,7 @@ Resources
~~~~~~~~~
Client represents API with two kinds of resources: Individuals and Collections. For example when we request
-all projects with name `copr` we would receive collection ProjectsList_ resource:
+all projects with name `copr` we would receive collection :py:class:`~copr.client_v2.resources.ProjectList` resource:
.. sourcecode:: python
@@ -31,7 +31,7 @@ retrieved in the one request, collections has method `next_page()` to retrieve m
-If we already knew project id we could get an individual Project_ resource:
+If we already knew project id we could get an individual :py:class:`~copr.client_v2.resources.Project` resource:
.. sourcecode:: python
diff --git a/python/docs/conf.py b/python/docs/conf.py
index ff2001e..115f114 100644
--- a/python/docs/conf.py
+++ b/python/docs/conf.py
@@ -69,7 +69,7 @@ release = '1.52'
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
-#default_role = None
+default_role = "any"
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
@@ -93,7 +93,9 @@ pygments_style = 'sphinx'
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
-html_theme = 'default'
+# html_theme = 'classic'
+#html_theme = 'alabaster'
+
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
@@ -243,4 +245,4 @@ texinfo_documents = [
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
-#autodoc_member_order = 'bysource'
+autodoc_member_order = 'bysource'
diff --git a/python/docs/index.rst b/python/docs/index.rst
index d23535d..8e75b14 100644
--- a/python/docs/index.rst
+++ b/python/docs/index.rst
@@ -12,7 +12,10 @@ through its `API <http://copr.fedoraproject.org/api>`_.
Python-copr right now is in alpha stage, so expect lot of changes. Now it targets python 2.6+
and python3.3+.
-.. include:: installation.rst
+.. toctree::
+ :maxdepth: 1
+
+ installation.rst
Contact
=======
@@ -31,8 +34,11 @@ Usage
Recently Copr started to offer an alternative REST-like APIv2_.
New API is provided by mostly independent `client_v2` package.
-.. include:: ClientV1.rst
-.. include:: ClientV2.rst
+.. toctree::
+ :maxdepth: 1
+
+ ClientV1.rst
+ ClientV2.rst
Indices and tables
8 years, 5 months