~ubuntu-branches/ubuntu/maverick/blender/maverick

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/Library.c

  • Committer: Bazaar Package Importer
  • Author(s): Khashayar Naderehvandi, Khashayar Naderehvandi, Alessio Treglia
  • Date: 2009-01-22 16:53:59 UTC
  • mfrom: (14.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090122165359-v0996tn7fbit64ni
Tags: 2.48a+dfsg-1ubuntu1
[ Khashayar Naderehvandi ]
* Merge from debian experimental (LP: #320045), Ubuntu remaining changes:
  - Add patch correcting header file locations.
  - Add libvorbis-dev and libgsm1-dev to Build-Depends.
  - Use avcodec_decode_audio2() in source/blender/src/hddaudio.c

[ Alessio Treglia ]
* Add missing previous changelog entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: Library.c 14669 2008-05-04 09:41:15Z campbellbarton $
 
2
 * $Id: Library.c 15645 2008-07-19 15:44:00Z campbellbarton $
3
3
 *
4
4
 * Blender.Library BPython module implementation.
5
5
 * This submodule has functions to append data from .blend files.
1135
1135
        return (PyObject *)lib;
1136
1136
}
1137
1137
 
 
1138
static PyObject *M_Library_GetPaths(PyObject *self, PyObject * args)
 
1139
{       
 
1140
        PyObject *list;
 
1141
        PyObject *name;
 
1142
        int type=0;
 
1143
        Library *lib;
 
1144
        
 
1145
        if( !PyArg_ParseTuple( args, "|i", &type ) || type < 0 || type > 2 ) {
 
1146
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
1147
                        "expected an int between 0 and 2." );
 
1148
        }
 
1149
        
 
1150
        list = PyList_New(0);
 
1151
        
 
1152
        for(lib= G.main->library.first; lib; lib= lib->id.next) {
 
1153
                if (type==0) {
 
1154
                        /* any type is ok */
 
1155
                } else if (type==1 && lib->parent == 0) {
 
1156
                        /* only direct linked */
 
1157
                } else if (type==2 && lib->parent != 0) {
 
1158
                        /* only indirect */
 
1159
                } else {
 
1160
                        continue; /* incompatible type */
 
1161
                }
 
1162
                
 
1163
                name = PyString_FromString(lib->name);
 
1164
                PyList_Append(list, name);
 
1165
                Py_DECREF(name);
 
1166
        }
 
1167
        return list;
 
1168
}
 
1169
 
 
1170
static PyObject *M_Library_ReplacePath(PyObject *self, PyObject * args)
 
1171
{
 
1172
        char *name_from, *name_to;
 
1173
        Library *lib;
 
1174
        
 
1175
        if( !PyArg_ParseTuple( args, "ss", &name_from, &name_to )) {
 
1176
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
1177
                        "expected the name of a library path" );
 
1178
        }
 
1179
        
 
1180
        for(lib= G.main->library.first; lib; lib= lib->id.next) {
 
1181
                if (strcmp(lib->name, name_from)==0) {
 
1182
                        if (lib->parent) {
 
1183
                                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
1184
                                        "path is indirectly linked, cannot be changed." );
 
1185
                        }
 
1186
                        
 
1187
                        if (strlen(name_to) > sizeof(lib->name)) {
 
1188
                                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
1189
                                        "string length too long, cannot set path." );
 
1190
                        }
 
1191
                        
 
1192
                        strcpy(lib->name, name_to);
 
1193
                        Py_RETURN_NONE;
 
1194
                }
 
1195
        }
 
1196
        
 
1197
        return EXPP_ReturnPyObjError( PyExc_ValueError,
 
1198
                "path given does not exist as a library" );
 
1199
}
 
1200
 
 
1201
 
 
1202
 
1138
1203
static struct PyMethodDef M_Library_methods[] = {
1139
1204
        {"load", (PyCFunction)M_Library_Load, METH_VARARGS,
1140
1205
        "(string) - declare a .blend file for use as a library"},
 
1206
        {"paths", (PyCFunction)M_Library_GetPaths, METH_VARARGS,
 
1207
        "(type) - return a list of library paths, type 0 for all, 1 only direct links, 2 only indirect links"},
 
1208
        {"replace", (PyCFunction)M_Library_ReplacePath, METH_VARARGS,
 
1209
        "(from, to) - replace the path of an existing, directly linked library."},
1141
1210
        {NULL, NULL, 0, NULL}
1142
1211
};
1143
1212