deps/obs-scripting: Fix script_log in python to append newline

This commit is contained in:
jp9000 2018-01-19 11:10:45 -08:00
parent 1c3f18a75a
commit 3259269c99

View file

@ -35,12 +35,12 @@ import os\n\
import obspython\n\
class stdout_logger(object):\n\
def write(self, message):\n\
obspython.script_log(obspython.LOG_INFO, message)\n\
obspython.script_log_no_endl(obspython.LOG_INFO, message)\n\
def flush(self):\n\
pass\n\
class stderr_logger(object):\n\
def write(self, message):\n\
obspython.script_log(obspython.LOG_ERROR, message)\n\
obspython.script_log_no_endl(obspython.LOG_ERROR, message)\n\
def flush(self):\n\
pass\n\
os.environ['PYTHONUNBUFFERED'] = '1'\n\
@ -1164,7 +1164,8 @@ static PyObject *sceneitem_list_release(PyObject *self, PyObject *args)
struct dstr cur_py_log_chunk = {0};
static PyObject *py_script_log(PyObject *self, PyObject *args)
static PyObject *py_script_log_internal(PyObject *self, PyObject *args,
bool add_endl)
{
static bool calling_self = false;
int log_level;
@ -1184,6 +1185,8 @@ static PyObject *py_script_log(PyObject *self, PyObject *args)
goto fail;
dstr_cat(&cur_py_log_chunk, msg);
if (add_endl)
dstr_cat(&cur_py_log_chunk, "\n");
const char *start = cur_py_log_chunk.array;
char *endl = strchr(start, '\n');
@ -1210,6 +1213,16 @@ fail:
return python_none();
}
static PyObject *py_script_log_no_endl(PyObject *self, PyObject *args)
{
return py_script_log_internal(self, args, false);
}
static PyObject *py_script_log(PyObject *self, PyObject *args)
{
return py_script_log_internal(self, args, true);
}
/* -------------------------------------------- */
static void add_hook_functions(PyObject *module)
@ -1217,6 +1230,7 @@ static void add_hook_functions(PyObject *module)
static PyMethodDef funcs[] = {
#define DEF_FUNC(n, c) {n, c, METH_VARARGS, NULL}
DEF_FUNC("script_log_no_endl", py_script_log_no_endl),
DEF_FUNC("script_log", py_script_log),
DEF_FUNC("timer_remove", timer_remove),
DEF_FUNC("timer_add", timer_add),