Logging: suppress "Info" prints when calling bpy.ops.* in quiet mode
This commit is contained in:
@@ -42,11 +42,25 @@ short BPy_reports_to_error(ReportList *reports, PyObject *exception, const bool
|
||||
|
||||
void BPy_reports_write_stdout(const ReportList *reports, const char *header)
|
||||
{
|
||||
const Report *report;
|
||||
for (report = static_cast<const Report *>(reports->list.first); report; report = report->next) {
|
||||
if (report->type < reports->printlevel) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (report == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (header) {
|
||||
PySys_WriteStdout("%s\n", header);
|
||||
}
|
||||
|
||||
LISTBASE_FOREACH (const Report *, report, &reports->list) {
|
||||
for (; report; report = report->next) {
|
||||
if (report->type < reports->printlevel) {
|
||||
continue;
|
||||
}
|
||||
PySys_WriteStdout("%s: %s\n", report->typestr, report->message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include "BLI_ghash.h"
|
||||
|
||||
#include "BKE_context.hh"
|
||||
#include "BKE_global.hh"
|
||||
#include "BKE_report.hh"
|
||||
|
||||
/* so operators called can spawn threads which acquire the GIL */
|
||||
@@ -258,7 +259,11 @@ static PyObject *pyop_call(PyObject * /*self*/, PyObject *args)
|
||||
|
||||
/* operator output is nice to have in the terminal/console too */
|
||||
if (!BLI_listbase_is_empty(&reports->list)) {
|
||||
/* Restore the print level as this is owned by the operator now. */
|
||||
eReportType level = eReportType(reports->printlevel);
|
||||
BKE_report_print_level_set(reports, G.quiet ? RPT_WARNING : RPT_DEBUG);
|
||||
BPy_reports_write_stdout(reports, nullptr);
|
||||
BKE_report_print_level_set(reports, level);
|
||||
}
|
||||
|
||||
BKE_reports_clear(reports);
|
||||
|
||||
@@ -9235,6 +9235,7 @@ static PyObject *pyrna_register_class(PyObject * /*self*/, PyObject *py_class)
|
||||
if (!BLI_listbase_is_empty(&reports.list)) {
|
||||
const bool has_error = (BPy_reports_to_error(&reports, PyExc_RuntimeError, false) == -1);
|
||||
if (!has_error) {
|
||||
BKE_report_print_level_set(&reports, G.quiet ? RPT_WARNING : RPT_DEBUG);
|
||||
BPy_reports_write_stdout(&reports, error_prefix);
|
||||
}
|
||||
if (has_error) {
|
||||
|
||||
@@ -436,6 +436,7 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
|
||||
BKE_reports_free(&reports);
|
||||
return nullptr;
|
||||
}
|
||||
BKE_report_print_level_set(&reports, G.quiet ? RPT_WARNING : RPT_DEBUG);
|
||||
BPy_reports_write_stdout(&reports, nullptr);
|
||||
BKE_reports_free(&reports);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user