From: Michael Tremer Date: Wed, 14 Jun 2023 15:15:50 +0000 (+0000) Subject: build: Add scaffolding to create images X-Git-Tag: 0.9.29~116 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a2612d13ffc3105f3d44dab5eaada905769f0280;p=people%2Fms%2Fpakfire.git build: Add scaffolding to create images Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index c78b2f8f6..ee059b3b9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -727,6 +727,7 @@ dist_scripts_SCRIPTS = \ src/scripts/find-prerequires \ src/scripts/find-provides \ src/scripts/find-requires \ + src/scripts/mkimage \ src/scripts/perl.prov \ src/scripts/perl.req \ src/scripts/strip diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index a37c80c0f..8b1ae63f8 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -1464,6 +1464,51 @@ ERROR: return ret; } +static PyObject* Pakfire_mkimage(PakfireObject* self, PyObject* args, PyObject* kwargs) { + char* kwlist[] = { + "type", + "path", + NULL, + }; + struct pakfire_build* build = NULL; + const char* type = NULL; + const char* path = NULL; + int r; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ss", kwlist, &type, &path)) + return NULL; + + // Create a new build environment + r = pakfire_build_create(&build, self->pakfire, NULL, 0); + if (r) { + PyErr_SetFromErrno(PyExc_OSError); + goto ERROR; + } + + Py_BEGIN_ALLOW_THREADS + + // Run mkimage + r = pakfire_build_mkimage(build, type, path); + if (r) { + Py_BLOCK_THREADS; + + if (r < 0) + PyErr_SetFromErrno(PyExc_OSError); + + goto ERROR; + } + + Py_END_ALLOW_THREADS + +ERROR: + if (build) + pakfire_build_unref(build); + if (r) + return NULL; + + Py_RETURN_NONE; +} + static struct PyMethodDef Pakfire_methods[] = { { "build", @@ -1537,6 +1582,12 @@ static struct PyMethodDef Pakfire_methods[] = { METH_VARARGS|METH_KEYWORDS, NULL, }, + { + "mkimage", + (PyCFunction)Pakfire_mkimage, + METH_VARARGS|METH_KEYWORDS, + NULL + }, { "open", (PyCFunction)Pakfire_open, diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index f7a020932..9dcdd90bf 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -2210,6 +2210,40 @@ ERROR: return r; } +PAKFIRE_EXPORT int pakfire_build_mkimage(struct pakfire_build* build, + const char* type, const char* filename) { + int r; + + // Check inputs + if (!type || !filename) { + errno = EINVAL; + return 1; + } + + // Initialize the build environment + r = pakfire_build_init(build); + if (r) + goto ERROR; + + // XXX Allocate a temporary file + + const char* args[] = { + type, + // XXX tempfile + NULL, + }; + + // Run the mkimage script + r = pakfire_build_run_script(build, "mkimage", args, NULL, NULL, NULL); + if (r) + goto ERROR; + +ERROR: + // XXX remove the tempfile + + return r; +} + int pakfire_build_clean(struct pakfire* pakfire, int flags) { struct pakfire_repo* local = NULL; int r = 0; diff --git a/src/libpakfire/include/pakfire/build.h b/src/libpakfire/include/pakfire/build.h index 7f470e1ac..143a2b2fd 100644 --- a/src/libpakfire/include/pakfire/build.h +++ b/src/libpakfire/include/pakfire/build.h @@ -43,6 +43,9 @@ int pakfire_build_set_target(struct pakfire_build* build, const char* target); int pakfire_build_exec(struct pakfire_build* build, const char* path); +int pakfire_build_mkimage(struct pakfire_build* build, + const char* type, const char* filename); + int pakfire_build_clean(struct pakfire* pakfire, int flags); int pakfire_shell(struct pakfire* pakfire, const char** packages, int flags); diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 0a0093b18..eb16a54d2 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -65,6 +65,7 @@ global: # build pakfire_build_create; pakfire_build_exec; + pakfire_build_mkimage; pakfire_build_ref; pakfire_build_set_ccache_path; pakfire_build_set_target; diff --git a/src/scripts/mkimage b/src/scripts/mkimage new file mode 100644 index 000000000..e56ae1646 --- /dev/null +++ b/src/scripts/mkimage @@ -0,0 +1,44 @@ +#!/bin/bash +############################################################################### +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2021 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +mkimage_installer_iso() { + echo "TODO" +} + +main() { + local type="${1}" + local path="${2}" + + case "${type}" in + installer-iso) + "mkimage_${type//-/_}" "${path}" || return $? + ;; + + *) + echo "Unknown image type: ${type}" >&2 + return 2 + ;; + esac + + return 0 +} + +main "$@" || exit $? diff --git a/src/scripts/pakfire-builder.in b/src/scripts/pakfire-builder.in index 8740512e8..da9c3fcdb 100644 --- a/src/scripts/pakfire-builder.in +++ b/src/scripts/pakfire-builder.in @@ -90,6 +90,16 @@ class Cli(object): extract.add_argument("--path", help=_("Extract the archive into this path")) extract.set_defaults(func=self._extract) + # image + image = subparsers.add_parser("image", help=_("Commands to manipulate images")) + image_subparsers = image.add_subparsers() + + # image create + image_create = image_subparsers.add_parser("create", help=_("Create a new image")) + image_create.set_defaults(func=self._image_create) + image_create.add_argument("type", help=_("Image Type")) + image_create.add_argument("path", help=_("Image Path")) + # info info = subparsers.add_parser("info", help=_("Print some information about the given package(s)")) @@ -408,6 +418,18 @@ class Cli(object): except pakfire.errors.CommandExecutionError as e: return e.args[0] + # Images + + def _image_create(self, ns): + """ + Creates a new image + """ + # Setup Pakfire + p = self.pakfire(ns) + + # Run mkimage() + p.mkimage(type=ns.type, path=ns.path) + if __name__ == "__main__": c = Cli()