summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/pychrysa.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysa/pychrysa.c')
-rw-r--r--plugins/pychrysa/pychrysa.c171
1 files changed, 162 insertions, 9 deletions
diff --git a/plugins/pychrysa/pychrysa.c b/plugins/pychrysa/pychrysa.c
index b6f89a0..eafb358 100644
--- a/plugins/pychrysa/pychrysa.c
+++ b/plugins/pychrysa/pychrysa.c
@@ -214,7 +214,11 @@ bool init_plugin(GPluginModule *plugin, GObject *ref)
-///////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////:///////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////:///////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////:///////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////:///////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////:///////////////////////////
#include <stdio.h>
@@ -224,18 +228,21 @@ bool init_plugin(GPluginModule *plugin, GObject *ref)
#include <config.h>
+#include <common/environment.h>
+#include <common/extstr.h>
#include <plugins/plugin-def.h>
#include <plugins/plugin-int.h>
+#include "plugin.h"
+#include "quirks.h"
#include "../../revision.h"
-
-DEFINE_CHRYSALIDE_ACTIVE_PLUGIN("PyChrysalide", "Provides bindings to Python", "0.1.0", PGA_ALL);
+DEFINE_CHRYSALIDE_ACTIVE_PLUGIN("PyChrysalide", "Provides bindings to Python", "0.1.0", PGA_PLUGIN_INIT);
/* Fournit la version du programme global. */
@@ -247,7 +254,8 @@ static PyObject *py_chrysalide_mod_version(PyObject *, PyObject *);
/* Détermine si l'interpréteur lancé est celui pris en compte. */
static bool is_current_abi_suitable(void);
-
+/* Charge autant de greffons composés en Python que possible. */
+static bool load_python_plugins(GPluginModule *plugin, GObject *);
@@ -428,10 +436,8 @@ PyMODINIT_FUNC PyInit_pychrysalide(void)
};
- // TODO : à bouger !
- //init_all_processors();
- //init_all_formats();
+#if 0
do
{
int argc = 0;
@@ -448,11 +454,14 @@ PyMODINIT_FUNC PyInit_pychrysalide(void)
add_pixmap_directory(PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "pixmaps");
init_work_queue(NULL/* !! */);
-
+#endif
////////////////////////
+
+
+
if (!is_current_abi_suitable())
return NULL;
@@ -468,17 +477,25 @@ PyMODINIT_FUNC PyInit_pychrysalide(void)
return NULL;
}
+ /* Préparatifs préalables aux chargements */
+
/**
* Pour une raison non identifiée, si le module n'est pas préchargé,
* le flot d'exécution plante dans la fonction insertdict() de Objects/dictobject.c:818.
*/
+
pygobj_mod = PyImport_ImportModule("gi.repository.GObject");
if (pygobj_mod == NULL)
+ {
+ PyErr_SetString(PyExc_ImportError, "could not import gi.gobject");
return NULL;
+ }
+
+ /* Mise en place des fonctionnalités offertes */
result = PyModule_Create(&py_chrysalide_module);
- status = true;
+ status = register_python_plugin_module(result);
status &= add_analysis_module_to_python_module(result);
status &= add_arch_module_to_python_module(result);
@@ -498,3 +515,139 @@ PyMODINIT_FUNC PyInit_pychrysalide(void)
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : plugin = instance représentant le greffon Python d'origine. *
+* ref = espace de référencement global. *
+* *
+* Description : Charge autant de greffons composés en Python que possible. *
+* *
+* Retour : true. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool load_python_plugins(GPluginModule *plugin, GObject *ref)
+{
+ char *paths; /* Emplacements de greffons */
+ char *save; /* Sauvegarde pour ré-entrance */
+ char *path; /* Chemin à fouiller */
+ DIR *dir; /* Répertoire à parcourir */
+ struct dirent entry; /* Elément trouvé */
+ struct dirent *next; /* Prochain élément fourni */
+ int ret; /* Bilan d'un appel système */
+ char *modname; /* Nom du module pour Python */
+ char *filename; /* Chemin d'accès reconstruit */
+ GPluginModule *pyplugin; /* Lien vers un grffon Python */
+
+ paths = get_env_var("PYTHONPATH");
+
+ save = NULL; /* gcc... */
+
+ for (path = strtok_r(paths, ";", &save);
+ path != NULL;
+ path = strtok_r(NULL, ";", &save))
+ {
+ dir = opendir(path);
+ if (dir == NULL)
+ {
+ perror("opendir");
+ continue;
+ }
+
+ g_plugin_module_log_variadic_message(plugin, LMT_INFO,
+ _("Looking for Python plugins in '%s'..."),
+ path);
+
+ for (ret = readdir_r(dir, &entry, &next);
+ ret == 0 && next != NULL;
+ ret = readdir_r(dir, &entry, &next))
+ {
+ if (entry.d_type != DT_DIR) continue;
+ if (entry.d_name[0] == '.') continue;
+
+ modname = strdup(entry.d_name);
+ modname = stradd(modname, ".");
+ modname = stradd(modname, "__init__");
+
+ filename = strdup(path);
+ filename = stradd(filename, G_DIR_SEPARATOR_S);
+ filename = stradd(filename, entry.d_name);
+
+ pyplugin = g_python_plugin_new(modname, filename, ref);
+
+ if (pyplugin == NULL)
+ g_plugin_module_log_variadic_message(plugin, LMT_ERROR,
+ _("No suitable Python plugin found in '%s'"),
+ filename);
+ else
+ {
+ g_plugin_module_log_variadic_message(plugin, LMT_PROCESS,
+ _("Loaded the Python plugin found in the '<b>%s</b>' directory"),
+ filename);
+ add_plugin_to_main_list(pyplugin);
+ }
+
+ free(filename);
+ free(modname);
+
+ }
+
+ closedir(dir);
+
+ }
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : plugin = greffon à manipuler. *
+* ref = espace de référencement global. *
+* *
+* Description : Prend acte du chargement du greffon. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin, GObject *ref)
+{
+ bool result; /* Bilan à retourner */
+ DIR *dir; /* Répertoire à parcourir */
+
+ define_internal_ref(ref);
+
+ /* Définition des zones d'influence */
+
+ dir = opendir(PLUGINS_DIR G_DIR_SEPARATOR_S "python");
+
+ if (dir != NULL)
+ {
+ closedir(dir);
+ add_to_env_var("PYTHONPATH", PLUGINS_DIR G_DIR_SEPARATOR_S "python", ";");
+ }
+ else
+ add_to_env_var("PYTHONPATH", PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "plugins" \
+ G_DIR_SEPARATOR_S "python", ";");
+
+ /* Chargement du module pour Python */
+
+ PyImport_AppendInittab("pychrysalide", &PyInit_pychrysalide);
+
+ Py_Initialize();
+
+ PySys_SetArgv(0, (wchar_t *[]) { NULL });
+
+ result = load_python_plugins(plugin, ref);
+
+ return result;
+
+}