PyObject* result = PyObject_CallObject(callback, args);
- // Extract return code
- if (PyLong_Check(result))
- r = PyLong_AsLong(result);
+ // If the callback raised an exception, we will ignore it and indicate
+ // that an error happened, but we cannot re-raise the exception
+ if (!result) {
+ r = -1;
+ goto ERROR;
+ }
+ // Set the return code
+ if (result == Py_True)
+ r = 0;
+ else
+ r = 1;
+
+ERROR:
Py_DECREF(args);
Py_DECREF(result);
enum pakfire_transaction_flags {
PAKFIRE_TRANSACTION_DRY_RUN = (1 << 0),
- PAKFIRE_TRANSACTION_INTERACTIVE = (1 << 1),
};
struct pakfire_transaction* pakfire_transaction_ref(struct pakfire_transaction* transaction);
if (!pakfire->callbacks.confirm)
return 0;
- // Skip this, if running in non-interactive mode
-#if 0
- if (!pakfire_has_flag(pakfire, PAKFIRE_FLAGS_INTERACTIVE))
- return 0;
-#endif
-
// Run callback
return pakfire->callbacks.confirm(
pakfire, pakfire->callbacks.confirm_data, message, question);
char* dump = pakfire_transaction_dump(transaction, 80);
// Check if we should continue
- if (flags & PAKFIRE_TRANSACTION_INTERACTIVE) {
- r = pakfire_confirm(transaction->pakfire, dump, _("Is this okay? [y/N]"));
- if (r) {
- ERROR(transaction->pakfire, "Transaction aborted upon user request\n");
- goto ERROR;
- }
+ r = pakfire_confirm(transaction->pakfire, dump, _("Is this okay?"));
+ if (r) {
+ ERROR(transaction->pakfire, "Transaction aborted upon user request\n");
+ goto ERROR;
}
// Write transaction dump to log
path=args.root,
offline=args.offline,
logger=logger.log,
+
+ # Callbacks
+ confirm_callback=self._confirm_callback,
)
# Disable repositories
# Return with exit code
sys.exit(r or 0)
+ def _confirm_callback(self, message, question):
+ """
+ This is called when Pakfire needs a confirmation from the user
+ """
+ if message:
+ print(message)
+
+ while True:
+ # Ask the question and wait for an answer
+ answer = input("%s [y/N] " % question)
+
+ # Positive response
+ if answer in ("y", "Y"):
+ return True
+
+ # Negative response
+ elif answer in ("", "n", "N"):
+ return False
+
def _check(self, p, args):
"""
Checks if this installation is properly intact