From: Michael Tremer Date: Thu, 14 Jul 2022 15:22:07 +0000 (+0000) Subject: client: Implement creating builds X-Git-Tag: 0.9.28~718 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dcc48721ac4dcb7e782d2d56468989673eed2851;p=pakfire.git client: Implement creating builds Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/client.py b/src/pakfire/client.py index 39daed23d..d248e7792 100644 --- a/src/pakfire/client.py +++ b/src/pakfire/client.py @@ -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) diff --git a/src/pakfire/hub.py b/src/pakfire/hub.py index 5c4f3cc03..76c07d3bc 100644 --- a/src/pakfire/hub.py +++ b/src/pakfire/hub.py @@ -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 diff --git a/src/scripts/pakfire-client.in b/src/scripts/pakfire-client.in index 597f9318d..ffd3206d7 100644 --- a/src/scripts/pakfire-client.in +++ b/src/scripts/pakfire-client.in @@ -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()