[gnumeric] Introspection: make sure plugins get loaded
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Introspection: make sure plugins get loaded
- Date: Sat, 14 Apr 2018 03:25:02 +0000 (UTC)
commit 9d5b33dffb659162d8d02b865c0b56899321dc6c
Author: Morten Welinder <terra gnome org>
Date: Fri Apr 13 23:24:28 2018 -0400
Introspection: make sure plugins get loaded
README-introspection | 32 ++++++++++++++++++++++++++-
src/gutils.c | 11 +++++++++
src/libgnumeric.c | 3 ++
test/Makefile.am | 3 +-
test/t3001-introspection-simple.py | 8 ++++++
test/t3002-introspection-io.py | 9 ++++++-
test/t3003-introspection-plugins.pl | 22 ++++++++++++++++++
test/t3003-introspection-plugins.py | 41 +++++++++++++++++++++++++++++++++++
8 files changed, 126 insertions(+), 3 deletions(-)
---
diff --git a/README-introspection b/README-introspection
index 7843bc5..3a2bd50 100644
--- a/README-introspection
+++ b/README-introspection
@@ -261,13 +261,43 @@ GOFileSaver: [GObject]
for_file_name(filename_or_uri)
for_mime_type(mimetype)
for_id(saverid)
+ props.id,
+ props.mime_type
+ props.extension
+ props.description
+ props.overwrite
+ props.interactive_only
+ props.format_level
+ props.scope
+
+
+GOFileOpener: [GObject]
+ get_suffixes()
+ get_mimes()
+ props.id,
+ props.description
+ props.interactive_only
+
+
+GOFileFormatLevel: [Enum]
+ NONE
+ WRITE_ONLY
+ NEW
+ MANUAL
+ MANUAL_REMEMBER
+ AUTO
+ LAST
+
Gnm (i.e., not in a class):
clipboard_copy_range(sheet,range)
+ plugins_init(cmdctx)
+
GOffice (i.e., not in a class):
filename_to_uri(filename)
-
+ get_file_savers()
+ get_file_openers()
diff --git a/src/gutils.c b/src/gutils.c
index fd1337a..b7cf2ba 100644
--- a/src/gutils.c
+++ b/src/gutils.c
@@ -68,10 +68,19 @@ running_in_tree (void)
return FALSE;
}
+static gboolean gutils_inited = FALSE;
+
void
gutils_init (void)
{
char const *home_dir;
+
+ // This function will end up being called twice in normal operation:
+ // once from gnm_pre_parse_init and once from gnm_init. Introspection
+ // will not get the first.
+ if (gutils_inited)
+ return;
+
#ifdef G_OS_WIN32
gchar *dir = g_win32_get_package_installation_directory_of_module (NULL);
gnumeric_lib_dir = g_build_filename (dir, "lib",
@@ -114,6 +123,8 @@ gutils_init (void)
gnumeric_usr_dir = gnumeric_usr_dir_unversioned
? g_build_filename (gnumeric_usr_dir_unversioned, GNM_VERSION_FULL, NULL)
: NULL;
+
+ gutils_inited = TRUE;
}
void
diff --git a/src/libgnumeric.c b/src/libgnumeric.c
index da5ae5c..eac55e0 100644
--- a/src/libgnumeric.c
+++ b/src/libgnumeric.c
@@ -289,6 +289,9 @@ gnm_init (void)
return;
inited = TRUE;
+ // Might be duplicate call, but that's ok
+ gutils_init ();
+
libgoffice_init ();
_gnm_register_resource ();
if (gdk_screen_get_default ()) {
diff --git a/test/Makefile.am b/test/Makefile.am
index ce20a32..b45dc19 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -182,7 +182,8 @@ SUPPS = common.supp gui.supp t8003-valgrind-pdf.supp
INTROSPECTION_TSTS = \
t3000-introspection-basic.pl \
t3001-introspection-simple.pl \
- t3002-introspection-io.pl
+ t3002-introspection-io.pl \
+ t3003-introspection-plugins.pl
INTROSPECTION_SUPPS = \
$(INTROSPECTION_TSTS:.pl=.py)
diff --git a/test/t3001-introspection-simple.py b/test/t3001-introspection-simple.py
index db9795d..d2e4f90 100755
--- a/test/t3001-introspection-simple.py
+++ b/test/t3001-introspection-simple.py
@@ -6,6 +6,14 @@ gi.require_version('Gnm', '1.12')
from gi.repository import Gnm
Gnm.init()
+# A context for reporting errors to stderr
+cc = Gnm.CmdContextStderr.new()
+
+# Load plugins
+Gnm.plugins_init(cc)
+
+# -----------------------------------------------------------------------------
+
# Create a workbook with one sheet
wb = Gnm.Workbook.new_with_sheets(1)
diff --git a/test/t3002-introspection-io.py b/test/t3002-introspection-io.py
index a232bf2..e4dc522 100755
--- a/test/t3002-introspection-io.py
+++ b/test/t3002-introspection-io.py
@@ -12,7 +12,14 @@ import sys
src_uri = GOffice.filename_to_uri (sys.argv[1])
dst_uri = GOffice.filename_to_uri (sys.argv[2])
-ioc = GOffice.IOContext.new (Gnm.CmdContextStderr.new ())
+# A context for reporting errors to stderr
+cc = Gnm.CmdContextStderr.new()
+
+# Load plugins
+Gnm.plugins_init(cc)
+
+# A context for io operations
+ioc = GOffice.IOContext.new (cc)
# Read a file
wbv = Gnm.WorkbookView.new_from_uri (src_uri, None, ioc, None)
diff --git a/test/t3003-introspection-plugins.pl b/test/t3003-introspection-plugins.pl
new file mode 100755
index 0000000..175c36e
--- /dev/null
+++ b/test/t3003-introspection-plugins.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/perl -w
+# -----------------------------------------------------------------------------
+
+use strict;
+use lib ($0 =~ m|^(.*/)| ? $1 : ".");
+use GnumericTest;
+
+&setup_python_environment ();
+
+my $python_script = $0;
+$python_script =~ s/\.pl$/.py/;
+&test_command ($PYTHON . ' ' . &GnumericTest::quotearg ($python_script),
+ sub {
+ return (# A few important savers
+ /^Saver ID: Gnumeric_Excel:xlsx$/m &&
+ /^Saver ID: Gnumeric_stf:stf_csv$/m &&
+ /^Saver ID: Gnumeric_XmlIO:sax$/m &&
+ /^Saver ID: Gnumeric_pdf:pdf_assistant$/m &&
+ # A few important loaders
+ /^Loader ID: Gnumeric_Excel:xlsx$/m &&
+ /^Loader ID: Gnumeric_OpenCalc:openoffice$/m);
+ });
diff --git a/test/t3003-introspection-plugins.py b/test/t3003-introspection-plugins.py
new file mode 100755
index 0000000..98159ce
--- /dev/null
+++ b/test/t3003-introspection-plugins.py
@@ -0,0 +1,41 @@
+#!/usr/bin/python
+# -----------------------------------------------------------------------------
+
+import gi
+gi.require_version('Gnm', '1.12')
+gi.require_version('GOffice', '0.10')
+from gi.repository import Gnm
+from gi.repository import GOffice
+Gnm.init()
+
+# A context for reporting errors to stderr
+cc = Gnm.CmdContextStderr.new ()
+
+# Load plugins
+Gnm.plugins_init(cc)
+
+# -----------------------------------------------------------------------------
+
+print("Savers available:")
+for fs in GOffice.get_file_savers():
+ print("Saver ID: {}".format(fs.props.id))
+ print(" Descripton: {}".format(fs.props.description))
+ print(" Mime type: {}".format(fs.props.mime_type))
+ print(" Extension: {}".format(fs.props.extension))
+ print(" Overwrite: {}".format(fs.props.overwrite))
+ print(" Interactive-only: {}".format(fs.props.interactive_only))
+ print(" Format level: {}".format(fs.props.format_level))
+print("")
+
+# -----------------------------------------------------------------------------
+
+print("Loaders available:")
+for fo in GOffice.get_file_openers():
+ print("Loader ID: {}".format(fo.props.id))
+ print(" Descripton: {}".format(fo.props.description))
+ print(" Suffixes: {}".format(", ".join (fo.get_suffixes())))
+ print(" Mime types: {}".format(", ".join (fo.get_mimes())))
+ print(" Interactive-only: {}".format(fo.props.interactive_only))
+print("")
+
+# -----------------------------------------------------------------------------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]