[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28724] trunk/blender: bpy.utils. blend_paths(absolute=False) (was Blender.GetPaths in 2.4x)

Campbell Barton ideasman42 at gmail.com
Tue May 11 09:08:32 CEST 2010


Revision: 28724
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28724
Author:   campbellbarton
Date:     2010-05-11 09:08:32 +0200 (Tue, 11 May 2010)

Log Message:
-----------
 bpy.utils.blend_paths(absolute=False)  (was Blender.GetPaths in 2.4x)

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy/utils.py
    trunk/blender/source/blender/blenlib/BLI_bpath.h
    trunk/blender/source/blender/python/intern/bpy.c

Modified: trunk/blender/release/scripts/modules/bpy/utils.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/utils.py	2010-05-11 06:56:59 UTC (rev 28723)
+++ trunk/blender/release/scripts/modules/bpy/utils.py	2010-05-11 07:08:32 UTC (rev 28724)
@@ -27,7 +27,7 @@
 import os as _os
 import sys as _sys
 
-from _bpy import home_paths
+from _bpy import home_paths, blend_paths
 
 
 def _test_import(module_name, loaded_modules):

Modified: trunk/blender/source/blender/blenlib/BLI_bpath.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_bpath.h	2010-05-11 06:56:59 UTC (rev 28723)
+++ trunk/blender/source/blender/blenlib/BLI_bpath.h	2010-05-11 07:08:32 UTC (rev 28724)
@@ -29,6 +29,9 @@
 /* Based on ghash, difference is ghash is not a fixed size,
  * so for BPath we dont need to malloc  */
 
+#ifndef BLI_BPATH_H
+#define BLI_BPATH_H
+
 struct BPathIteratorSeqData {
 	int totseq;
 	int seq;
@@ -72,3 +75,5 @@
 void makeFilesRelative(char *basepath, ReportList *reports);
 void makeFilesAbsolute(char *basepath, ReportList *reports);
 void findMissingFiles(char *basepath, char *str);
+
+#endif // BLI_BPATH_H

Modified: trunk/blender/source/blender/python/intern/bpy.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy.c	2010-05-11 06:56:59 UTC (rev 28723)
+++ trunk/blender/source/blender/python/intern/bpy.c	2010-05-11 07:08:32 UTC (rev 28724)
@@ -31,8 +31,9 @@
 #include "bpy_app.h"
 #include "bpy_props.h"
 #include "bpy_operator.h"
- 
+
 #include "BLI_path_util.h"
+#include "BLI_bpath.h"
  
  /* external util modules */
 #include "../generic/geometry.h"
@@ -43,7 +44,7 @@
 static char bpy_home_paths_doc[] =
 ".. function:: home_paths(subfolder)\n"
 "\n"
-"   return 3 paths to blender home directories.\n"
+"   Return 3 paths to blender home directories.\n"
 "\n"
 "   :arg subfolder: The name of a subfolder to find within the blenders home directory.\n"
 "   :type subfolder: string\n"
@@ -71,7 +72,56 @@
 	return ret;
 }
 
+static char bpy_blend_paths_doc[] =
+".. function:: blend_paths(absolute=False)\n"
+"\n"
+"   Returns a list of paths assosiated with this blend file.\n"
+"\n"
+"   :arg absolute: When true the paths returned are made absolute.\n"
+"   :type absolute: boolean\n"
+"   :return: path list.\n"
+"   :rtype: list of strigs\n";
+static PyObject *bpy_blend_paths(PyObject * self, PyObject *args, PyObject *kw)
+{
+	struct BPathIterator bpi;
+	PyObject *list = PyList_New(0), *st; /* stupidly big string to be safe */
+	/* be sure there is low chance of the path being too short */
+	char filepath_expanded[1024];
+	char *lib;
+
+	int absolute = 0;
+	static char *kwlist[] = {"absolute", NULL};
+
+	if (!PyArg_ParseTupleAndKeywords(args, kw, "|i:blend_paths", kwlist, &absolute))
+		return NULL;
+
+	for(BLI_bpathIterator_init(&bpi, NULL); !BLI_bpathIterator_isDone(&bpi); BLI_bpathIterator_step(&bpi)) {
+		/* build the list */
+		if (absolute) {
+			BLI_bpathIterator_getPathExpanded(&bpi, filepath_expanded);
+		}
+		else {
+			lib = BLI_bpathIterator_getLib(&bpi);
+			if (lib && (strcmp(lib, bpi.base_path))) { /* relative path to the library is NOT the same as our blendfile path, return an absolute path */
+				BLI_bpathIterator_getPathExpanded(&bpi, filepath_expanded);
+			}
+			else {
+				BLI_bpathIterator_getPath(&bpi, filepath_expanded);
+			}
+		}
+		st = PyUnicode_FromString(filepath_expanded);
+
+		PyList_Append(list, st);
+		Py_DECREF(st);
+	}
+
+	BLI_bpathIterator_free(&bpi);
+
+	return list;
+}
+
 static PyMethodDef meth_bpy_home_paths[] = {{ "home_paths", (PyCFunction)bpy_home_paths, METH_VARARGS, bpy_home_paths_doc}};
+static PyMethodDef meth_bpy_blend_paths[] = {{ "blend_paths", (PyCFunction)bpy_blend_paths, METH_VARARGS|METH_KEYWORDS, bpy_blend_paths_doc}};
 
 static void bpy_import_test(char *modname)
 {
@@ -138,6 +188,7 @@
 
 	/* utility func's that have nowhere else to go */
 	PyModule_AddObject(mod, meth_bpy_home_paths->ml_name, (PyObject *)PyCFunction_New(meth_bpy_home_paths, NULL));
+	PyModule_AddObject(mod, meth_bpy_blend_paths->ml_name, (PyObject *)PyCFunction_New(meth_bpy_blend_paths, NULL));
 
 	/* add our own modules dir, this is a python package */
 	bpy_import_test("bpy");





More information about the Bf-blender-cvs mailing list