#458 [frontend][python] add possibility to query all projects (see RhBug: 1130166)
Merged 5 years ago by msuchy. Opened 5 years ago by frostyx.
copr/ frostyx/copr apiv3-all-projects  into  master

@@ -63,8 +63,10 @@ 

  @apiv3_ns.route("/project/list", methods=GET)

  @pagination()

  @query_params()

- def get_project_list(ownername, **kwargs):

-     if ownername.startswith("@"):

+ def get_project_list(ownername=None, **kwargs):

+     if not ownername:

+         query = CoprsLogic.get_multiple()

+     elif ownername.startswith("@"):

          group_name = ownername[1:]

          query = CoprsLogic.get_multiple()

          query = CoprsLogic.filter_by_group_name(query, group_name)

@@ -23,7 +23,7 @@ 

          response = request.send()

          return munchify(response)

  

-     def get_list(self, ownername, pagination=None):

+     def get_list(self, ownername=None, pagination=None):

          """

          Return a list of projects

  

Do not insist on ownername parameter for ProjectProxy.get_list(...) to have a possibility to query all projects (of all users).

Usage:

from copr.v3 import Client
from copr.v3.pagination import next_page

client = Client.create_from_config_file()

projects_page = client.project_proxy.get_list(pagination={"limit": 10})
while projects_page:
    for project in projects_page:
        print(project.full_name)
    projects_page = next_page(projects_page)

It is an example with pagination, I wouldn't recommend anyone to query all projects in Copr without it.

Pull-Request has been merged by msuchy

5 years ago