};
struct pakfire_build* build = NULL;
const char* type = NULL;
- const char* path = NULL;
+ PyObject* file = NULL;
+ FILE* f = NULL;
int r;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ss", kwlist, &type, &path))
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO", kwlist, &type, &file))
+ return NULL;
+
+ // Make a file handle out of file
+ f = PyObject_AsFileHandle(file, "w");
+ if (!f)
return NULL;
// Create a new build environment
Py_BEGIN_ALLOW_THREADS
// Run mkimage
- r = pakfire_build_mkimage(build, type, path);
+ r = pakfire_build_mkimage(build, type, f);
if (r) {
Py_BLOCK_THREADS;
ERROR:
if (build)
pakfire_build_unref(build);
+ if (f)
+ fclose(f);
if (r)
return NULL;
}
PAKFIRE_EXPORT int pakfire_build_mkimage(struct pakfire_build* build,
- const char* type, const char* filename) {
+ const char* type, FILE* f) {
+ FILE* t = NULL;
+ char path[PATH_MAX];
int r;
// Check inputs
- if (!type || !filename) {
+ if (!type || !f) {
errno = EINVAL;
return 1;
}
+ // Create a path inside the build environment
+ r = pakfire_path(build->pakfire, path, "%s", PAKFIRE_TMP_DIR "/pakfire-image.XXXXXX");
+ if (r)
+ goto ERROR;
+
+ // Allocate a temporary file
+ t = pakfire_mktemp(path, 0600);
+ if (!t) {
+ ERROR(build->pakfire, "Could not allocate a temporary file: %m\n");
+ r = 1;
+ goto ERROR;
+ }
+
// Initialize the build environment
r = pakfire_build_init(build);
if (r)
goto ERROR;
- // XXX Allocate a temporary file
-
const char* args[] = {
type,
- // XXX tempfile
+ pakfire_relpath(build->pakfire, path),
NULL,
};
if (r)
goto ERROR;
+ // Copy data to its destination
+ r = pakfire_copy(build->pakfire, t, f);
+ if (r)
+ goto ERROR;
+
ERROR:
- // XXX remove the tempfile
+ // Unlink the temporary file
+ if (*path)
+ unlink(path);
return r;
}
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);
+ const char* type, FILE* f);
int pakfire_build_clean(struct pakfire* pakfire, int flags);
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"))
+ image_create.add_argument("path", help=_("Image Path"), type=argparse.FileType("w"))
# info
info = subparsers.add_parser("info",