Esempio n. 1
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");
}
Esempio n. 2
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);
}
Esempio n. 3
0
static FILE *
gnumeric_fopen_error_info (const char *file_name, const char *mode, GOErrorInfo **ret_error)
{
	FILE *f;

	g_return_val_if_fail (file_name != NULL, NULL);
	g_return_val_if_fail (mode != NULL, NULL);
	g_return_val_if_fail (ret_error != NULL, NULL);

	*ret_error = NULL;
	f = g_fopen (file_name, mode);
	if (f == NULL) {
		if (strchr (mode, 'w') != NULL && strchr (mode, 'r') == NULL) {
			*ret_error = go_error_info_new_printf (
			             _("Error while opening file \"%s\" for writing."),
			             file_name);
		} else {
			*ret_error = go_error_info_new_printf (
			             _("Error while opening file \"%s\" for reading."),
			             file_name);
		}
		go_error_info_add_details (*ret_error, go_error_info_new_from_errno ());
	}

	return f;
}
Esempio n. 4
0
/**
 * go_error_info_new_str_with_details:
 * @msg: error message
 * @details: #GOErrorInfo to add
 *
 * Creates a new #GOErrorInfo from @message and an existing #GOErrorInfo
 * instance to add to the message.
 * Returns: (transfer full): the newly created #GOErrorInfo
 **/
GOErrorInfo *
go_error_info_new_str_with_details (char const *msg, GOErrorInfo *details)
{
	GOErrorInfo *error = go_error_info_new_str (msg);
	go_error_info_add_details (error, details);
	return error;
}
Esempio n. 5
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);
}
Esempio n. 6
0
void
go_io_error_push (GOIOContext *context, GOErrorInfo *error)
{
	g_return_if_fail (context != NULL);
	g_return_if_fail (error != NULL);

	if (context->info == NULL)
		go_io_error_info_set (context, error);
	else {
		GOErrorInfo *info = context->info->data;
		go_error_info_add_details (error, info);
		context->info->data = error;
	}
}