[geany/geany-plugins] 10e2c7: Sync with latest upstream
Matthew Brush
git-noreply at xxxxx
Fri Feb 17 05:40:53 UTC 2017
Branch: refs/heads/master
Author: Matthew Brush <mbrush at codebrainz.ca>
Committer: Matthew Brush <mbrush at codebrainz.ca>
Date: Fri, 17 Feb 2017 05:40:53 UTC
Commit: 10e2c7ef4c7868055735675d705989972fd221d1
https://github.com/geany/geany-plugins/commit/10e2c7ef4c7868055735675d705989972fd221d1
Log Message:
-----------
Sync with latest upstream
Closes #526
Modified Paths:
--------------
geanypy/geany/Makefile.am
geanypy/geany/__init__.py
geanypy/geany/logger.py
geanypy/geany/plugin.py
geanypy/src/Makefile.am
geanypy/src/geanypy-app.c
geanypy/src/geanypy-document.c
geanypy/src/geanypy-editor.c
geanypy/src/geanypy-glog.c
geanypy/src/geanypy-plugin.c
geanypy/src/makefile.win32
Modified: geanypy/geany/Makefile.am
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -1,5 +1,6 @@
geanypy_sources = __init__.py \
console.py \
+ logger.py \
plugin.py \
signalmanager.py
geanypy_objects = $(geanypy_sources:.py=.pyc)
Modified: geanypy/geany/__init__.py
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -15,6 +15,7 @@
import encoding
import filetypes
import highlighting
+import glog
import main
import msgwindow
import navqueue
@@ -42,6 +43,7 @@
"main_widgets",
"interface_prefs",
"app",
+ "glog",
"keybindings",
"general_prefs",
"search_prefs",
Modified: geanypy/geany/logger.py
74 lines changed, 74 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,74 @@
+# -*- coding: utf-8 -*-
+
+from geany import glog
+from traceback import format_exception
+import logging
+import sys
+
+
+GLIB_LOG_LEVEL_MAP = {
+ logging.DEBUG: glog.LOG_LEVEL_DEBUG,
+ logging.INFO: glog.LOG_LEVEL_INFO,
+ logging.WARNING: glog.LOG_LEVEL_WARNING,
+ # error and critical levels are swapped on purpose because
+ # GLib interprets CRITICAL less fatal than Python and additionally
+ # GLib abort()s the program on G_LOG_LEVEL_ERROR which is uncommon
+ # in Python
+ logging.ERROR: glog.LOG_LEVEL_CRITICAL,
+ logging.CRITICAL: glog.LOG_LEVEL_ERROR,
+}
+
+
+class PluginLogger(object):
+ """
+ Convenience wrapper softly emulating Python's logging interface.
+ Any log messages are passed to the GLib log system using g_log()
+ and the LOG_DOMAIN is set automatically to the plugin's name for convenience.
+ """
+
+ def __init__(self, plugin_name):
+ self._log_domain = u'geanypy-%s' % plugin_name
+
+ def debug(self, msg_format, *args, **kwargs):
+ self.log(logging.DEBUG, msg_format, *args, **kwargs)
+
+ def info(self, msg_format, *args, **kwargs):
+ self.log(logging.INFO, msg_format, *args, **kwargs)
+
+ def message(self, msg_format, *args, **kwargs):
+ self.log(glog.LOG_LEVEL_MESSAGE, msg_format, *args, **kwargs)
+
+ def warning(self, msg_format, *args, **kwargs):
+ self.log(logging.WARNING, msg_format, *args, **kwargs)
+
+ def error(self, msg_format, *args, **kwargs):
+ self.log(logging.ERROR, msg_format, *args, **kwargs)
+
+ def exception(self, msg_format, *args, **kwargs):
+ kwargs['exc_info'] = True
+ self.error(msg_format, *args, **kwargs)
+
+ def critical(self, msg_format, *args, **kwargs):
+ self.log(logging.CRITICAL, msg_format, *args, **kwargs)
+
+ warn = warning
+ fatal = critical
+
+ def log(self, level, msg_format, *args, **kwargs):
+ # map log level from Python to GLib
+ glib_log_level = GLIB_LOG_LEVEL_MAP.get(level, glog.LOG_LEVEL_MESSAGE)
+ # format message
+ log_message = msg_format % args
+ # log exception information if requested
+ exc_info = kwargs.get('exc_info', False)
+ if exc_info:
+ traceback_text = self._format_exception(exc_info)
+ log_message = '%s\n%s' % (log_message, traceback_text)
+
+ glog.glog(self._log_domain, glib_log_level, log_message)
+
+ def _format_exception(self, exc_info):
+ if not isinstance(exc_info, tuple):
+ exc_info = sys.exc_info()
+ exc_text_lines = format_exception(*exc_info)
+ return ''.join(exc_text_lines)
Modified: geanypy/geany/plugin.py
4 lines changed, 3 insertions(+), 1 deletions(-)
===================================================================
@@ -35,6 +35,8 @@ def cleanup(self):
~/.config/geany/plugins). Only files with a `.py` extension will be loaded.
"""
+
+from geany.logger import PluginLogger
import keybindings
class Plugin(object):
@@ -60,7 +62,7 @@ def __init__(self):
When the plugin is loaded its __init__() function will be called
so that's a good place to put plugin initialization code.
"""
-
+ self.logger = PluginLogger(self.name)
def cleanup(self):
Modified: geanypy/src/Makefile.am
7 lines changed, 4 insertions(+), 3 deletions(-)
===================================================================
@@ -5,11 +5,11 @@ geanyplugin_LTLIBRARIES = geanypy.la
geanyplugindir = $(libdir)/geany
geanypy_la_LDFLAGS = -module -avoid-version -Wl,--export-dynamic
-geanypy_la_CPPFLAGS = @GEANY_CFLAGS@ @PYGTK_CFLAGS@ @PYTHON_CPPFLAGS@ \
+geanypy_la_CPPFLAGS = @PYTHON_CPPFLAGS@ \
-DGEANYPY_PYTHON_DIR="\"$(libdir)/geany/geanypy\"" \
-DGEANYPY_PLUGIN_DIR="\"$(libdir)/geany\"" \
-DG_LOG_DOMAIN=\"GeanyPy\"
-geanypy_la_CFLAGS = @GEANYPY_CFLAGS@ @GMODULE_CFLAGS@
+geanypy_la_CFLAGS = @PYGTK_CFLAGS@ @GEANY_CFLAGS@ @GEANYPY_CFLAGS@ @GMODULE_CFLAGS@
geanypy_la_LIBADD = @GEANY_LIBS@ @PYGTK_LIBS@ \
$(PYTHON_LDFLAGS) $(PYTHON_LIBS) \
@PYTHON_EXTRA_LIBS@ @PYTHON_EXTRA_LDFLAGS@ \
@@ -20,11 +20,12 @@ geanypy_la_SOURCES = geanypy-app.c \
geanypy-editor.c geanypy-editor.h \
geanypy-encoding.c geanypy-encoding.h \
geanypy-filetypes.c geanypy-filetypes.h \
+ geanypy-glog.c \
geanypy.h \
geanypy-highlighting.c \
geanypy-indentprefs.c \
geanypy-interfaceprefs.c \
- geanypy-keybindings.c geanypy-keybindings.h\
+ geanypy-keybindings.c geanypy-keybindings.h \
geanypy-main.c \
geanypy-mainwidgets.c \
geanypy-msgwindow.c \
Modified: geanypy/src/geanypy-app.c
1 lines changed, 0 insertions(+), 1 deletions(-)
===================================================================
@@ -4,7 +4,6 @@
#include "geanypy.h"
-
typedef struct
{
PyObject_HEAD
Modified: geanypy/src/geanypy-document.c
4 lines changed, 2 insertions(+), 2 deletions(-)
===================================================================
@@ -118,9 +118,9 @@ Document_get_property(Document *self, const gchar *prop_name)
else if (g_str_equal(prop_name, "text_changed"))
{
if (self->doc->changed)
- Py_RETURN_NONE;
+ Py_RETURN_TRUE;
else
- Py_RETURN_NONE;
+ Py_RETURN_FALSE;
}
Py_RETURN_NONE;
Modified: geanypy/src/geanypy-editor.c
4 lines changed, 2 insertions(+), 2 deletions(-)
===================================================================
@@ -62,7 +62,7 @@ Editor_get_property(Editor *self, const gchar *prop_name)
PyObject *py_doc;
py_doc = (PyObject *) Document_create_new_from_geany_document(
self->editor->document);
- if (py_doc && py_doc != Py_None)
+ if (!py_doc || py_doc == Py_None)
Py_RETURN_NONE;
return py_doc;
}
@@ -296,7 +296,7 @@ static PyMethodDef Editor_methods[] = {
{ "indicator_set_on_range", (PyCFunction) Editor_indicator_set_on_range, METH_KEYWORDS,
"Sets an indicator on the range specified." },
{ "insert_snippet", (PyCFunction) Editor_insert_snippet, METH_KEYWORDS,
- "Replces all special sequences in snippet and inserts it at "
+ "Replaces all special sequences in snippet and inserts it at "
"the specified position." },
{ "insert_text_block", (PyCFunction) Editor_insert_text_block, METH_KEYWORDS,
"Inserts text, replacing tab chars and newline chars accordingly "
Modified: geanypy/src/geanypy-glog.c
45 lines changed, 45 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,45 @@
+#if defined(HAVE_CONFIG_H) && !defined(GEANYPY_WINDOWS)
+# include "config.h"
+#endif
+
+#include "geanypy.h"
+
+
+static PyObject *
+Glog_glog(PyObject *module, PyObject *args, PyObject *kwargs)
+{
+ static gchar *kwlist[] = { "log_domain", "log_level", "message", NULL };
+ gchar *log_domain, *message;
+ GLogLevelFlags log_level;
+
+ if (PyArg_ParseTupleAndKeywords(args, kwargs, "sis", kwlist, &log_domain, &log_level, &message))
+ {
+ g_log(log_domain, log_level, "%s", message);
+ }
+ Py_RETURN_NONE;
+}
+
+
+static
+PyMethodDef GlogModule_methods[] = {
+ { "glog", (PyCFunction) Glog_glog, METH_KEYWORDS, "Wrapper around g_log()." },
+ { NULL }
+};
+
+
+PyMODINIT_FUNC initglog(void)
+{
+ PyObject *m;
+
+ m = Py_InitModule3("glog", GlogModule_methods, "GLib Log utility functions.");
+
+ /* TODO: These constants are for the geany.logger.GLIB_LOG_LEVEL_MAP mapping.
+ * It would be better to build this mapping on the C layer but how to
+ * access the Python logging.* level constants here? */
+ PyModule_AddIntConstant(m, "LOG_LEVEL_DEBUG", G_LOG_LEVEL_DEBUG);
+ PyModule_AddIntConstant(m, "LOG_LEVEL_INFO", G_LOG_LEVEL_INFO);
+ PyModule_AddIntConstant(m, "LOG_LEVEL_MESSAGE", G_LOG_LEVEL_MESSAGE);
+ PyModule_AddIntConstant(m, "LOG_LEVEL_WARNING", G_LOG_LEVEL_WARNING);
+ PyModule_AddIntConstant(m, "LOG_LEVEL_ERROR", G_LOG_LEVEL_ERROR);
+ PyModule_AddIntConstant(m, "LOG_LEVEL_CRITICAL", G_LOG_LEVEL_CRITICAL);
+}
Modified: geanypy/src/geanypy-plugin.c
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -40,6 +40,7 @@ PyMODINIT_FUNC initdocument(void);
PyMODINIT_FUNC initeditor(void);
PyMODINIT_FUNC initencoding(void);
PyMODINIT_FUNC initfiletypes(void);
+PyMODINIT_FUNC initglog(void);
PyMODINIT_FUNC inithighlighting(void);
PyMODINIT_FUNC initmain(void);
PyMODINIT_FUNC initmsgwin(void);
@@ -81,6 +82,7 @@ GeanyPy_start_interpreter(void)
initeditor();
initencoding();
initfiletypes();
+ initglog();
inithighlighting();
initmain();
initmsgwin();
Modified: geanypy/src/makefile.win32
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -10,6 +10,7 @@ SOURCES = \
geanypy-highlighting.c \
geanypy-indentprefs.c \
geanypy-interfaceprefs.c \
+ geanypy-log.c \
geanypy-main.c \
geanypy-mainwidgets.c \
geanypy-msgwindow.c \
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Plugins-Commits
mailing list