Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-05-06 21:54:55 +0400
committerCampbell Barton <ideasman42@gmail.com>2008-05-06 21:54:55 +0400
commit4255f3c7abe5c0bc7e9d2bc407ec6671e6ae6c45 (patch)
treed36e4b68107597912f8f9cf38764a03c78b8401f /source/blender/python/api2_2x/Sys.c
parent722f24d15357275ee3efed33fa03f9b27909a604 (diff)
made python add mesh module respect blenders user settings for editmode and view align.
added sys.cleanpath() was a patch in the tracker but blender's internal path cleaning is now more general and can be used from python.
Diffstat (limited to 'source/blender/python/api2_2x/Sys.c')
-rw-r--r--source/blender/python/api2_2x/Sys.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/source/blender/python/api2_2x/Sys.c b/source/blender/python/api2_2x/Sys.c
index 9de4e344e8c..3863cc12227 100644
--- a/source/blender/python/api2_2x/Sys.c
+++ b/source/blender/python/api2_2x/Sys.c
@@ -58,6 +58,7 @@ static PyObject *M_sys_exists( PyObject * self, PyObject * value );
static PyObject *M_sys_time( PyObject * self );
static PyObject *M_sys_sleep( PyObject * self, PyObject * args );
static PyObject *M_sys_expandpath( PyObject *self, PyObject *value);
+static PyObject *M_sys_cleanpath( PyObject *self, PyObject *value);
/*****************************************************************************/
/* The following string definitions are used for documentation strings. */
@@ -120,10 +121,13 @@ static char M_sys_expandpath_doc[] =
(path) - the string path to convert.\n\n\
Note: internally Blender paths can contain two special character sequences:\n\
- '//' (at start) for base path directory (the current .blend's dir path);\n\
-- '#' (at ending) for current frame number.\n\n\
+- '#' characters in the filename will be replaced by the frame number.\n\n\
This function expands these to their actual content, returning a valid path.\n\
If the special chars are not found in the given path, it is simply returned.";
+static char M_sys_cleanpath_doc[] =
+"(path) - Removes parts of a path that are not needed paths such as '../foo/../bar/' and '//./././'";
+
/*****************************************************************************/
/* Python method structure definition for Blender.sys module: */
/*****************************************************************************/
@@ -139,6 +143,7 @@ struct PyMethodDef M_sys_methods[] = {
{"sleep", M_sys_sleep, METH_VARARGS, M_sys_sleep_doc},
{"time", ( PyCFunction ) M_sys_time, METH_NOARGS, M_sys_time_doc},
{"expandpath", M_sys_expandpath, METH_O, M_sys_expandpath_doc},
+ {"cleanpath", M_sys_cleanpath, METH_O, M_sys_cleanpath_doc},
{NULL, NULL, 0, NULL}
};
@@ -396,3 +401,24 @@ static PyObject *M_sys_expandpath( PyObject * self, PyObject * value )
return PyString_FromString(expanded);
}
+
+static PyObject *M_sys_cleanpath( PyObject * self, PyObject * value )
+{
+ char *path = PyString_AsString(value);
+ char cleaned[FILE_MAXDIR + FILE_MAXFILE];
+ int trailing_slash = 0;
+ if (!path)
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected string argument" );
+ if (strstr(path, "/") || strstr(path, "\\")) {
+ trailing_slash = 1;
+ }
+ BLI_strncpy(cleaned, path, FILE_MAXDIR + FILE_MAXFILE);
+ BLI_cleanup_file(NULL, cleaned);
+
+ if (trailing_slash) {
+ BLI_add_slash(cleaned);
+ }
+
+ return PyString_FromString(cleaned);
+}