From: Michael Tremer Date: Thu, 9 Dec 2021 12:23:33 +0000 (+0000) Subject: Make pakfire non-interactive by default X-Git-Tag: 0.9.28~836 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=135aec29004d5bee2dc3cab01e39761e94e20694;p=pakfire.git Make pakfire non-interactive by default This feels a lot more logical in the code. Most of the time Pakfire will be used in a non-interactive mode and therefore making it optional is the better choice. Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 8320bdd73..93690a641 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -155,18 +155,19 @@ ERROR: } static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { - char* kwlist[] = { "path", "arch", "logger", "offline", "conf", "build", + char* kwlist[] = { "path", "arch", "logger", "interactive", "offline", "conf", "build", "enable_ccache", "enable_snapshot", "status_callback", "progress_callback", NULL }; const char* path = NULL; const char* arch = NULL; const char* conf = NULL; + int interactive = 0; int offline = 0; int build = 0; int enable_ccache = 1; int enable_snapshot = 1; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzOpzpppOO", kwlist, - &path, &arch, &self->callbacks.log, &offline, &conf, &build, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzOppzpppOO", kwlist, + &path, &arch, &self->callbacks.log, &interactive, &offline, &conf, &build, &enable_ccache, &enable_snapshot, &self->callbacks.status, &self->callbacks.progress)) return -1; @@ -191,6 +192,10 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { int flags = 0; + // Enable interactive mode + if (interactive) + flags |= PAKFIRE_FLAGS_INTERACTIVE; + // Enable offline mode if (offline) flags |= PAKFIRE_FLAGS_OFFLINE; diff --git a/src/libpakfire/archive.c b/src/libpakfire/archive.c index 73f84fc49..c72f73206 100644 --- a/src/libpakfire/archive.c +++ b/src/libpakfire/archive.c @@ -866,7 +866,7 @@ PAKFIRE_EXPORT int pakfire_archive_extract(struct pakfire_archive* archive, cons DEBUG(archive->pakfire, "Extracting %s to %s\n", archive->path, path); // Create a progressbar - if (!pakfire_has_flag(archive->pakfire, PAKFIRE_FLAGS_NON_INTERACTIVE)) { + if (pakfire_has_flag(archive->pakfire, PAKFIRE_FLAGS_INTERACTIVE)) { r = pakfire_archive_extract_progressbar(archive, &progressbar); if (r) goto ERROR; diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index 47bd89ead..52ee69b11 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -43,8 +43,8 @@ enum pakfire_digests { #include enum pakfire_flags { - PAKFIRE_FLAGS_OFFLINE = (1 << 0), - PAKFIRE_FLAGS_NON_INTERACTIVE = (1 << 1), + PAKFIRE_FLAGS_INTERACTIVE = (1 << 0), + PAKFIRE_FLAGS_OFFLINE = (1 << 1), PAKFIRE_FLAGS_BUILD = (1 << 2), PAKFIRE_FLAGS_DISABLE_CCACHE = (1 << 3), PAKFIRE_FLAGS_DISABLE_SNAPSHOT = (1 << 4), diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index e6a182184..522c08903 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -933,11 +933,11 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path, DEBUG(p, " path = %s\n", pakfire_get_path(p)); // Automatically disable interactive mode - if (!pakfire_has_flag(p, PAKFIRE_FLAGS_NON_INTERACTIVE)) { + if (pakfire_has_flag(p, PAKFIRE_FLAGS_INTERACTIVE)) { if (pakfire_tty_is_noninteractive()) { DEBUG(p, "Interactive mode disabled\n"); - flags |= PAKFIRE_FLAGS_NON_INTERACTIVE; + flags &= ~PAKFIRE_FLAGS_INTERACTIVE; } } @@ -1021,7 +1021,7 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path, // Setup build stuff if (pakfire_has_flag(p, PAKFIRE_FLAGS_BUILD)) { // Builds are never interactive - p->flags |= PAKFIRE_FLAGS_NON_INTERACTIVE; + p->flags &= ~PAKFIRE_FLAGS_INTERACTIVE; } *pakfire = p; diff --git a/src/libpakfire/transaction.c b/src/libpakfire/transaction.c index 484490587..7ceb5de1e 100644 --- a/src/libpakfire/transaction.c +++ b/src/libpakfire/transaction.c @@ -1223,7 +1223,7 @@ PAKFIRE_EXPORT int pakfire_transaction_run(struct pakfire_transaction* transacti char* dump = pakfire_transaction_dump(transaction, 80); // Check if we should continue - if (!pakfire_has_flag(transaction->pakfire, PAKFIRE_FLAGS_NON_INTERACTIVE)) { + if (pakfire_has_flag(transaction->pakfire, PAKFIRE_FLAGS_INTERACTIVE)) { r = pakfire_ui_confirm(transaction->pakfire, dump, _("Is this okay? [y/N]")); if (r) { ERROR(transaction->pakfire, "Transaction aborted upon user request\n"); diff --git a/src/libpakfire/ui.c b/src/libpakfire/ui.c index 22f25cc1b..96f43054b 100644 --- a/src/libpakfire/ui.c +++ b/src/libpakfire/ui.c @@ -32,7 +32,7 @@ int pakfire_ui_confirm(struct pakfire* pakfire, const char* message, const char* printf("%s\n", message); // Skip this, if running in non-interactive mode - if (pakfire_has_flag(pakfire, PAKFIRE_FLAGS_NON_INTERACTIVE)) + if (!pakfire_has_flag(pakfire, PAKFIRE_FLAGS_INTERACTIVE)) return 0; char* line = NULL; @@ -81,7 +81,7 @@ END: static int pakfire_ui_enter_number(struct pakfire* pakfire, const char* question, unsigned int* choice, unsigned int min, unsigned int max) { // Skip this, if running in non-interactive mode - if (pakfire_has_flag(pakfire, PAKFIRE_FLAGS_NON_INTERACTIVE)) + if (!pakfire_has_flag(pakfire, PAKFIRE_FLAGS_INTERACTIVE)) return 0; char* line = NULL; @@ -216,7 +216,7 @@ int pakfire_ui_pick_solution(struct pakfire* pakfire, struct pakfire_request* re } // Skip this, if running in non-interactive mode - if (pakfire_has_flag(pakfire, PAKFIRE_FLAGS_NON_INTERACTIVE)) { + if (!pakfire_has_flag(pakfire, PAKFIRE_FLAGS_INTERACTIVE)) { r = 1; goto ERROR; } diff --git a/src/scripts/pakfire.in b/src/scripts/pakfire.in index fdd21f26a..52a16248a 100644 --- a/src/scripts/pakfire.in +++ b/src/scripts/pakfire.in @@ -248,6 +248,7 @@ class Cli(object): conf=args.config, arch=args.arch, path=args.root, + interactive=True, offline=args.offline, )