- Support for importing python packages. (directories of python scripts containing an __init__.py)
- BLI_add_slash returns the new string length. - BLI_where_am_i() would often have /./ in the path (not incorrect but annoying, got into python exceptions) - release/ui/space_image.py, py error referencing invalid keyword args.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_util.h"
|
||||
#include "BLI_fileops.h"
|
||||
#include "BLI_string.h"
|
||||
|
||||
#include "BKE_context.h"
|
||||
@@ -441,6 +442,26 @@ int BPY_run_python_script_space(const char *modulename, const char *func)
|
||||
#include "PIL_time.h"
|
||||
#endif
|
||||
|
||||
/* for use by BPY_run_ui_scripts only */
|
||||
static int bpy_import_module(char *modname, int reload)
|
||||
{
|
||||
PyObject *mod= PyImport_ImportModuleLevel(modname, NULL, NULL, NULL, 0);
|
||||
if (mod) {
|
||||
if (reload) {
|
||||
PyObject *mod_orig= mod;
|
||||
mod= PyImport_ReloadModule(mod);
|
||||
Py_DECREF(mod_orig);
|
||||
}
|
||||
}
|
||||
|
||||
if(mod) {
|
||||
Py_DECREF(mod); /* could be NULL from reloading */
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* XXX this is temporary, need a proper script registration system for 2.5 */
|
||||
void BPY_run_ui_scripts(bContext *C, int reload)
|
||||
{
|
||||
@@ -453,10 +474,9 @@ void BPY_run_ui_scripts(bContext *C, int reload)
|
||||
char *dirname;
|
||||
char path[FILE_MAX];
|
||||
char *dirs[] = {"ui", "io", NULL};
|
||||
int a;
|
||||
int a, err;
|
||||
|
||||
PyGILState_STATE gilstate;
|
||||
PyObject *mod;
|
||||
PyObject *sys_path;
|
||||
|
||||
gilstate = PyGILState_Ensure();
|
||||
@@ -486,27 +506,32 @@ void BPY_run_ui_scripts(bContext *C, int reload)
|
||||
while((de = readdir(dir)) != NULL) {
|
||||
/* We could stat the file but easier just to let python
|
||||
* import it and complain if theres a problem */
|
||||
err = 0;
|
||||
|
||||
file_extension = strstr(de->d_name, ".py");
|
||||
|
||||
if(file_extension && file_extension[3] == '\0') {
|
||||
BLI_strncpy(path, de->d_name, (file_extension - de->d_name) + 1); /* cut off the .py on copy */
|
||||
mod= PyImport_ImportModuleLevel(path, NULL, NULL, NULL, 0);
|
||||
if (mod) {
|
||||
if (reload) {
|
||||
PyObject *mod_orig= mod;
|
||||
mod= PyImport_ReloadModule(mod);
|
||||
Py_DECREF(mod_orig);
|
||||
}
|
||||
if (de->d_name[0] == '.') {
|
||||
/* do nothing, probably .svn */
|
||||
}
|
||||
else if(de->d_type==DT_DIR) {
|
||||
/* support packages */
|
||||
BLI_join_dirfile(path, dirname, de->d_name);
|
||||
BLI_join_dirfile(path, path, "__init__.py");
|
||||
|
||||
if(BLI_exists(path)) {
|
||||
bpy_import_module(de->d_name, reload);
|
||||
}
|
||||
} else {
|
||||
/* normal py files */
|
||||
file_extension = strstr(de->d_name, ".py");
|
||||
|
||||
if(mod) {
|
||||
Py_DECREF(mod); /* could be NULL from reloading */
|
||||
} else {
|
||||
BPy_errors_to_report(NULL);
|
||||
fprintf(stderr, "unable to import \"%s\" %s/%s\n", path, dirname, de->d_name);
|
||||
if(file_extension && file_extension[3] == '\0') {
|
||||
de->d_name[(file_extension - de->d_name) + 1] = '\0';
|
||||
bpy_import_module(de->d_name, reload);
|
||||
}
|
||||
}
|
||||
|
||||
if(err==-1) {
|
||||
BPy_errors_to_report(NULL);
|
||||
fprintf(stderr, "unable to import %s/%s\n", dirname, de->d_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user