]> git.ipfire.org Git - pakfire.git/commitdiff
client: Implement creating builds
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 14 Jul 2022 15:22:07 +0000 (15:22 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 14 Jul 2022 15:22:07 +0000 (15:22 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/client.py
src/pakfire/hub.py
src/scripts/pakfire-client.in

index 39daed23d4aa99c3869819aded183f8c19218ec0..d248e7792d2253e4bcd50293a79ba2781e16be4f 100644 (file)
@@ -59,10 +59,8 @@ class Client(object):
 
        # Builds
 
-       def create_build(self, filename, **kwargs):
-               build_id = self.hub.create_build(filename, **kwargs)
-
-               return self.get_build(build_id)
+       async def build(self, *args, **kwargs):
+               return await self.hub.build(*args, **kwargs)
 
        def get_build(self, build_id):
                return Build(self, build_id)
index 5c4f3cc0335f9c4f82ec255ef1dda5b5dd544016..76c07d3bc932947ac08347adf3af9441dfa24f08 100644 (file)
@@ -126,25 +126,22 @@ class Hub(object):
        def get_build(self, uuid):
                return self._request("/builds/%s" % uuid, decode="json")
 
-       def create_build(self, path, type, arches=None, distro=None):
+       async def build(self, path, arches=None):
                """
                        Create a new build on the hub
                """
-               assert type in ("scratch", "release")
+               # Upload the souce file to the server
+               upload_id = await self.upload(path)
 
-               # XXX Check for permission to actually create a build
+               log.debug("%s has been uploaded as %s" % (path, upload_id))
 
-               # Upload the souce file to the server
-               upload_id = self.upload_file(path)
+               # Create a new build
+               build_id = await self._request("POST", "/builds",
+                       upload_id=upload_id, arches=arches)
 
-               data = {
-                       "arches"     : ",".join(arches or []),
-                       "build_type" : type,
-                       "distro"     : distro or "",
-                       "upload_id"  : upload_id,
-               }
+               log.debug("Build creates as %s" % build_id)
 
-               return self._request("/builds/create", data=data, decode="ascii")
+               return build_id
 
        # Job actions
 
index 597f9318d61b94f09454ba5b8d49d44cdc29f3a4..ffd3206d76635c1dbd4aac60df415d0c5fa77859 100644 (file)
@@ -100,47 +100,18 @@ class Cli(object):
                sys.exit(ret or 0)
 
        async def _build(self, client, ns):
-               # Create a temporary directory.
-               temp_dir = tempfile.mkdtemp()
-
-               # Format arches.
-               if ns.arch:
-                       arches = self.args.arch.split(",")
-               else:
-                       arches = None
+               # Create a temporary directory if we need to call dist
+               tmp = tempfile.TemporaryDirectory(prefix="pakfire-client-")
 
                try:
-                       # Package all packages first and save the actual filenames
-                       packages = []
+                       # XXX implement calling dist
 
+                       # Build all packages
                        for package in ns.packages:
-                               if package.endswith(".%s" % MAKEFILE_EXTENSION):
-                                       # Create a source package from the makefile.
-                                       p = self.pakfire()
-                                       package = p.dist(package, temp_dir)
-                                       packages.append(package)
-
-                               elif package.endswith(".%s" % PACKAGE_EXTENSION):
-                                       packages.append(package)
-
-                               else:
-                                       raise Exception("Unknown filetype: %s" % package)
-
-                       assert packages
-
-                       # Upload the packages to the build service
-                       for package in packages:
-                               build = client.create_build(package, type="scratch", arches=arches)
-
-                               # Show information about the uploaded build
-                               summary = build.dump()
-                               for line in summary.splitlines():
-                                       print("  %s" % line)
+                               await client.build(package, arches=ns.arch)
 
                finally:
-                       # Cleanup the temporary directory and all files.
-                       if os.path.exists(temp_dir):
-                               shutil.rmtree(temp_dir, ignore_errors=True)
+                       tmp.cleanup()
 
        async def _check_connection(self, client, ns):
                success = client.check_connection()