# Some test data to run tests
EXTRA_DIST += \
+ tests/pakfire.conf \
+ \
tests/data/726D8B0B0889B04E.key \
tests/data/beep-1.3-2.ip3.x86_64.pfm \
\
AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir"])
+AC_DEFINE_UNQUOTED([PAKFIRE_CONFIG_PATH], ["${sysconfdir}/${PACKAGE_NAME}"],
+ [The path where Pakfire stores configuration files])
AC_DEFINE_UNQUOTED([PAKFIRE_CACHE_PATH], ["/var/cache/${PACKAGE_NAME}"],
[The path where Pakfire stores temporary data])
AC_DEFINE_UNQUOTED([PAKFIRE_PRIVATE_DIR], ["/var/lib/${PACKAGE_NAME}"],
}
static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) {
- char* kwlist[] = { "path", "arch", "offline", NULL };
+ char* kwlist[] = { "path", "arch", "offline", "conf", NULL };
const char* path = NULL;
const char* arch = NULL;
+ const char* conf = NULL;
int offline = 0;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzp", kwlist, &path, &arch, &offline))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzpz", kwlist,
+ &path, &arch, &offline, &conf))
return -1;
// Create a new Pakfire instance
- int r = pakfire_create(&self->pakfire, path, arch);
+ int r = pakfire_create(&self->pakfire, path, arch, conf);
if (r) {
switch (errno) {
// Invalid architecture or path
#include <pakfire/parser.h>
#include <pakfire/types.h>
-int pakfire_create(Pakfire* pakfire, const char* path, const char* arch);
+int pakfire_create(Pakfire* pakfire, const char* path, const char* arch, const char* conf);
Pakfire pakfire_ref(Pakfire pakfire);
Pakfire pakfire_unref(Pakfire pakfire);
return 0;
}
+static int pakfire_read_config(Pakfire pakfire, const char* path) {
+ char* default_path = NULL;
+
+ // Use default path if none set
+ if (!path) {
+ default_path = pakfire_make_path(pakfire, PAKFIRE_CONFIG_PATH "/general.conf");
+ if (!default_path)
+ return 1;
+
+ path = default_path;
+ }
+
+ DEBUG(pakfire, "Reading configuration from %s\n", path);
+
+ FILE* f = fopen(path, "r");
+ if (!f) {
+ // Silently ignore when there is no default configuration file
+ if (default_path && errno == ENOENT)
+ return 0;
+
+ return 1;
+ }
+
+ // Read configuration from file
+ int r = pakfire_config_read(pakfire->config, f);
+ if (r)
+ goto ERROR;
+
+ERROR:
+ fclose(f);
+
+ if (default_path)
+ free(default_path);
+
+ return r;
+}
+
static int pakfire_read_os_release(Pakfire pakfire) {
char* line = NULL;
size_t l = 0;
return r;
}
-PAKFIRE_EXPORT int pakfire_create(Pakfire* pakfire, const char* path, const char* arch) {
+PAKFIRE_EXPORT int pakfire_create(
+ Pakfire* pakfire, const char* path, const char* arch, const char* conf) {
char tempdir[PATH_MAX] = PAKFIRE_PRIVATE_DIR "/tmp/XXXXXX";
int r = 1;
if (r)
goto ERROR;
+ // Read configuration file
+ r = pakfire_read_config(p, conf);
+ if (r)
+ goto ERROR;
+
// Set cache path
snprintf(p->cache_path, sizeof(p->cache_path) - 1,
"%s/%s/%s", PAKFIRE_CACHE_PATH, p->distro.id, p->distro.version_id);
--- /dev/null
+# This is the configuration file for the test environment
LOG("running %s (%s)\n", t->name, root);
// Create a pakfire instance
- r = pakfire_create(&t->pakfire, root, NULL);
+ r = pakfire_create(&t->pakfire, root, NULL, TEST_SRC_PATH "/pakfire.conf");
if (r) {
LOG("ERROR: Could not initialize Pakfire: %s\n", strerror(errno));
exit(1);