]> git.ipfire.org Git - pakfire.git/commitdiff
client: Add repo API opertions
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 18 Aug 2023 15:27:49 +0000 (15:27 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 18 Aug 2023 15:29:25 +0000 (15:29 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/hub.py
src/scripts/pakfire-client.in

index 99e2ca06baeda3afd008dc6c8f38fe7976cd2456..4d55b333affd7c4e0d339fc7638256e59e3c68c1 100644 (file)
@@ -464,6 +464,33 @@ class Hub(object):
                """
                return await self._proxy(JobControlConnection, *args, **kwargs)
 
+       # Repositories
+
+       async def list_repos(self, distro):
+               """
+                       Lists all repositories
+               """
+               return await self._request("GET", "/api/v1/repos/%s" % distro)
+
+       async def get_repo(self, distro, name):
+               """
+                       Fetches repository information
+               """
+               return await self._request("GET", "/api/v1/repos/%s/%s" % (distro, name))
+
+       async def create_repo(self, distro, name, description=None):
+               """
+                       Creates a new repository
+               """
+               return await self._request("POST", "/api/v1/repos/%s" % distro,
+                       name=name, description=description)
+
+       async def delete_repo(self, distro, name):
+               """
+                       Deletes a repository
+               """
+               await self._request("DELETE", "/api/v1/repos/%s/%s" % (distro, name))
+
 
 class HubObject(object):
        # Disable Nagle's algorithm?
index 0df520205a3d65831120adf07c0d309d4345c5b7..a0ead668775bd866c8f0bef7f680553adf4dabec 100644 (file)
@@ -58,6 +58,36 @@ class Cli(object):
                        help=_("Check the connection to the hub"))
                check_connection.set_defaults(func=self._check_connection)
 
+               # repo
+               repo = subparsers.add_parser("repo",
+                       help=_("Manage repositories"))
+
+               repo_subparsers = repo.add_subparsers()
+
+               # repo create
+               repo_create = repo_subparsers.add_parser("create", help=_("Create a repository"))
+               repo_create.add_argument("distro", help=_("Distribution"))
+               repo_create.add_argument("name", help=_("The name of the repository"))
+               repo_create.add_argument("--description", help=_("Description"))
+               repo_create.set_defaults(func=self._repo_create)
+
+               # repo delete
+               repo_delete = repo_subparsers.add_parser("delete", help=_("Delete a repository"))
+               repo_delete.add_argument("distro", help=_("Distribution"))
+               repo_delete.add_argument("name", help=_("The name of the repository"))
+               repo_delete.set_defaults(func=self._repo_delete)
+
+               # repo list
+               repo_list = repo_subparsers.add_parser("list", help=_("List all repositories"))
+               repo_list.add_argument("distro", help=_("Distribution"))
+               repo_list.set_defaults(func=self._repo_list)
+
+               # repo show
+               repo_show = repo_subparsers.add_parser("show", help=_("Show a repository"))
+               repo_show.add_argument("distro", help=_("Distribution"))
+               repo_show.add_argument("name", help=_("The name of the repository"))
+               repo_show.set_defaults(func=self._repo_show)
+
                # upload
                upload = subparsers.add_parser("upload",
                        help=_("Upload a file to the build service"))
@@ -146,6 +176,56 @@ class Cli(object):
                except KeyError:
                        pass
 
+       # Repositories
+
+       def _print_repo(self, repo):
+               print("%s:" % repo.get("name"))
+
+               # Description
+               description = repo.get("description")
+               if description:
+                       print()
+                       for line in description.splitlines():
+                               print(" %s" % line)
+                       print()
+
+               print(_("Created"), repo.get("created_at"))
+               print()
+
+       async def _repo_create(self, hub, ns):
+               # Send request
+               repo = await hub.create_repo(distro=ns.distro,
+                       name=ns.name, description=ns.description)
+
+               # Print the result
+               self._print_repo(repo)
+
+       async def _repo_delete(self, hub, ns):
+               # Send request
+               await hub.delete_repo(distro=ns.distro, name=ns.name)
+
+       async def _repo_list(self, hub, ns):
+               # Send request
+               repos = await hub.list_repos(distro=ns.distro)
+
+               # Get repos
+               repos = repos.get("repos", [])
+
+               # End if nothing was found
+               if not repos:
+                       return
+
+               # Print all repositories
+               for repo in sorted(repos, key=lambda r: r.get("name")):
+                       self._print_repo(repo)
+
+       async def _repo_show(self, hub, ns):
+               # Send request
+               repo = await hub.get_repo(distro=ns.distro, name=ns.name)
+
+               if repo:
+                       self._print_repo(repo)
+
        # Uploads
 
        async def _upload_list(self, hub, ns):