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:
authorWillian Padovani Germano <wpgermano@gmail.com>2005-03-21 08:26:52 +0300
committerWillian Padovani Germano <wpgermano@gmail.com>2005-03-21 08:26:52 +0300
commit62147bba3030ed79dd37a7d7f63d031ff263570e (patch)
tree6926313e7f15798337aa925752eb9e50ecd75721 /source/blender
parent12107e6af2eeeee8a993eca3963ef7bae3eeffe9 (diff)
Scripts (making some changes to the scripts dir):
- moved bpydata/ to scripts/bpydata/ and added a config/ subdir to it; - created scripts/bpymodules for py modules (also got rid of those "mod_"'s appended to the files); - updated scripts accordingly. This will require you to "reinstall" (just copy the scripts/ dir over your older one) if you have a .blender/scripts/ dir somewhere. Otherwise some scripts won't work. You can use the updated "Help->System->System Information" script here to check all is fine. An installer script yet to be written will help users with these issues, specially to make the user defined dir have the same structure expected from the default scripts dir, so the basic facilities (module search; saved config data; scripts: installer, help browser, config editor) are also available for a user's own collection of written and downloaded scripts. BPython: - slikdigit's crash was because he had no <home or blender exe location>/.blender/: proper check added and also now if all else fails the <cvsblender>/release/scripts/ dir is also searched for scripts. All this registration dirs stuff is a little messy (installation!), so please report any troubles (I only tested on linux). - slight change in error report in BPY_interface.c's BPY_menu_do_python; remembering to set globaldict pointer to NULL there, too. - moved bpy_gethome() to EXPP_interface.[ch] - "//" as user defined python dir is ignored while looking for scripts, considering it's only a default some users use, not really meant for a scripts dir.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/python/BPY_extern.h1
-rw-r--r--source/blender/python/BPY_interface.c112
-rw-r--r--source/blender/python/BPY_menus.c226
-rw-r--r--source/blender/python/BPY_menus.h6
-rw-r--r--source/blender/python/api2_2x/Blender.c17
-rw-r--r--source/blender/python/api2_2x/EXPP_interface.c68
-rw-r--r--source/blender/python/api2_2x/EXPP_interface.h6
7 files changed, 281 insertions, 155 deletions
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h
index ab981939987..dbf464de019 100644
--- a/source/blender/python/BPY_extern.h
+++ b/source/blender/python/BPY_extern.h
@@ -78,7 +78,6 @@ extern "C" {
void init_syspath( int first_time );
void syspath_append( char *dir );
- char *bpy_gethome( int append_scriptsdir );
#ifdef __cplusplus
} /* extern "C" */
diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c
index 0034a65b547..fa38aa8c4c1 100644
--- a/source/blender/python/BPY_interface.c
+++ b/source/blender/python/BPY_interface.c
@@ -147,9 +147,6 @@ void BPY_start_python( int argc, char **argv )
* rest of our init msgs.
*/
- if( first_time ) { /* so it only prints msg on first_time */
- }
-
Py_Initialize( );
PySys_SetArgv( argc_copy, argv_copy );
@@ -211,7 +208,7 @@ void init_syspath( int first_time )
PyObject *mod, *d;
PyObject *p;
char *c, *progname;
- char execdir[FILE_MAXDIR + FILE_MAXFILE]; /*defines from DNA_space_types.h */
+ char execdir[FILE_MAXDIR]; /*defines from DNA_space_types.h */
int n;
@@ -310,9 +307,28 @@ that dir info is available.
void BPY_post_start_python( void )
{
PyObject *result, *dict;
+ char dirpath[FILE_MAXDIR];
+ char *sdir = NULL;
+
+ if(U.pythondir[0] != '\0' ) {
+ char modpath[FILE_MAXDIR];
+
+ BLI_strncpy(dirpath, U.pythondir, FILE_MAXDIR);
+ BLI_convertstringcode(dirpath, G.sce, 0);
+ syspath_append(dirpath); /* append to module search path */
+
+ BLI_make_file_string("/", modpath, dirpath, "bpymodules/");
+ if (BLI_exists(modpath)) syspath_append(modpath);
+ }
+
+ sdir = bpy_gethome(1);
+ if (sdir) {
- if( U.pythondir && U.pythondir[0] != '\0' )
- syspath_append( U.pythondir ); /* append to module search path */
+ syspath_append(sdir);
+
+ BLI_make_file_string("/", dirpath, sdir, "bpymodules/");
+ if (BLI_exists(dirpath)) syspath_append(dirpath);
+ }
BPyMenu_Init( 0 ); /* get dynamic menus (registered scripts) data */
@@ -642,15 +658,29 @@ int BPY_menu_do_python( short menutype, int event )
}
}
- if( !pyarg ) { /* no submenus */
+ if( !pyarg ) { /* no submenus */
Py_INCREF( Py_None );
pyarg = Py_None;
}
- if( pym->dir ) /* script is in U.pythondir */
- BLI_make_file_string( "/", filestr, U.pythondir, pym->filename );
- else /* script is in ~/.blender/scripts/ */
- BLI_make_file_string( "/", filestr, bpy_gethome(1), pym->filename );
+ if( pym->dir ) { /* script is in U.pythondir */
+ char upythondir[FILE_MAXDIR];
+
+ /* dirs in Blender can be "//", which has a special meaning */
+ BLI_strncpy(upythondir, U.pythondir, FILE_MAXDIR);
+ BLI_convertstringcode(upythondir, G.sce, 0); /* if so, this expands it */
+ BLI_make_file_string( "/", filestr, upythondir, pym->filename );
+ }
+ else { /* script is in default scripts dir */
+ char *scriptsdir = bpy_gethome(1);
+
+ if (!scriptsdir) {
+ printf("Error loading script: can't find default scripts dir!");
+ return 0;
+ }
+
+ BLI_make_file_string( "/", filestr, scriptsdir, pym->filename );
+ }
fp = fopen( filestr, "rb" );
if( !fp ) {
@@ -782,8 +812,8 @@ int BPY_menu_do_python( short menutype, int event )
if( !py_res ) { /* Failed execution of the script */
BPY_Err_Handle( script->id.name + 2 );
- PyErr_Print( );
ReleaseGlobalDictionary( py_dict );
+ script->py_globaldict = NULL;
if( G.main->script.first )
free_libblock( &G.main->script, script );
error( "Python script error: check console" );
@@ -1344,61 +1374,3 @@ void init_ourImport( void )
d = PyModule_GetDict( m );
PyDict_SetItemString( d, "__import__", import );
}
-
-/* this makes sure BLI_gethome() returns a path with '.blender' appended
- * Besides, this function now either returns userhome/.blender (if it exists)
- * or blenderInstallDir/.blender/ otherwise.
- * If append_scriptsdir is non NULL, "scripts/" is appended to the dir, to
- * get the path to the scripts folder.
- * Finally, if searched dir doesn't exist, NULL is returned.
-*/
-char *bpy_gethome(int append_scriptsdir)
-{
- static char homedir[FILE_MAXDIR];
- static char scriptsdir[FILE_MAXDIR];
- char bprogdir[FILE_MAXDIR];
- char *s;
- int i;
-
- if (append_scriptsdir) {
- if (scriptsdir[0] != '\0')
- return scriptsdir;
- }
- else if (homedir[0] != '\0')
- return homedir;
-
- s = BLI_gethome( );
-
- if( strstr( s, ".blender" ) )
- PyOS_snprintf( homedir, FILE_MAXDIR, s );
- else
- BLI_make_file_string( "/", homedir, s, ".blender/" );
-
- /* if userhome/.blender/ exists, return it */
- if( BLI_exists( homedir ) ) {
- if (append_scriptsdir) {
- BLI_make_file_string("/", scriptsdir, homedir, "scripts/");
- if (BLI_exists (scriptsdir)) return scriptsdir;
- }
- else return homedir;
- }
-
- /* otherwise, use argv[0] (bprogname) to get .blender/ in
- * Blender's installation dir */
- s = BLI_last_slash( bprogname );
-
- i = s - bprogname + 1;
-
- PyOS_snprintf( bprogdir, i, bprogname );
- BLI_make_file_string( "/", homedir, bprogdir, ".blender/" );
-
- if (BLI_exists(homedir)) {
- if (append_scriptsdir) {
- BLI_make_file_string("/", scriptsdir, homedir, "scripts/");
- if (BLI_exists(scriptsdir)) return scriptsdir;
- }
- else return homedir;
- }
-
- return NULL;
-}
diff --git a/source/blender/python/BPY_menus.c b/source/blender/python/BPY_menus.c
index c75b4c470fe..a35c7470841 100644
--- a/source/blender/python/BPY_menus.c
+++ b/source/blender/python/BPY_menus.c
@@ -63,6 +63,7 @@
#include "BPY_extern.h"
#include "BPY_menus.h"
+#include "api2_2x/EXPP_interface.h" /* for bpy_gethome() */
#include <errno.h>
@@ -337,8 +338,14 @@ static BPyMenu *bpymenu_AddEntry( short group, short version, char *name,
next = menu->next;
} else { /* they are in the same dir */
if (DEBUG) {
- printf("\nWarning: script %s's menu name is already in use.\n", fname );
- printf("Edit the script and change its Name: '%s' field, please.\n" "Note: if you really want two scripts in the same menu with\n" "the same name, keep one in the default dir and the other in\n" "the user defined dir, where it will take precedence.\n", name);
+ fprintf(stderr, "\n\
+Warning: script %s's menu name is already in use.\n\
+Edit the script and change its \n\
+Name: '%s'\n\
+field, please.\n\
+Note: if you really want to have two scripts for the same menu with\n\
+the same name, keep one in the default dir and the other in\n\
+the user defined dir (only the later will be registered).\n", fname, name);
}
return NULL;
}
@@ -422,6 +429,7 @@ static int bpymenu_CreateFromFile( void )
{
FILE *fp;
char line[255], w1[255], w2[255], tooltip[255], *tip;
+ char *homedir = NULL;
int parsing, version, is_userdir;
short group;
BPyMenu *pymenu = NULL;
@@ -432,13 +440,21 @@ static int bpymenu_CreateFromFile( void )
BPyMenuTable[group] = NULL;
/* let's try to open the file with bpymenu data */
- BLI_make_file_string( "/", line, bpy_gethome(0), BPYMENU_DATAFILE );
+ homedir = bpy_gethome(0);
+ if (!homedir) {
+ if( DEBUG )
+ fprintf(stderr,
+ "BPyMenus error: couldn't open config file Bpymenus: no home dir.\n");
+ return -1;
+ }
+
+ BLI_make_file_string( "/", line, homedir, BPYMENU_DATAFILE );
fp = fopen( line, "rb" );
if( !fp ) {
if( DEBUG )
- printf( "BPyMenus error: couldn't open config file %s.\n", line );
+ fprintf(stderr, "BPyMenus error: couldn't open config file %s.\n", line );
return -1;
}
@@ -449,7 +465,11 @@ static int bpymenu_CreateFromFile( void )
w1[0] = '\0';
fscanf( fp, "# User defined scripts dir: %[^\n]\n", w1 );
if( w1 ) {
- if( strcmp( w1, U.pythondir ) != 0 )
+ char upythondir[FILE_MAXDIR];
+
+ BLI_strncpy(upythondir, U.pythondir, FILE_MAXDIR);
+ BLI_convertstringcode(upythondir, G.sce, 0);
+ if( strcmp( w1, upythondir ) != 0 )
return -1;
w1[0] = '\0';
}
@@ -471,7 +491,9 @@ static int bpymenu_CreateFromFile( void )
if( parsing == 1 ) { /* got menu group string */
group = bpymenu_group_atoi( w1 );
if( group < 0 && DEBUG ) { /* invalid type */
- printf( "BPyMenus error parsing config file: wrong group: %s, " "will use 'Misc'.\n", w1 );
+ fprintf(stderr,
+ "BPyMenus error parsing config file: wrong group: %s,\n\
+will use 'Misc'.\n", w1 );
}
} else
continue;
@@ -526,15 +548,24 @@ static void bpymenu_WriteDataFile( void )
BPyMenu *pymenu;
BPySubMenu *smenu;
FILE *fp;
- char fname[FILE_MAXDIR + FILE_MAXFILE];
+ char fname[FILE_MAXDIR], *homedir;
int i;
- BLI_make_file_string( "/", fname, bpy_gethome(0), BPYMENU_DATAFILE );
+ homedir = bpy_gethome(0);
+
+ if (!homedir) {
+ if( DEBUG )
+ fprintf(stderr,
+ "BPyMenus error: couldn't write Bpymenus file: no home dir.\n\n");
+ return;
+ }
+
+ BLI_make_file_string( "/", fname, homedir, BPYMENU_DATAFILE );
fp = fopen( fname, "w" );
if( !fp ) {
if( DEBUG )
- printf( "BPyMenus error: couldn't write %s file.",
+ fprintf(stderr, "BPyMenus error: couldn't write %s file.\n\n",
fname );
return;
}
@@ -542,8 +573,15 @@ static void bpymenu_WriteDataFile( void )
fprintf( fp,
"# Blender: registered menu entries for bpython scripts\n" );
- if( U.pythondir[0] != '\0' && strcmp(U.pythondir, "/") != 0)
- fprintf( fp, "# User defined scripts dir: %s\n", U.pythondir );
+ if (U.pythondir[0] != '\0' &&
+ strcmp(U.pythondir, "/") != 0 && strcmp(U.pythondir, "//") != 0)
+ {
+ char upythondir[FILE_MAXDIR];
+
+ BLI_strncpy(upythondir, U.pythondir, FILE_MAXDIR);
+ BLI_convertstringcode(upythondir, G.sce, 0);
+ fprintf( fp, "# User defined scripts dir: %s\n", upythondir );
+ }
for( i = 0; i < PYMENU_TOTAL; i++ ) {
pymenu = BPyMenuTable[i];
@@ -777,7 +815,7 @@ static int bpymenu_ParseDir(char *dirname, char *parentdir, int is_userdir )
struct dirent *de;
struct stat status;
char *file_extension;
- char path[FILE_MAXFILE + FILE_MAXDIR];
+ char path[FILE_MAXDIR];
char subdir[FILE_MAXDIR];
char *s = NULL;
@@ -827,23 +865,27 @@ static int bpymenu_ParseDir(char *dirname, char *parentdir, int is_userdir )
Dir_Depth++;
if (Dirs_Number > MAX_DIR_NUMBER) {
if (DEBUG) {
- fprintf(stderr, "BPyMenus error: Too many subdirs.\n");
+ fprintf(stderr, "BPyMenus error: too many subdirs.\n");
}
+ closedir(dir);
return -1;
}
else if (Dir_Depth > MAX_DIR_DEPTH) {
- Dir_Depth--;
if (DEBUG)
fprintf(stderr,
- "BPyMenus error: Max depth reached traversing dirs.\n");
- break;
+ "BPyMenus error: max depth reached traversing dir tree.\n");
+ closedir(dir);
+ return -1;
}
s = de->d_name;
if (parentdir) {
BLI_make_file_string(NULL, subdir, parentdir, de->d_name);
s = subdir;
}
- if (bpymenu_ParseDir(path, s, is_userdir) == -1) return -1;
+ if (bpymenu_ParseDir(path, s, is_userdir) == -1) {
+ closedir(dir);
+ return -1;
+ }
}
}
@@ -889,112 +931,148 @@ static int bpymenu_GetStatMTime( char *name, int is_file, time_t * mtime )
*/
int BPyMenu_Init( int usedir )
{
- char fname[FILE_MAXDIR + FILE_MAXFILE];
+ char fname[FILE_MAXDIR];
char dirname[FILE_MAXDIR];
- char *upydir = U.pythondir;
- time_t tdir1 = 0, tdir2 = 0, tfile = 0;
- int res1 = 0, res2 = 0, resf = 0;
+ char upythondir[FILE_MAXDIR];
+ char *upydir = U.pythondir, *sdir = NULL;
+ time_t time_dir1 = 0, time_dir2 = 0, time_file = 0;
+ int stat_dir1 = 0, stat_dir2 = 0, stat_file = 0;
+ int i;
DEBUG = G.f & G_DEBUG; /* is Blender in debug mode (started with -d) ? */
/* init global bpymenu table (it is a list of pointers to struct BPyMenus
* for each available group: import, export, etc.) */
- for( res1 = 0; res1 < PYMENU_TOTAL; res1++ )
- BPyMenuTable[res1] = NULL;
+ for( i = 0; i < PYMENU_TOTAL; i++ )
+ BPyMenuTable[i] = NULL;
- if( U.pythondir[0] == '\0' || strcmp(U.pythondir, "/") == 0)
+ if( U.pythondir[0] == '\0' ||
+ strcmp(U.pythondir, "/") == 0 || strcmp(U.pythondir, "//") == 0)
+ {
upydir = NULL;
+ }
+ else {
+ BLI_strncpy(upythondir, upydir, FILE_MAXDIR);
+ BLI_convertstringcode(upythondir, G.sce, 0);
+ }
- BLI_strncpy(dirname, bpy_gethome(1), FILE_MAXDIR);
-
- res1 = bpymenu_GetStatMTime( dirname, 0, &tdir1 );
-
- if( res1 < 0 ) {
- tdir1 = 0;
- if( DEBUG ) {
- printf( "\nDefault scripts dir: %s:\n%s\n", dirname,
- strerror( errno ) );
- if( upydir )
- printf( "Getting scripts menu data from user defined dir: %s.\n", upydir );
+ sdir = bpy_gethome(1);
+
+ if (sdir) {
+ BLI_strncpy(dirname, sdir, FILE_MAXDIR);
+ stat_dir1 = bpymenu_GetStatMTime( dirname, 0, &time_dir1 );
+
+ if( stat_dir1 < 0 ) {
+ time_dir1 = 0;
+ if( DEBUG ) {
+ fprintf(stderr,
+ "\nDefault scripts dir: %s:\n%s\n", dirname, strerror(errno));
+ if( upydir )
+ fprintf(stderr,
+ "Getting scripts menu data from user defined dir: %s.\n",
+ upythondir );
+ }
}
- } else {
- syspath_append( dirname );
}
+ else stat_dir1 = -1;
if( upydir ) {
- res2 = bpymenu_GetStatMTime( U.pythondir, 0, &tdir2 );
+ stat_dir2 = bpymenu_GetStatMTime( upythondir, 0, &time_dir2 );
- if( res2 < 0 ) {
- tdir2 = 0;
+ if( stat_dir2 < 0 ) {
+ time_dir2 = 0;
if( DEBUG )
- printf( "\nUser defined scripts dir: %s:\n%s.\n", upydir, strerror( errno ) );
- if( res1 < 0 ) {
+ fprintf(stderr, "\nUser defined scripts dir: %s:\n%s.\n",
+ upythondir, strerror( errno ) );
+ if( stat_dir1 < 0 ) {
if( DEBUG )
- printf( "To have scripts in menus, please add them to the" "default scripts dir: %s\n" "and/or go to 'Info window -> File Paths tab' and set a valid\n" "path for the user defined scripts dir.\n", dirname );
+ fprintf(stderr, "\
+To have scripts in menus, please add them to the default scripts dir:\n\
+%s\n\
+and / or go to 'Info window -> File Paths tab' and set a valid path for\n\
+the user defined scripts dir.\n", dirname );
return -1;
}
}
- } else
- res2 = -1;
+ }
+ else stat_dir2 = -1;
- if( ( res1 < 0 ) && ( res2 < 0 ) ) {
+ if( ( stat_dir1 < 0 ) && ( stat_dir2 < 0 ) ) {
if( DEBUG ) {
- printf( "\nCannot register scripts in menus, no scripts dir" " available.\nExpected default dir in %s .\n", dirname );
+ fprintf(stderr, "\nCannot register scripts in menus, no scripts dir"
+ " available.\nExpected default dir at: %s \n", dirname );
}
return -1;
}
if( DEBUG )
- printf( "\nRegistering scripts in Blender menus ...\n\n" );
+ fprintf(stderr, "\nRegistering scripts in Blender menus ...\n\n" );
- if (usedir) resf = -1;
+ if (usedir) stat_file = -1;
else { /* if we're not forced to use the dir */
- BLI_make_file_string( "/", fname, bpy_gethome(0),
- BPYMENU_DATAFILE );
- resf = bpymenu_GetStatMTime( fname, 1, &tfile );
- if( resf < 0 )
- tfile = 0;
+ char *homedir = bpy_gethome(0);
+
+ if (homedir) {
+ BLI_make_file_string( "/", fname, homedir, BPYMENU_DATAFILE );
+ stat_file = bpymenu_GetStatMTime( fname, 1, &time_file );
+ if( stat_file < 0 )
+ time_file = 0;
/* comparing dates */
- if( ( tfile > tdir1 ) && ( tfile > tdir2 ) && !resf ) { /* file is newer */
- resf = bpymenu_CreateFromFile( ); /* -1 if an error occurred */
- if( !resf && DEBUG )
- printf( "Getting menu data for scripts from file: %s\n\n", fname );
+ if((stat_file == 0)
+ && (time_file > time_dir1) && (time_file > time_dir2))
+ { /* file is newer */
+ stat_file = bpymenu_CreateFromFile( ); /* -1 if an error occurred */
+ if( !stat_file && DEBUG )
+ fprintf(stderr,
+ "Getting menu data for scripts from file: %s\n\n", fname );
+ }
+ else stat_file = -1;
}
- else resf = -1; /* -1 to use dirs: didn't use file or it was corrupted */
+ else stat_file = -1; /* -1 to use dirs: didn't use file or it was corrupted */
}
- if( resf == -1 ) { /* use dirs */
+ if( stat_file == -1 ) { /* use dirs */
if( DEBUG ) {
- printf( "Getting menu data for scripts from dir(s):\n%s\n\n", dirname );
+ fprintf(stderr,
+ "Getting menu data for scripts from dir(s):\ndefault: %s\n", dirname );
if( upydir )
- printf( "%s\n", upydir );
+ fprintf(stderr, "user defined: %s", upythondir );
+ fprintf(stderr, "\n");
+ }
+ if( stat_dir1 == 0 ) {
+ i = bpymenu_ParseDir( dirname, NULL, 0 );
+ if (i == -1 && DEBUG)
+ fprintf(stderr, "Default scripts dir does not seem valid.\n\n");
}
- if( res1 == 0 )
- bpymenu_ParseDir( dirname, NULL, 0 );
- if( res2 == 0 ) {
+ if( stat_dir2 == 0 ) {
BLI_strncpy(dirname, U.pythondir, FILE_MAXDIR);
BLI_convertstringcode(dirname, G.sce, 0);
- bpymenu_ParseDir( dirname, NULL, 1 );
+ i = bpymenu_ParseDir( dirname, NULL, 1 );
+ if (i == -1 && DEBUG)
+ fprintf(stderr, "User defined scripts dir does not seem valid.\n\n");
}
/* check if we got any data */
- for( res1 = 0; res1 < PYMENU_TOTAL; res1++ )
- if( BPyMenuTable[res1] )
+ for( i = 0; i < PYMENU_TOTAL; i++ )
+ if( BPyMenuTable[i] )
break;
/* if we got, recreate the file */
- if( res1 < PYMENU_TOTAL )
+ if( i < PYMENU_TOTAL )
bpymenu_WriteDataFile( );
else if( DEBUG ) {
- printf( "\nWarning: Registering scripts in menus -- no info found.\n" "Either your scripts dirs have no .py scripts or the scripts\n" "don't have a header with registration data.\n" "Default scripts dir is: %s\n", dirname );
+ fprintf(stderr, "\n\
+Warning: Registering scripts in menus -- no info found.\n\
+Either your scripts dirs have no .py scripts or the scripts\n\
+don't have a header with registration data.\n\
+Default scripts dir is:\n\
+%s\n", dirname );
if( upydir )
- printf( "User defined scripts dir is: %s\n",
- upydir );
+ fprintf(stderr, "User defined scripts dir is: %s\n",
+ upythondir );
}
-
- return 0;
}
return 0;
diff --git a/source/blender/python/BPY_menus.h b/source/blender/python/BPY_menus.h
index 8848ba75a45..52ab5e85e4a 100644
--- a/source/blender/python/BPY_menus.h
+++ b/source/blender/python/BPY_menus.h
@@ -39,7 +39,7 @@
* slots are called groups here (Import, Export, etc). This is how it works:
* - scripts at dirs user pref U.pythondir and .blender/scripts/ are scanned
* for registration info.
- * - this data is also saved to a .Bpymenus file at the user's home dir and
+ * - this data is also saved to a Bpymenus file at the user's .blender/ dir and
* only re-created when the scripts folder gets modified.
* - on start-up Blender uses this info to fill a table, which is used to
* create the menu entries when they are needed (see header_info.c or
@@ -91,7 +91,7 @@ typedef enum {
PYMENU_UV,/* UV editing tools, to go in UV/Image editor space, 'UV' menu */
PYMENU_WIZARDS,/* complex 'app' scripts */
- /* entries put below don't appear at the Scripts win->Scripts menu;
+ /* entries put after Wizards don't appear at the Scripts win->Scripts menu;
* see define right below */
PYMENU_FACESELECT,
@@ -102,7 +102,7 @@ typedef enum {
PYMENU_TOTAL
} PYMENUHOOKS;
-#define PYMENU_SCRIPTS_MENU_TOTAL PYMENU_FACESELECT
+#define PYMENU_SCRIPTS_MENU_TOTAL (PYMENU_WIZARDS + 1)
/* BPyMenuTable holds all registered pymenus, as linked lists for each menu
* where they can appear (see PYMENUHOOKS enum above).
diff --git a/source/blender/python/api2_2x/Blender.c b/source/blender/python/api2_2x/Blender.c
index 342c167530f..017ede81b80 100644
--- a/source/blender/python/api2_2x/Blender.c
+++ b/source/blender/python/api2_2x/Blender.c
@@ -60,9 +60,10 @@
#include <BKE_ipo.h>
#include <blendef.h>
+#include "EXPP_interface.h" /* for bpy_gethome() */
#include "gen_utils.h"
#include "modules.h"
-#include "../BPY_extern.h" /* for bpy_gethome() */
+#include "../BPY_extern.h" /* BPY_txt_do_python_Text */
#include "../BPY_menus.h" /* to update menus */
/**********************************************************/
@@ -217,19 +218,21 @@ static PyObject *Blender_Get( PyObject * self, PyObject * args )
ret = PyString_FromString( G.sce );
else if( StringEqual( str, "homedir" ) ) {
char *hdir = bpy_gethome(0);
- if( BLI_exists( hdir ))
+ if( hdir && BLI_exists( hdir ))
ret = PyString_FromString( hdir );
else
ret = EXPP_incr_ret( Py_None );
}
else if( StringEqual( str, "datadir" ) ) {
char datadir[FILE_MAXDIR];
+ char *sdir = bpy_gethome(1);
- BLI_make_file_string( "/", datadir, bpy_gethome(1), "bpydata/" );
- if( BLI_exists( datadir ) )
- ret = PyString_FromString( datadir );
- else
- ret = EXPP_incr_ret( Py_None );
+ if (sdir) {
+ BLI_make_file_string( "/", datadir, sdir, "bpydata/" );
+ if( BLI_exists( datadir ) )
+ ret = PyString_FromString( datadir );
+ }
+ if (!ret) ret = EXPP_incr_ret( Py_None );
}
else if(StringEqual(str, "udatadir")) {
if (U.pythondir[0] != '\0') {
diff --git a/source/blender/python/api2_2x/EXPP_interface.c b/source/blender/python/api2_2x/EXPP_interface.c
index 2a03936c3f7..0dd363146e7 100644
--- a/source/blender/python/api2_2x/EXPP_interface.c
+++ b/source/blender/python/api2_2x/EXPP_interface.c
@@ -37,15 +37,83 @@
#include <BKE_global.h>
#include <BKE_library.h>
#include <BKE_main.h>
+#include <BLI_blenlib.h>
+#include <DNA_space_types.h> /* for FILE_MAXDIR, FILE_MAXFILE */
#include "EXPP_interface.h"
#include "Blender.h"
#include "Registry.h"
#include "gen_utils.h"
+extern char bprogname[]; /* argv[0] from creator.c */
void initBlenderApi2_2x( void )
{
g_blenderdict = NULL;
M_Blender_Init( );
}
+
+/* this makes sure BLI_gethome() returns a path with '.blender' appended
+ * Besides, this function now either returns userhome/.blender (if it exists)
+ * or blenderInstallDir/.blender/ otherwise (can also be cvs dir).
+ * If append_scriptsdir is non NULL, "scripts/" is appended to the dir, to
+ * get the path to the scripts folder ("release/scripts/" if cvs dir).
+ * Finally, if all else fails BLI_gethome() is returned
+ * (or NULL if append_scriptdir != 0).
+*/
+char *bpy_gethome(int append_scriptsdir)
+{
+ static char homedir[FILE_MAXDIR];
+ static char scriptsdir[FILE_MAXDIR];
+ char bprogdir[FILE_MAXDIR];
+ char *s;
+ int i;
+
+ if (append_scriptsdir) {
+ if (scriptsdir[0] != '\0')
+ return scriptsdir;
+ }
+ else if (homedir[0] != '\0')
+ return homedir;
+
+ s = BLI_gethome();
+
+ if( strstr( s, ".blender" ) )
+ PyOS_snprintf( homedir, FILE_MAXDIR, s );
+ else
+ BLI_make_file_string( "/", homedir, s, ".blender/" );
+
+ /* if userhome/.blender/ exists, return it */
+ if( BLI_exists( homedir ) ) {
+ if (append_scriptsdir) {
+ BLI_make_file_string("/", scriptsdir, homedir, "scripts/");
+ if (BLI_exists (scriptsdir)) return scriptsdir;
+ }
+ else return homedir;
+ }
+
+ /* otherwise, use argv[0] (bprogname) to get .blender/ in
+ * Blender's installation dir */
+ s = BLI_last_slash( bprogname );
+
+ i = s - bprogname + 1;
+
+ PyOS_snprintf( bprogdir, i, bprogname );
+ BLI_make_file_string( "/", homedir, bprogdir, ".blender/" );
+
+ if (BLI_exists(homedir)) {
+ if (append_scriptsdir) {
+ BLI_make_file_string("/", scriptsdir, homedir, "scripts/");
+ if (BLI_exists(scriptsdir)) return scriptsdir;
+ }
+ else return homedir;
+ }
+
+ /* last try for scripts dir: blender in cvs dir, scripts/ inside release/: */
+ if (append_scriptsdir) {
+ BLI_make_file_string("/", scriptsdir, bprogdir, "release/scripts/");
+ if (BLI_exists(scriptsdir)) return scriptsdir;
+ }
+
+ return NULL;
+}
diff --git a/source/blender/python/api2_2x/EXPP_interface.h b/source/blender/python/api2_2x/EXPP_interface.h
index ba267c5c935..3e38810143f 100644
--- a/source/blender/python/api2_2x/EXPP_interface.h
+++ b/source/blender/python/api2_2x/EXPP_interface.h
@@ -30,10 +30,16 @@
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
+#ifndef EXPP_INTERFACE_H
+#define EXPP_INTERFACE_H
+
#include <DNA_ID.h>
struct Script;
void initBlenderApi2_2x( void );
+char *bpy_gethome( int append_scriptsdir );
void discardFromBDict( char *key );
void EXPP_Library_Close( void ); /* in Library.c, used by BPY_end_python */
+
+#endif /* EXPP_INTERFACE_H */