示例#1
0
static void
gplp_func_exec_action (GOPluginService *service,
		       GnmAction const *action,
		       WorkbookControl *wbc,
		       GOErrorInfo **ret_error)
{
	ServiceLoaderDataUI *loader_data;
	PyObject *fn, *ret;

	g_return_if_fail (_PyGObject_API != NULL);

	GO_INIT_RET_ERROR_INFO (ret_error);
	loader_data = g_object_get_data (G_OBJECT (service), "loader_data");
	SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service));
	fn = PyDict_GetItemString (loader_data->ui_actions, action->id);
	if (fn == NULL) {
		*ret_error = go_error_info_new_printf (_("Unknown action: %s"),
						    action->id);
		return;
	} else if (!PyCallable_Check (fn)) {
		*ret_error = go_error_info_new_printf (
			_("Not a valid function for action: %s"), action->id);
		return;
	}
	ret = PyObject_CallFunction (fn, (char *) "N",
				     py_new_Gui_object (WBC_GTK (wbc)));
	if (ret == NULL) {
		*ret_error = go_error_info_new_str (py_exc_to_string ());
		PyErr_Clear ();
	} else {
		Py_DECREF (ret);
	}
}
示例#2
0
static void
gplp_load_service_file_opener (GOPluginLoader *loader,
			       GOPluginService *service,
			       GOErrorInfo **ret_error)
{
	printf("gplp_load_service_file_opener(start)\n");

	GnmPythonPluginLoader *loader_python = GNM_PYTHON_PLUGIN_LOADER (loader);
	gchar *func_name_file_probe, *func_name_file_open;
	PyObject *python_func_file_probe, *python_func_file_open;

	g_return_if_fail (GO_IS_PLUGIN_SERVICE_FILE_OPENER (service));

	GO_INIT_RET_ERROR_INFO (ret_error);
	gnm_py_interpreter_switch_to (loader_python->py_interpreter_info);
	gnm_py_interpreter_load(loader_python->py_interpreter_info);	

	func_name_file_probe = g_strconcat (
		go_plugin_service_get_id (service), "_file_probe", NULL);
	python_func_file_probe = PyDict_GetItemString (loader_python->main_module_dict,
	                                               func_name_file_probe);
	gnm_python_clear_error_if_needed (loader_python->py_object);
	func_name_file_open = g_strconcat (
		go_plugin_service_get_id (service), "_file_open", NULL);
	python_func_file_open = PyDict_GetItemString (loader_python->main_module_dict,
	                                              func_name_file_open);
	gnm_python_clear_error_if_needed (loader_python->py_object);
	if (python_func_file_open != NULL) {
		GOPluginServiceFileOpenerCallbacks *cbs;
		ServiceLoaderDataFileOpener *loader_data;

		cbs = go_plugin_service_get_cbs (service);
		cbs->plugin_func_file_probe = gplp_func_file_probe;
		cbs->plugin_func_file_open = gplp_func_file_open;

		loader_data = g_new (ServiceLoaderDataFileOpener, 1);
		loader_data->python_func_file_probe = python_func_file_probe;
		loader_data->python_func_file_open = python_func_file_open;
		if (python_func_file_probe != NULL)
			Py_INCREF (loader_data->python_func_file_probe);
		Py_INCREF (loader_data->python_func_file_open);
		g_object_set_data_full
			(G_OBJECT (service), "loader_data", loader_data,
			 (GDestroyNotify) gplp_loader_data_opener_free);
	} else {
		*ret_error = go_error_info_new_printf (
		             _("Python file \"%s\" has invalid format."),
		             loader_python->module_name);
		go_error_info_add_details (*ret_error,
		                        go_error_info_new_printf (
		                        _("File doesn't contain \"%s\" function."),
		                        func_name_file_open));
	}
	g_free (func_name_file_probe);
	g_free (func_name_file_open);
	gnm_py_interpreter_save(loader_python->py_interpreter_info);
}
示例#3
0
static void
go_plugin_service_file_opener_deactivate (GOPluginService *service,
					  GOErrorInfo **ret_error)
{
	GOPluginServiceFileOpener *service_file_opener = GO_PLUGIN_SERVICE_FILE_OPENER (service);

	GO_INIT_RET_ERROR_INFO (ret_error);
	go_file_opener_unregister (service_file_opener->opener);
	service->is_active = FALSE;
}
示例#4
0
static void
gplp_load_service_function_group (GOPluginLoader *loader,
				  GOPluginService *service,
				  GOErrorInfo **ret_error)
{
	printf("gplp_load_service_function_group(start)\n");

	GnmPythonPluginLoader *loader_python = GNM_PYTHON_PLUGIN_LOADER (loader);
	gchar *fn_info_dict_name;
	PyObject *python_fn_info_dict;

	g_return_if_fail (IS_GNM_PLUGIN_SERVICE_FUNCTION_GROUP (service));

	GO_INIT_RET_ERROR_INFO (ret_error);
	gnm_py_interpreter_switch_to (loader_python->py_interpreter_info);
	gnm_py_interpreter_load(loader_python->py_interpreter_info);	

	fn_info_dict_name = g_strconcat (
		go_plugin_service_get_id (service), "_functions", NULL);
	python_fn_info_dict = PyDict_GetItemString (loader_python->main_module_dict,
	                                             fn_info_dict_name);
	gnm_python_clear_error_if_needed (loader_python->py_object);
	if (python_fn_info_dict != NULL && PyDict_Check (python_fn_info_dict)) {
		PluginServiceFunctionGroupCallbacks *cbs;
		ServiceLoaderDataFunctionGroup *loader_data;

		cbs = go_plugin_service_get_cbs (service);
		cbs->func_desc_load = &gplp_func_desc_load;

		loader_data = g_new (ServiceLoaderDataFunctionGroup, 1);
		loader_data->python_fn_info_dict = (PyObject *) python_fn_info_dict;
		Py_INCREF (loader_data->python_fn_info_dict);
		g_object_set_data_full
			(G_OBJECT (service), "loader_data", loader_data,
			 (GDestroyNotify) gplp_loader_data_fngroup_free);
	} else {
		*ret_error = go_error_info_new_printf (
		             _("Python file \"%s\" has invalid format."),
		             loader_python->module_name);
		if (python_fn_info_dict == NULL) {
			go_error_info_add_details (*ret_error,
			                        go_error_info_new_printf (
			                        _("File doesn't contain \"%s\" dictionary."),
			                        fn_info_dict_name));
		} else if (!PyDict_Check (python_fn_info_dict)) {
			go_error_info_add_details (*ret_error,
			                        go_error_info_new_printf (
			                        _("Object \"%s\" is not a dictionary."),
			                        fn_info_dict_name));
		}
	}
	g_free (fn_info_dict_name);
	gnm_py_interpreter_save(loader_python->py_interpreter_info);	
	printf("gplp_load_service_function_group(end)\n");
}
示例#5
0
static void
go_plugin_service_file_opener_activate (GOPluginService *service,
					GOErrorInfo **ret_error)
{
	GOPluginServiceFileOpener *service_file_opener = GO_PLUGIN_SERVICE_FILE_OPENER (service);

	GO_INIT_RET_ERROR_INFO (ret_error);
	service_file_opener->opener = GO_FILE_OPENER (go_plugin_file_opener_new (service));
	go_file_opener_register (service_file_opener->opener,
				  service_file_opener->priority);
	service->is_active = TRUE;
}
示例#6
0
static void
gplp_unload_base (GOPluginLoader *loader, GOErrorInfo **ret_error)
{
	GnmPythonPluginLoader *loader_python = GNM_PYTHON_PLUGIN_LOADER (loader);
	GOPlugin *plugin = go_plugin_loader_get_plugin (loader);

	GO_INIT_RET_ERROR_INFO (ret_error);
	g_object_steal_data (G_OBJECT (plugin), "python-loader");
	gnm_python_destroy_interpreter (
		loader_python->py_object, loader_python->py_interpreter_info);
	g_object_unref (loader_python->py_object);
}
示例#7
0
static void
go_plugin_service_file_saver_deactivate (GOPluginService *service, GOErrorInfo **ret_error)
{
	GOPluginServiceFileSaver *service_file_saver = GO_PLUGIN_SERVICE_FILE_SAVER (service);
	GHashTable *file_savers_hash;

	GO_INIT_RET_ERROR_INFO (ret_error);
	file_savers_hash = get_plugin_file_savers_hash (service->plugin);
	g_hash_table_remove (file_savers_hash, service->id);
	go_file_saver_unregister (service_file_saver->saver);
	service->is_active = FALSE;
}
示例#8
0
static void
gplp_load_service_ui (GOPluginLoader *loader,
		      GOPluginService *service,
		      GOErrorInfo **ret_error)
{

	GnmPythonPluginLoader *loader_python = GNM_PYTHON_PLUGIN_LOADER (loader);
	gchar *ui_action_names;
	PyObject *ui_actions;

	g_return_if_fail (IS_GNM_PLUGIN_SERVICE_UI (service));

	GO_INIT_RET_ERROR_INFO (ret_error);
	gnm_py_interpreter_switch_to (loader_python->py_interpreter_info);
	gnm_py_interpreter_load(loader_python->py_interpreter_info);	

	ui_action_names = g_strconcat (go_plugin_service_get_id (service),
				     "_ui_actions", NULL);
	ui_actions = PyDict_GetItemString (loader_python->main_module_dict,
					   ui_action_names);
	gnm_python_clear_error_if_needed (loader_python->py_object);
	if (ui_actions != NULL && PyDict_Check (ui_actions)) {
		PluginServiceUICallbacks *cbs;
		ServiceLoaderDataUI *loader_data;

		cbs = go_plugin_service_get_cbs (service);
		cbs->plugin_func_exec_action = gplp_func_exec_action;

		loader_data = g_new (ServiceLoaderDataUI, 1);
		loader_data->ui_actions = ui_actions;
		Py_INCREF (loader_data->ui_actions);
		g_object_set_data_full
			(G_OBJECT (service), "loader_data", loader_data,
			 (GDestroyNotify) gplp_loader_data_ui_free);
	} else {
		*ret_error = go_error_info_new_printf (
		             _("Python file \"%s\" has invalid format."),
		             loader_python->module_name);
		if (ui_actions == NULL) {
			go_error_info_add_details (*ret_error,
			                        go_error_info_new_printf (
			                        _("File doesn't contain \"%s\" dictionary."),
			                        ui_action_names));
		} else if (!PyDict_Check (ui_actions)) {
			go_error_info_add_details (*ret_error,
			                        go_error_info_new_printf (
			                        _("Object \"%s\" is not a dictionary."),
			                        ui_action_names));
		}
	}
	g_free (ui_action_names);
	gnm_py_interpreter_save(loader_python->py_interpreter_info);
}
示例#9
0
void
go_plugin_service_load (GOPluginService *service, GOErrorInfo **ret_error)
{
	g_return_if_fail (GO_IS_PLUGIN_SERVICE (service));

	GO_INIT_RET_ERROR_INFO (ret_error);

	if (service->is_loaded)
		return;
	go_plugin_load_service (service->plugin, service, ret_error);
	if (*ret_error == NULL)
		service->is_loaded = TRUE;
}
示例#10
0
static void
go_plugin_service_plugin_loader_deactivate (GOPluginService *service,
					    GOErrorInfo **ret_error)
{
	gchar *full_id;

	GO_INIT_RET_ERROR_INFO (ret_error);
	full_id = g_strconcat (
		go_plugin_get_id (service->plugin), ":", service->id, NULL);
	go_plugins_unregister_loader (full_id);
	g_free (full_id);
	service->is_active = FALSE;
}
示例#11
0
static void
gplp_load_service_function_group (GOPluginLoader *loader,
				  GOPluginService *service,
				  GOErrorInfo **ret_error)
{
	GnmPluginServiceFunctionGroupCallbacks *cbs;

	g_return_if_fail (GNM_IS_PLUGIN_SERVICE_FUNCTION_GROUP (service));

	GO_INIT_RET_ERROR_INFO (ret_error);

	cbs = go_plugin_service_get_cbs (service);
	cbs->load_stub = &gplp_func_load_stub;
}
示例#12
0
static void
go_plugin_service_file_saver_read_xml (GOPluginService *service, xmlNode *tree, GOErrorInfo **ret_error)
{
	xmlNode *information_node;
	gchar *description;

	GO_INIT_RET_ERROR_INFO (ret_error);
	information_node = go_xml_get_child_by_name (tree, "information");
	if (information_node != NULL) {
		xmlNode *node = go_xml_get_child_by_name_by_lang
			(information_node, "description");
		description = node ? xml2c (xmlNodeGetContent (node)) : NULL;
	} else {
		description = NULL;
	}

	if (description != NULL) {
		int scope = GO_FILE_SAVE_WORKBOOK;
		int level = GO_FILE_FL_WRITE_ONLY;
		GOPluginServiceFileSaver *psfs =
			GO_PLUGIN_SERVICE_FILE_SAVER (service);

		psfs->file_extension =
			xml2c (go_xml_node_get_cstr (tree, "file_extension"));

		psfs->mime_type =
			xml2c (go_xml_node_get_cstr (tree, "mime_type"));

		psfs->description = description;

		(void)go_xml_node_get_enum
			(tree, "format_level",
			 GO_TYPE_FILE_FORMAT_LEVEL, &level);
		psfs->format_level = (GOFileFormatLevel)level;

		if (!go_xml_node_get_int (tree, "default_saver_priority", &(psfs->default_saver_priority)))
			psfs->default_saver_priority = -1;

		(void)go_xml_node_get_enum
			(tree, "save_scope",
			 GO_TYPE_FILE_SAVE_SCOPE, &scope);
		psfs->save_scope = (GOFileSaveScope)scope;

		if (!go_xml_node_get_bool (tree, "overwrite_files", &(psfs->overwrite_files)))
			psfs->overwrite_files = TRUE;
	} else {
		*ret_error = go_error_info_new_str (_("File saver has no description"));
	}
}
示例#13
0
static void
gplp_set_attributes (GOPluginLoader *loader, GHashTable *attrs, GOErrorInfo **ret_error)
{
	GnmPythonPluginLoader *loader_python = GNM_PYTHON_PLUGIN_LOADER (loader);
	gchar *module_name = NULL;

	GO_INIT_RET_ERROR_INFO (ret_error);
	module_name = g_hash_table_lookup (attrs, "module_name");
	if (module_name != NULL) {
		loader_python->module_name = g_strdup (module_name);
	} else {
		*ret_error = go_error_info_new_str (
		             _("Python module name not given."));
	}
}
示例#14
0
static void
gplp_unload_service_function_group (GOPluginLoader *loader,
				    GOPluginService *service,
				    GOErrorInfo **ret_error)
{
	ServiceLoaderDataFunctionGroup *loader_data;

	g_return_if_fail (GNM_IS_PYTHON_PLUGIN_LOADER (loader));
	g_return_if_fail (GNM_IS_PLUGIN_SERVICE_FUNCTION_GROUP (service));

	GO_INIT_RET_ERROR_INFO (ret_error);
	loader_data = g_object_get_data (G_OBJECT (service), "loader_data");
	SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service));
	Py_DECREF (loader_data->python_fn_info_dict);
}
示例#15
0
static void
go_plugin_service_resource_read_xml (GOPluginService *service, xmlNode *tree, GOErrorInfo **ret_error)
{
	GOPluginServiceResource *sr = GO_PLUGIN_SERVICE_RESOURCE (service);
	char *data = NULL;
	gsize length;
	xmlChar *file;

	GO_INIT_RET_ERROR_INFO (ret_error);

	sr->id = xml2c (go_xml_node_get_cstr (tree, "id"));
	if (!sr->id)
		goto error;

	file = go_xml_node_get_cstr (tree, "file");
	if (file) {
		char *absfile;
		gboolean ok;

		if (!g_path_is_absolute (CXML2C (file))) {
			char const *dir = go_plugin_get_dir_name
				(go_plugin_service_get_plugin (service));
			absfile = g_build_filename (dir, CXML2C (file), NULL);
		} else
			absfile = g_strdup (CXML2C (file));
		xmlFree (file);
		ok = g_file_get_contents (absfile, &data, &length, NULL);
		g_free (absfile);

		if (!ok)
			goto error;
	} else {
		data = xml2c (go_xml_node_get_cstr (tree, "data"));
		length = strlen (data);
	}
	if (!data)
		goto error;

	/* No encoding case */
	sr->value = g_string_sized_new (length);
	g_string_append_len (sr->value, data, length);
	g_free (data);
	return;

 error:
	*ret_error = go_error_info_new_str (_("Invalid resource service"));
	g_free (data);
}
示例#16
0
static void
go_plugin_service_general_deactivate (GOPluginService *service, GOErrorInfo **ret_error)
{
	GOPluginServiceGeneral *service_general = GO_PLUGIN_SERVICE_GENERAL (service);
	GOErrorInfo *error = NULL;

	GO_INIT_RET_ERROR_INFO (ret_error);
	g_return_if_fail (service_general->cbs.plugin_func_cleanup != NULL);
	service_general->cbs.plugin_func_cleanup (service, &error);
	if (error != NULL) {
		*ret_error = go_error_info_new_str_with_details (
		             _("Cleanup function inside plugin returned error."),
		             error);
		return;
	}
	service->is_active = FALSE;
}
示例#17
0
GOPluginService *
go_plugin_service_new (GOPlugin *plugin, xmlNode *tree, GOErrorInfo **ret_error)
{
	GOPluginService *service = NULL;
	char *type_str;
	GOErrorInfo *service_error = NULL;
	GOPluginServiceCreate ctor;

	g_return_val_if_fail (GO_IS_PLUGIN (plugin), NULL);
	g_return_val_if_fail (tree != NULL, NULL);
	g_return_val_if_fail (strcmp (tree->name, "service") == 0, NULL);

	GO_INIT_RET_ERROR_INFO (ret_error);
	type_str = go_xml_node_get_cstr (tree, "type");
	if (type_str == NULL) {
		*ret_error = go_error_info_new_str (_("No \"type\" attribute on \"service\" element."));
		return NULL;
	}

	ctor = g_hash_table_lookup (services, type_str);
	if (ctor == NULL) {
		*ret_error = go_error_info_new_printf (_("Unknown service type: %s."), type_str);
		xmlFree (type_str);
		return NULL;
	}
	xmlFree (type_str);

	service = g_object_new (ctor(), NULL);
	service->plugin = plugin;
	service->id = xml2c (go_xml_node_get_cstr (tree, "id"));
	if (service->id == NULL)
		service->id = xmlStrdup ("default");

	if (GO_PLUGIN_SERVICE_GET_CLASS (service)->read_xml != NULL) {
		GO_PLUGIN_SERVICE_GET_CLASS (service)->read_xml (service, tree, &service_error);
		if (service_error != NULL) {
			*ret_error = go_error_info_new_str_with_details (
				_("Error reading service information."), service_error);
			g_object_unref (service);
			service = NULL;
		}
	}

	return service;
}
示例#18
0
void
go_plugin_service_unload (GOPluginService *service, GOErrorInfo **ret_error)
{
	GOErrorInfo *error = NULL;

	g_return_if_fail (GO_IS_PLUGIN_SERVICE (service));

	GO_INIT_RET_ERROR_INFO (ret_error);
	if (!service->is_loaded) {
		return;
	}
	go_plugin_unload_service (service->plugin, service, &error);
	if (error == NULL) {
		service->is_loaded = FALSE;
	} else {
		*ret_error = error;
	}
}
示例#19
0
static void
go_plugin_service_file_saver_activate (GOPluginService *service, GOErrorInfo **ret_error)
{
	GOPluginServiceFileSaver *service_file_saver = GO_PLUGIN_SERVICE_FILE_SAVER (service);
	GHashTable *file_savers_hash;

	GO_INIT_RET_ERROR_INFO (ret_error);
	service_file_saver->saver = GO_FILE_SAVER (go_plugin_file_saver_new (service));
	if (service_file_saver->default_saver_priority < 0) {
		go_file_saver_register (service_file_saver->saver);
	} else {
		go_file_saver_register_as_default (service_file_saver->saver,
						   service_file_saver->default_saver_priority);
	}
	file_savers_hash = get_plugin_file_savers_hash (service->plugin);
	g_assert (g_hash_table_lookup (file_savers_hash, service->id) == NULL);
	g_hash_table_insert (file_savers_hash, g_strdup (service->id), service_file_saver->saver);
	service->is_active = TRUE;
}
示例#20
0
void
go_plugin_service_deactivate (GOPluginService *service, GOErrorInfo **ret_error)
{
	g_return_if_fail (GO_IS_PLUGIN_SERVICE (service));

	GO_INIT_RET_ERROR_INFO (ret_error);
	if (!service->is_active) {
		return;
	}
	GO_PLUGIN_SERVICE_GET_CLASS (service)->deactivate (service, ret_error);
	if (*ret_error == NULL) {
		GOErrorInfo *ignored_error = NULL;

		service->is_active = FALSE;
		/* FIXME */
		go_plugin_service_unload (service, &ignored_error);
		go_error_info_free (ignored_error);
	}
}
示例#21
0
GType
go_plugin_service_plugin_loader_generate_type (GOPluginService *service,
					       GOErrorInfo **ret_error)
{
	GOPluginServicePluginLoader *service_plugin_loader = GO_PLUGIN_SERVICE_PLUGIN_LOADER (service);
	GOErrorInfo *error = NULL;
	GType loader_type;

	GO_INIT_RET_ERROR_INFO (ret_error);
	go_plugin_service_load (service, &error);
	if (error == NULL) {
		loader_type = service_plugin_loader->cbs.plugin_func_get_loader_type (
			service, &error);
		if (error == NULL)
			return loader_type;
		*ret_error = error;
	} else {
		*ret_error = go_error_info_new_str_with_details (
		             _("Error while loading plugin service."),
		             error);
	}
	return G_TYPE_NONE;
}
示例#22
0
static void
go_plugin_service_general_activate (GOPluginService *service, GOErrorInfo **ret_error)
{
	GOPluginServiceGeneral *service_general = GO_PLUGIN_SERVICE_GENERAL (service);
	GOErrorInfo *error = NULL;

	GO_INIT_RET_ERROR_INFO (ret_error);
	go_plugin_service_load (service, &error);
	if (error != NULL) {
		*ret_error = go_error_info_new_str_with_details (
		             _("Error while loading plugin service."),
		             error);
		return;
	}
	g_return_if_fail (service_general->cbs.plugin_func_init != NULL);
	service_general->cbs.plugin_func_init (service, &error);
	if (error != NULL) {
		*ret_error = go_error_info_new_str_with_details (
		             _("Initializing function inside plugin returned error."),
		             error);
		return;
	}
	service->is_active = TRUE;
}
示例#23
0
void
go_plugin_service_activate (GOPluginService *service, GOErrorInfo **ret_error)
{
	g_return_if_fail (GO_IS_PLUGIN_SERVICE (service));

	GO_INIT_RET_ERROR_INFO (ret_error);
	if (service->is_active) {
		return;
	}
#ifdef PLUGIN_ALWAYS_LOAD
	{
		GOErrorInfo *load_error = NULL;

		go_plugin_service_load (service, &load_error);
		if (load_error != NULL) {
			*ret_error = go_error_info_new_str_with_details (
				_("We must load service before activating it (PLUGIN_ALWAYS_LOAD is set) "
				  "but loading failed."), load_error);
			return;
		}
	}
#endif
	GO_PLUGIN_SERVICE_GET_CLASS (service)->activate (service, ret_error);
}
示例#24
0
文件: boot.c 项目: GNOME/gnumeric
G_MODULE_EXPORT GType
python_get_loader_type (GOErrorInfo **ret_error)
{
	GO_INIT_RET_ERROR_INFO (ret_error);
	return TYPE_GNM_PYTHON_PLUGIN_LOADER;
}
示例#25
0
static void
gplp_load_base (GOPluginLoader *loader, GOErrorInfo **ret_error)
{
	static gchar const *python_file_extensions[] = {"py", "pyc", "pyo", NULL};

	GnmPythonPluginLoader *loader_python = GNM_PYTHON_PLUGIN_LOADER (loader);
	gchar const **file_ext;
	GnmPython *py_object;
	GnmPyInterpreter *py_interpreter_info;
	gchar *full_module_file_name = NULL;
	FILE *f;
	GOPlugin *plugin = go_plugin_loader_get_plugin (loader);
	GOErrorInfo *open_error = NULL;
	PyObject *modules, *main_module, *main_module_dict;

	GO_INIT_RET_ERROR_INFO (ret_error);
	g_object_set_data (G_OBJECT (plugin), "python-loader", loader);

	py_object = gnm_python_object_get (ret_error);
	if (py_object == NULL)
		return;		/* gnm_python_object_get sets ret_error */
	py_interpreter_info = gnm_python_new_interpreter (py_object, plugin);
	if (py_interpreter_info == NULL) {
		*ret_error = go_error_info_new_str (_("Cannot create new Python interpreter."));
		gnm_python_clear_error_if_needed (py_object);
		g_object_unref (py_object);
		return;
	}

	for (file_ext = python_file_extensions; *file_ext != NULL; file_ext++) {
		gchar *file_name = g_strconcat (
			loader_python->module_name, ".", *file_ext, NULL);
		gchar *path = g_build_filename (
			go_plugin_get_dir_name (plugin),
			file_name, NULL);
		g_free (file_name);
		if (g_file_test (path, G_FILE_TEST_EXISTS)) {
			full_module_file_name = path;
			break;
		} else
			g_free (path);
	}
	if (full_module_file_name == NULL) {
		*ret_error = go_error_info_new_printf (
		             _("Module \"%s\" doesn't exist."),
		             loader_python->module_name);
		gnm_python_destroy_interpreter (py_object, py_interpreter_info);
		g_object_unref (py_object);
		return;
	}
	f = gnumeric_fopen_error_info (full_module_file_name, "r", &open_error);
	g_free (full_module_file_name);
	if (f == NULL) {
		*ret_error = open_error;
		gnm_python_destroy_interpreter (py_object, py_interpreter_info);
		g_object_unref (py_object);
		return;
	}

	if (PyRun_SimpleFile (f, loader_python->module_name) != 0) {
		(void) fclose (f);
		*ret_error = go_error_info_new_printf (
		             _("Execution of module \"%s\" failed."),
		             loader_python->module_name);
		gnm_python_destroy_interpreter (py_object, py_interpreter_info);
		g_object_unref (py_object);
		return;
	}
	(void) fclose (f);

	modules = PyImport_GetModuleDict ();
	g_return_if_fail (modules != NULL);
	main_module = PyDict_GetItemString (modules, (char *) "__main__");
	g_return_if_fail (main_module != NULL);
	main_module_dict = PyModule_GetDict (main_module);
	g_return_if_fail (main_module_dict != NULL);
	loader_python->py_object = py_object;
	loader_python->py_interpreter_info = py_interpreter_info;
	loader_python->main_module = main_module;
	loader_python->main_module_dict = main_module_dict;
}
示例#26
0
static void
go_plugin_service_file_opener_read_xml (GOPluginService *service, xmlNode *tree, GOErrorInfo **ret_error)
{
	int priority;
	gboolean has_probe;
	gboolean encoding_dependent;
	xmlNode *information_node;
	gchar *description;

	GO_INIT_RET_ERROR_INFO (ret_error);
	if (go_xml_node_get_int (tree, "priority", &priority))
		priority = CLAMP (priority, 0, 100);
	else
		priority = 50;

	if (!go_xml_node_get_bool (tree, "probe", &has_probe))
		has_probe = TRUE;
	if (!go_xml_node_get_bool (tree, "encoding_dependent", &encoding_dependent))
		encoding_dependent = FALSE;

	information_node = go_xml_get_child_by_name (tree, "information");
	if (information_node != NULL) {
		xmlNode *node = go_xml_get_child_by_name_by_lang
			(information_node, "description");
		description = node ? xml2c (xmlNodeGetContent (node)) : NULL;
	} else {
		description = NULL;
	}
	if (description != NULL) {
		GSList *suffixes = NULL, *mimes = NULL;
		xmlNode *list, *node;
		GOPluginServiceFileOpener *service_file_opener = GO_PLUGIN_SERVICE_FILE_OPENER (service);

		list = go_xml_get_child_by_name (tree, "suffixes");
		if (list != NULL) {
			for (node = list->xmlChildrenNode; node != NULL; node = node->next) {
				char *tmp;

				if (strcmp (node->name, "suffix"))
					continue;

				tmp = xml2c (xmlNodeGetContent (node));
				if (!tmp)
					continue;

				GO_SLIST_PREPEND (suffixes, tmp);
			}
		}
		GO_SLIST_REVERSE (suffixes);

		list = go_xml_get_child_by_name (tree, "mime-types");
		if (list != NULL) {
			for (node = list->xmlChildrenNode; node != NULL; node = node->next) {
				char *tmp;

				if (strcmp (node->name, "mime-type"))
					continue;

				tmp = xml2c (xmlNodeGetContent (node));
				if (!tmp)
					continue;

				GO_SLIST_PREPEND (mimes, tmp);
			}
		}
		GO_SLIST_REVERSE (mimes);

		service_file_opener->priority = priority;
		service_file_opener->has_probe = has_probe;
		service_file_opener->encoding_dependent	= encoding_dependent;
		service_file_opener->description = description;
		service_file_opener->suffixes	= suffixes;
		service_file_opener->mimes	= mimes;
	} else {
		*ret_error = go_error_info_new_str (_("File opener has no description"));
	}
}