]> git.ipfire.org Git - pakfire.git/commitdiff
build: Add scaffolding to create images
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 14 Jun 2023 15:15:50 +0000 (15:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 14 Jun 2023 15:15:50 +0000 (15:15 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/_pakfire/pakfire.c
src/libpakfire/build.c
src/libpakfire/include/pakfire/build.h
src/libpakfire/libpakfire.sym
src/scripts/mkimage [new file with mode: 0644]
src/scripts/pakfire-builder.in

index c78b2f8f667c31fb92955fcc05172259fd3040d7..ee059b3b95d8bc8eb063648e1b23940d4906d8ca 100644 (file)
@@ -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
index a37c80c0f82cfb9e19d57ffe3476403145090a9d..8b1ae63f82e29c3f3f38e0d0d85ed5109e0b7387 100644 (file)
@@ -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,
index f7a020932d767bd2f69cb4a8b68d4494ee352318..9dcdd90bf71da817fbddbf00b6db7acc1ec73dd9 100644 (file)
@@ -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;
index 7f470e1aca47975ef22aa580629b5dfb84037f21..143a2b2fd94de55294dad398209891aaafaa4524 100644 (file)
@@ -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);
index 0a0093b18968f9c75111d00a48c72973fef59e97..eb16a54d28022a9d41ab0ae3eeedb863191476fb 100644 (file)
@@ -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 (file)
index 0000000..e56ae16
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+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 $?
index 8740512e8b0b1cd3da0896ea6fdd5b40fd2a009b..da9c3fcdb774d5308fa302a6650f601d33062e13 100644 (file)
@@ -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()