diff options
Diffstat (limited to 'plugins/pychrysalide/common/pathname.c')
-rw-r--r-- | plugins/pychrysalide/common/pathname.c | 114 |
1 files changed, 34 insertions, 80 deletions
diff --git a/plugins/pychrysalide/common/pathname.c b/plugins/pychrysalide/common/pathname.c index c83c27d..9ea9a2b 100644 --- a/plugins/pychrysalide/common/pathname.c +++ b/plugins/pychrysalide/common/pathname.c @@ -40,18 +40,11 @@ -#define PYTHON_PATHNAME_DOC \ - "Path manipulations in Python for Chrysalide.\n" \ - "\n" \ - "There is no constructor for this class: its methods" \ - " are static methods only." - - /* Calcule le chemin relatif entre deux fichiers donnés. */ -static PyObject *py_build_relative_filename(PyObject *, PyObject *); +static PyObject *py_pathname_build_relative_filename(PyObject *, PyObject *); /* Calcule le chemin absolu d'un fichier par rapport à un autre. */ -static PyObject *py_build_absolute_filename(PyObject *, PyObject *); +static PyObject *py_pathname_build_absolute_filename(PyObject *, PyObject *); @@ -68,7 +61,7 @@ static PyObject *py_build_absolute_filename(PyObject *, PyObject *); * * ******************************************************************************/ -static PyObject *py_build_relative_filename(PyObject *self, PyObject *args) +static PyObject *py_pathname_build_relative_filename(PyObject *self, PyObject *args) { PyObject *result; /* Instance à retourner */ const char *ref; /* Fichier de référence */ @@ -76,13 +69,16 @@ static PyObject *py_build_relative_filename(PyObject *self, PyObject *args) int ret; /* Bilan de lecture des args. */ char *relative; /* Chemin d'accès construit */ -#define BUILD_RELATIVE_FILENAME_METHOD PYTHON_METHOD_DEF \ -( \ - build_relative_filename, "ref, target", \ - METH_VARARGS | METH_STATIC, py, \ - "Compute the relative path between two files.\n" \ - "\n" \ - "Both arguments must be strings." \ +#define BUILD_RELATIVE_FILENAME_METHOD PYTHON_METHOD_DEF \ +( \ + build_relative_filename, "reference, target", \ + METH_VARARGS, py_pathname, \ + "Compute the relative path between two files: a *reference*" \ + " location as point of view and a *target* file.\n" \ + "\n" \ + "Both arguments must be strings.\n" \ + "\n" \ + "The result is also a string." \ ) ret = PyArg_ParseTuple(args, "ss", &ref, &target); @@ -112,7 +108,7 @@ static PyObject *py_build_relative_filename(PyObject *self, PyObject *args) * * ******************************************************************************/ -static PyObject *py_build_absolute_filename(PyObject *self, PyObject *args) +static PyObject *py_pathname_build_absolute_filename(PyObject *self, PyObject *args) { PyObject *result; /* Instance à retourner */ const char *ref; /* Fichier de référence */ @@ -120,13 +116,17 @@ static PyObject *py_build_absolute_filename(PyObject *self, PyObject *args) int ret; /* Bilan de lecture des args. */ char *relative; /* Chemin d'accès construit */ -#define BUILD_ABSOLUTE_FILENAME_METHOD PYTHON_METHOD_DEF \ -( \ - build_absolute_filename, "ref, target", \ - METH_VARARGS | METH_STATIC, py, \ - "Compute the absolute path for a file.\n" \ - "\n" \ - "Both arguments must be strings." \ +#define BUILD_ABSOLUTE_FILENAME_METHOD PYTHON_METHOD_DEF \ +( \ + build_absolute_filename, "reference, target", \ + METH_VARARGS, py_pathname, \ + "Compute the absolute path for a *target* file from a" \ + " *reference* location.\n" \ + "\n" \ + "Both arguments must be strings.\n" \ + "\n" \ + "The result is a string on success. A *ValueError* exception" \ + " is raised on failure." \ ) ret = PyArg_ParseTuple(args, "ss", &ref, &target); @@ -154,75 +154,29 @@ static PyObject *py_build_absolute_filename(PyObject *self, PyObject *args) * * * Paramètres : - * * * -* Description : Fournit un accès à une définition de type à diffuser. * +* Description : Définit une extension du module 'common' à compléter. * * * -* Retour : Définition d'objet pour Python. * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -PyTypeObject *get_python_pathname_type(void) +bool populate_common_module_with_pathname(void) { + bool result; /* Bilan à retourner */ + PyObject *module; /* Module à recompléter */ + static PyMethodDef py_pathname_methods[] = { BUILD_RELATIVE_FILENAME_METHOD, BUILD_ABSOLUTE_FILENAME_METHOD, { NULL } }; - static PyTypeObject py_pathname_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.common.pathname", - .tp_basicsize = sizeof(PyObject), - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = PYTHON_PATHNAME_DOC, - - .tp_methods = py_pathname_methods, + module = get_access_to_python_module("pychrysalide.common"); - .tp_new = no_python_constructor_allowed, + result = register_python_module_methods(module, py_pathname_methods); - }; - - return &py_pathname_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.core.pathname'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool ensure_python_pathname_is_registered(void) -{ - PyTypeObject *type; /* Type Python pour 'pathname' */ - PyObject *module; /* Module à recompléter */ - - type = get_python_pathname_type(); - - if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) - { - if (PyType_Ready(type) != 0) - return false; - - module = get_access_to_python_module("pychrysalide.common"); - - if (!register_python_module_object(module, type)) - return false; - - } - - return true; + return result; } |