static PyObject* Pakfire_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
PakfireObject* self = (PakfireObject *)type->tp_alloc(type, 0);
- if (self) {
+ if (self)
self->pakfire = NULL;
- // Callbacks
- self->callbacks.log = NULL;
- self->callbacks.confirm = NULL;
- }
-
return (PyObject *)self;
}
static void Pakfire_dealloc(PakfireObject* self) {
if (self->pakfire) {
- // Reset log callback
- if (self->callbacks.log) {
- pakfire_set_log_callback(self->pakfire, NULL, NULL);
- Py_DECREF(self->callbacks.log);
- }
-
// Reset confirm callback
if (self->callbacks.confirm) {
pakfire_set_confirm_callback(self->pakfire, NULL, NULL);
pakfire_log_null(struct pakfire* pakfire, const char *format, ...) {}
#define pakfire_log_condition(pakfire, prio, r, arg...) \
- do { \
- if (pakfire_log_get_priority(pakfire) >= prio) \
- pakfire_log(pakfire, prio, r, __FILE__, __LINE__, __FUNCTION__, ## arg); \
- } while (0)
+ pakfire_log(pakfire, prio, r, __FILE__, __LINE__, __FUNCTION__, ## arg)
#define INFO(pakfire, arg...) pakfire_log_condition(pakfire, LOG_INFO, 0, ## arg)
#define ERROR(pakfire, arg...) pakfire_log_condition(pakfire, LOG_ERR, 0, ## arg)
};
// Callbacks
-void pakfire_set_log_callback(struct pakfire* pakfire,
- pakfire_log_callback callback, void* data);
typedef int (*pakfire_confirm_callback)(struct pakfire* pakfire, void* data,
const char* message, const char* question);
void pakfire_set_confirm_callback(struct pakfire* pakfire,
int pakfire_search(struct pakfire* pakfire, const char* what, int flags,
struct pakfire_packagelist* list);
-// Logging
-
-int pakfire_log_get_priority(struct pakfire* pakfire);
-void pakfire_log_set_priority(struct pakfire* pakfire, int priority);
-
// Check
int pakfire_check(struct pakfire* pakfire, struct pakfire_filelist* errors);
// Callbacks
struct pakfire_callbacks {
- // Logging
- pakfire_log_callback log;
- void* log_data;
-
// Confirm
pakfire_confirm_callback confirm;
void* confirm_data;
return unmapped_id;
}
-static int log_priority(const char* priority) {
- char* end;
-
- int prio = strtol(priority, &end, 10);
- if (*end == '\0' || isspace(*end))
- return prio;
-
- if (strncmp(priority, "error", strlen("error")) == 0)
- return LOG_ERR;
-
- if (strncmp(priority, "info", strlen("info")) == 0)
- return LOG_INFO;
-
- if (strncmp(priority, "debug", strlen("debug")) == 0)
- return LOG_DEBUG;
-
- return 0;
-}
-
static void pool_log(Pool* pool, void* data, int type, const char* s) {
struct pakfire* pakfire = (struct pakfire*)data;
pakfire_log_callback log_callback, void* log_data) {
char tempdir[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-root-XXXXXX";
char private_dir[PATH_MAX];
- const char* env = NULL;
int r = 1;
// Reset pakfire pointer
p->nrefs = 1;
p->flags = flags;
- // Setup logging
- if (log_callback)
- pakfire_set_log_callback(p, log_callback, log_data);
- else
- pakfire_set_log_callback(p, pakfire_log_syslog, NULL);
-
- // Set log level to debug if in debug mode
- if (pakfire_has_flag(p, PAKFIRE_FLAGS_DEBUG)) {
- pakfire_log_set_priority(p, LOG_DEBUG);
-
- // Otherwise take the log level from the environment
- } else if ((env = secure_getenv("PAKFIRE_LOG"))) {
- pakfire_log_set_priority(p, log_priority(env));
-
- // Otherwise set the log level to INFO
- } else {
- pakfire_log_set_priority(p, LOG_INFO);
- }
-
// Store the nominal architecture
r = pakfire_string_set(p->arches.nominal, arch);
if (r)
// Logging
-PAKFIRE_EXPORT int pakfire_log_get_priority(struct pakfire* pakfire) {
- return pakfire->log_priority;
-}
-
-PAKFIRE_EXPORT void pakfire_log_set_priority(struct pakfire* pakfire, int priority) {
- pakfire->log_priority = priority;
-}
-
-PAKFIRE_EXPORT void pakfire_set_log_callback(struct pakfire* pakfire,
- pakfire_log_callback callback, void* data) {
- pakfire->callbacks.log = callback;
- pakfire->callbacks.log_data = data;
-}
-
// XXX This function is deprecated and needs to be removed
void pakfire_log(struct pakfire* pakfire, int priority, int r,
const char* file, int line, const char* fn, const char* format, ...) {