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:
authorKen Hughes <khughes@pacific.edu>2008-05-01 22:52:26 +0400
committerKen Hughes <khughes@pacific.edu>2008-05-01 22:52:26 +0400
commita87d82023a2790ae62032eb8c272bda0262c5a23 (patch)
tree79dbd1d90764a33663bc1b17e5f825fb611bc7cc /source/blender/python/api2_2x/Library.c
parent3eac2b2faa5748c319352367c0dd6b7d6c358fe2 (diff)
Add library.name attribute, which returns the actual library name used by blender (this may be different from the library.filename attribute).
Diffstat (limited to 'source/blender/python/api2_2x/Library.c')
-rw-r--r--source/blender/python/api2_2x/Library.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/source/blender/python/api2_2x/Library.c b/source/blender/python/api2_2x/Library.c
index 54399b15aa1..b6fb1500a6e 100644
--- a/source/blender/python/api2_2x/Library.c
+++ b/source/blender/python/api2_2x/Library.c
@@ -977,6 +977,39 @@ static int Library_setFilename( BPy_Library * self, PyObject * args )
return 0;
}
+/*
+ * Return the library's name. The format depends on whether the library is
+ * accessed as relative or absolute.
+ */
+
+static PyObject *Library_getName( BPy_Library * self )
+{
+ Library *lib;
+ BlendHandle *openlib;
+ char longFilename[FILE_MAX];
+
+ /* try to open the library */
+ openlib = open_library( self->filename, longFilename );
+ if( openlib ) {
+ BLO_blendhandle_close( openlib );
+ /* remove any /../ or /./ junk */
+ BLI_cleanup_file(NULL, longFilename);
+
+ /* search the loaded libraries for a match */
+ for( lib = G.main->library.first; lib; lib = lib->id.next )
+ if( strcmp( longFilename, lib->filename ) == 0) {
+ return PyString_FromString( lib->name );
+ }
+
+ /* library not found in memory */
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "library not loaded" );
+ }
+ /* could not load library */
+ return EXPP_ReturnPyObjError( PyExc_IOError, "library not found" );
+}
+
+
/************************************************************************
* Python Library_type attributes get/set structure
************************************************************************/
@@ -986,6 +1019,10 @@ static PyGetSetDef Library_getseters[] = {
(getter)Library_getFilename, (setter)Library_setFilename,
"library filename",
NULL},
+ {"name",
+ (getter)Library_getName, (setter)NULL,
+ "library name (as used by Blender)",
+ NULL},
{"objects",
(getter)LibraryData_CreatePyObject, (setter)NULL,
"objects from the library",