Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit 3026da47cb3a504f4394b8dfa00488e29bf6c681
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Fri Sep 19 14:16:25 2014 +0200
[python-copr] minor fixes, added usage examples to docs
---------------------------------------------------------------
python/copr/client/client.py | 11 ++--
python/copr/client/parsers.py | 2 +-
python/copr/client/responses.py | 7 +++
python/docs/Examples.rst | 98 +++++++++++++++++++++++++++++++++++++++
python/docs/conf.py | 4 +-
python/docs/index.rst | 8 ++-
6 files changed, 119 insertions(+), 11 deletions(-)
diff --git a/python/copr/client/client.py b/python/copr/client/client.py
index a84330c..170bdd1 100644
--- a/python/copr/client/client.py
+++ b/python/copr/client/client.py
@@ -300,10 +300,10 @@ class CoprClient(object):
NewBuildListParser,
]
)
- response.handle = BuildHandle(
- self, response=response, build_id=None,
- projectname=projectname, username=username
- )
+ response.handle = BaseHandle(
+ self, response=response,
+ projectname=projectname, username=username)
+
return response
def get_project_details(self, projectname, username=None):
@@ -318,7 +318,7 @@ class CoprClient(object):
- text fields: "description", "instructions",
"last_modified",
"name"
- - **chroots_list**: list of
+ - **chroots**: list of
:py:class:`~.responses.ProjectChrootWrapper`
"""
if not username:
@@ -485,6 +485,7 @@ class CoprClient(object):
data=result_data,
parsers=[
CommonMsgErrorOutParser,
+ ProjectDetailsFieldsParser,
fabric_simple_fields_parser(["buildroot_pkgs"])
]
)
diff --git a/python/copr/client/parsers.py b/python/copr/client/parsers.py
index 159653b..aa8338c 100644
--- a/python/copr/client/parsers.py
+++ b/python/copr/client/parsers.py
@@ -82,7 +82,7 @@ class ProjectChrootsParser(IParser):
chrootname=chrootname,
repo_url=url
)
- for chrootname, url in
data["detail"]["yum_repos"].iteritems()
+ for chrootname, url in
data["detail"]["yum_repos"].items()
]
else:
raise KeyError("Response missing data about chroots")
diff --git a/python/copr/client/responses.py b/python/copr/client/responses.py
index 10aea13..7871234 100644
--- a/python/copr/client/responses.py
+++ b/python/copr/client/responses.py
@@ -132,6 +132,13 @@ class ProjectHandle(BaseHandle):
return self.client.delete_project(
self.projectname, username=self.username)
+ def create_new_build(self, src_pkgs, chroots=None):
+ """
+ Shortcut to :meth"`~.client.CoprClient.create_new_build'
+ """
+ return self.client.create_new_build(self.projectname,
+ src_pkgs, chroots)
+
class BuildHandle(BaseHandle):
"""
diff --git a/python/docs/Examples.rst b/python/docs/Examples.rst
new file mode 100644
index 0000000..540ca2b
--- /dev/null
+++ b/python/docs/Examples.rst
@@ -0,0 +1,98 @@
+Create client
+-------------
+::
+
+ from copr.client import CoprClient
+ cl = CoprClient.create_from_file_config()
+
+
+Get projects list
+-----------------
+::
+
+ # your projects
+ result = cl.get_projects_list().projects_list
+
+ # other user projects
+ result = cl.get_projects_list(username="rhscl")
+
+ # print list for humans and machines
+ from pprint import pprint
+ for prj in result.projects_list:
+ print(prj)
+ pprint(prj.get_project_details().data)
+
+
+Search for projects
+-------------------
+::
+
+ result = cl.search_projects("python")
+ # print list for humans
+ for prj in result.projects_list:
+ print(prj)
+
+
+
+Create/update/delete project
+----------------------------
+::
+
+ result = cl.create_project("hello_world",
chroots=["fedora-20-x86_64"],
+ description="My cool app")
+
+ # assert correct description
+ assert result.handle.get_project_details().description == "My cool app"
+
+ # add instruction
+ result.handle.modify_project(instructions="How does one patch KDE2 under
FreeBSD?")
+ # which is shorter than
+ cl.modify_project("hello_world", instructions="...")
+
+ # delete project
+ result.handle.delete_project()
+ # again shortcut for
+ cl.delete_project("hello_world")
+
+
+
+Work with builds
+----------------
+::
+
+ # building new package
+ result = cl.create_new_build("hello_world",
+
pkgs=["http://example.com/pkg.src.rpm",])
+
+ # retrieve build statuses
+ for bw in result.builds_list:
+ print("{}:{}".format(bw.build_id,
bw.handle.get_build_details().status))
+
+ # cancel all created build
+ for bw in result.builds_list:
+ bw.handle.cancel_build()
+
+ # get build status for each chroot
+ for bw in result.builds_list:
+ print("build: {}".format(bw.build_id))
+ for ch, status in
bw.handle.get_build_details().data["chroots"].items():
+ print("\t chroot {}:\t {}".format(ch, status))
+
+ # simple build progress:
+ import time, datetime
+ watched = set(result.builds_list)
+ done = set()
+ while watched != done:
+ print("time: {}".format(datetime.datetime.now()))
+ for bw in watched:
+ if bw in done:
+ continue
+ status = bw.handle.get_build_details().status
+ print("{}: {}".format(bw.build_id, status))
+ if status in ["skipped", "failed",
"succeeded"]:
+ done.add(bw)
+ time.sleep(10)
+
+ # cancel all created build
+ for bw in result.builds_list:
+ bw.handle.cancel_build()
diff --git a/python/docs/conf.py b/python/docs/conf.py
index f26ddbf..c8bb7ce 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.48'
+version = '1.52'
# The full version, including alpha/beta/rc tags.
-release = '1.48'
+release = '1.52'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff --git a/python/docs/index.rst b/python/docs/index.rst
index 653c34a..75bd2a6 100644
--- a/python/docs/index.rst
+++ b/python/docs/index.rst
@@ -64,19 +64,21 @@ are wrapped into the Response object.
Depending on used methods Responses will have different set of
provided attributes and methods.
+.. toctree::
+ Examples
-Auto-generated documentation
-----------------------------
+Autodoc
+-------
See method signatures and response objects in
the auto generated documentation:
.. toctree::
-
CoprClient
Responses
+
Indices and tables
==================