-- Stephane Soppera (thanks) reported libc stat function fails for paths ending with "\" under win with free VC++ compiler toolkit 2003:
    removed final '/' (BLI_make_file_string changes the '/' to '\\\\' for win) slashes from relevant paths, that should take care of it .  Note: here (linux, glibc, gcc 3.3.3) stat doesn't have this problem.  Also checking if U.pythondir ends with a slash and, if so (as long as its length > 2 to), removing the slash, for the same reason.
-- small cosmetic changes in BPY_menus.c for debug msgs and in header_scripts (added a separator in the Scripts win -> Scripts menu).
This commit is contained in:
Willian Padovani Germano 2005-03-22 04:28:36 +00:00
parent a8a73e8097
commit a4b5ddb371
5 changed files with 43 additions and 36 deletions

@ -306,18 +306,28 @@ that dir info is available.
****************************************************************************/ ****************************************************************************/
void BPY_post_start_python( void ) void BPY_post_start_python( void )
{ {
PyObject *result, *dict;
char dirpath[FILE_MAXDIR]; char dirpath[FILE_MAXDIR];
char *sdir = NULL; char *sdir = NULL;
if(U.pythondir[0] != '\0' ) { if(U.pythondir[0] != '\0' ) {
char modpath[FILE_MAXDIR]; char modpath[FILE_MAXDIR];
int upyslen = strlen(U.pythondir);
/* check if user pydir ends with a slash and, if so, remove the slash
* (for eventual implementations of c library's stat function that might
* not like it) */
if (upyslen > 2) { /* avoids doing anything if dir == '//' */
char ending = U.pythondir[upyslen - 1];
if (ending == '/' || ending == '\\')
U.pythondir[upyslen - 1] = '\0';
}
BLI_strncpy(dirpath, U.pythondir, FILE_MAXDIR); BLI_strncpy(dirpath, U.pythondir, FILE_MAXDIR);
BLI_convertstringcode(dirpath, G.sce, 0); BLI_convertstringcode(dirpath, G.sce, 0);
syspath_append(dirpath); /* append to module search path */ syspath_append(dirpath); /* append to module search path */
BLI_make_file_string("/", modpath, dirpath, "bpymodules/"); BLI_make_file_string("/", modpath, dirpath, "bpymodules");
if (BLI_exists(modpath)) syspath_append(modpath); if (BLI_exists(modpath)) syspath_append(modpath);
} }
@ -326,25 +336,13 @@ void BPY_post_start_python( void )
syspath_append(sdir); syspath_append(sdir);
BLI_make_file_string("/", dirpath, sdir, "bpymodules/"); BLI_make_file_string("/", dirpath, sdir, "bpymodules");
if (BLI_exists(dirpath)) syspath_append(dirpath); if (BLI_exists(dirpath)) syspath_append(dirpath);
} }
BPyMenu_Init( 0 ); /* get dynamic menus (registered scripts) data */ BPyMenu_Init( 0 ); /* get dynamic menus (registered scripts) data */
dict = PyDict_New( ); return;
/* here we check if the user has (some of) the expected modules */
if( dict ) {
char *s = "import chunk, gzip, math, os, struct, string";
result = PyRun_String( s, Py_eval_input, dict, dict );
if( !result ) {
PyErr_Clear( );
/*XXX print msg about this, point to readme.html */
} else
Py_DECREF( result );
Py_DECREF( dict );
}
} }
/**************************************************************************** /****************************************************************************

@ -946,9 +946,18 @@ int BPyMenu_Init( int usedir )
for( i = 0; i < PYMENU_TOTAL; i++ ) for( i = 0; i < PYMENU_TOTAL; i++ )
BPyMenuTable[i] = NULL; BPyMenuTable[i] = NULL;
if( U.pythondir[0] == '\0' || if( DEBUG )
strcmp(U.pythondir, "/") == 0 || strcmp(U.pythondir, "//") == 0) fprintf(stdout, "\nRegistering scripts in Blender menus ...\n\n" );
{
if( U.pythondir[0] == '\0') {
upydir = NULL;
}
else if (strcmp(U.pythondir, "/") == 0 || strcmp(U.pythondir, "//") == 0) {
/* these are not accepted to prevent possible slight slowdowns on startup;
* they should not be used as user defined scripts dir, anyway, also from
* speed considerations, since they'd not be dedicated scripts dirs */
if (DEBUG) fprintf(stderr,
"BPyMenus: invalid user defined Python scripts dir: \"/\" or \"//\".\n");
upydir = NULL; upydir = NULL;
} }
else { else {
@ -968,7 +977,7 @@ int BPyMenu_Init( int usedir )
fprintf(stderr, fprintf(stderr,
"\nDefault scripts dir: %s:\n%s\n", dirname, strerror(errno)); "\nDefault scripts dir: %s:\n%s\n", dirname, strerror(errno));
if( upydir ) if( upydir )
fprintf(stderr, fprintf(stdout,
"Getting scripts menu data from user defined dir: %s.\n", "Getting scripts menu data from user defined dir: %s.\n",
upythondir ); upythondir );
} }
@ -981,6 +990,7 @@ int BPyMenu_Init( int usedir )
if( stat_dir2 < 0 ) { if( stat_dir2 < 0 ) {
time_dir2 = 0; time_dir2 = 0;
upydir = NULL;
if( DEBUG ) if( DEBUG )
fprintf(stderr, "\nUser defined scripts dir: %s:\n%s.\n", fprintf(stderr, "\nUser defined scripts dir: %s:\n%s.\n",
upythondir, strerror( errno ) ); upythondir, strerror( errno ) );
@ -990,7 +1000,7 @@ int BPyMenu_Init( int usedir )
To have scripts in menus, please add them to the default scripts dir:\n\ To have scripts in menus, please add them to the default scripts dir:\n\
%s\n\ %s\n\
and / or go to 'Info window -> File Paths tab' and set a valid path for\n\ and / or go to 'Info window -> File Paths tab' and set a valid path for\n\
the user defined scripts dir.\n", dirname ); the user defined Python scripts dir.\n", dirname );
return -1; return -1;
} }
} }
@ -1005,9 +1015,6 @@ the user defined scripts dir.\n", dirname );
return -1; return -1;
} }
if( DEBUG )
fprintf(stderr, "\nRegistering scripts in Blender menus ...\n\n" );
if (usedir) stat_file = -1; if (usedir) stat_file = -1;
else { /* if we're not forced to use the dir */ else { /* if we're not forced to use the dir */
char *homedir = bpy_gethome(0); char *homedir = bpy_gethome(0);
@ -1025,8 +1032,8 @@ the user defined scripts dir.\n", dirname );
{ /* file is newer */ { /* file is newer */
stat_file = bpymenu_CreateFromFile( ); /* -1 if an error occurred */ stat_file = bpymenu_CreateFromFile( ); /* -1 if an error occurred */
if( !stat_file && DEBUG ) if( !stat_file && DEBUG )
fprintf(stderr, fprintf(stdout,
"Getting menu data for scripts from file: %s\n\n", fname ); "Getting menu data for scripts from file:\n%s\n\n", fname );
} }
else stat_file = -1; else stat_file = -1;
} }
@ -1035,11 +1042,11 @@ the user defined scripts dir.\n", dirname );
if( stat_file == -1 ) { /* use dirs */ if( stat_file == -1 ) { /* use dirs */
if( DEBUG ) { if( DEBUG ) {
fprintf(stderr, fprintf(stdout,
"Getting menu data for scripts from dir(s):\ndefault: %s\n", dirname ); "Getting menu data for scripts from dir(s):\ndefault: %s\n", dirname );
if( upydir ) if( upydir )
fprintf(stderr, "user defined: %s", upythondir ); fprintf(stdout, "user defined: %s\n", upythondir );
fprintf(stderr, "\n"); fprintf(stdout, "\n");
} }
if( stat_dir1 == 0 ) { if( stat_dir1 == 0 ) {
i = bpymenu_ParseDir( dirname, NULL, 0 ); i = bpymenu_ParseDir( dirname, NULL, 0 );

@ -228,7 +228,7 @@ static PyObject *Blender_Get( PyObject * self, PyObject * args )
char *sdir = bpy_gethome(1); char *sdir = bpy_gethome(1);
if (sdir) { if (sdir) {
BLI_make_file_string( "/", datadir, sdir, "bpydata/" ); BLI_make_file_string( "/", datadir, sdir, "bpydata" );
if( BLI_exists( datadir ) ) if( BLI_exists( datadir ) )
ret = PyString_FromString( datadir ); ret = PyString_FromString( datadir );
} }
@ -244,7 +244,7 @@ static PyObject *Blender_Get( PyObject * self, PyObject * args )
if (BLI_exists(upydir)) { if (BLI_exists(upydir)) {
char udatadir[FILE_MAXDIR]; char udatadir[FILE_MAXDIR];
BLI_make_file_string("/", udatadir, upydir, "bpydata/"); BLI_make_file_string("/", udatadir, upydir, "bpydata");
if (BLI_exists(udatadir)) if (BLI_exists(udatadir))
ret = PyString_FromString(udatadir); ret = PyString_FromString(udatadir);

@ -81,12 +81,12 @@ char *bpy_gethome(int append_scriptsdir)
if( strstr( s, ".blender" ) ) if( strstr( s, ".blender" ) )
PyOS_snprintf( homedir, FILE_MAXDIR, s ); PyOS_snprintf( homedir, FILE_MAXDIR, s );
else else
BLI_make_file_string( "/", homedir, s, ".blender/" ); BLI_make_file_string( "/", homedir, s, ".blender" );
/* if userhome/.blender/ exists, return it */ /* if userhome/.blender/ exists, return it */
if( BLI_exists( homedir ) ) { if( BLI_exists( homedir ) ) {
if (append_scriptsdir) { if (append_scriptsdir) {
BLI_make_file_string("/", scriptsdir, homedir, "scripts/"); BLI_make_file_string("/", scriptsdir, homedir, "scripts");
if (BLI_exists (scriptsdir)) return scriptsdir; if (BLI_exists (scriptsdir)) return scriptsdir;
} }
else return homedir; else return homedir;
@ -99,11 +99,11 @@ char *bpy_gethome(int append_scriptsdir)
i = s - bprogname + 1; i = s - bprogname + 1;
PyOS_snprintf( bprogdir, i, bprogname ); PyOS_snprintf( bprogdir, i, bprogname );
BLI_make_file_string( "/", homedir, bprogdir, ".blender/" ); BLI_make_file_string( "/", homedir, bprogdir, ".blender" );
if (BLI_exists(homedir)) { if (BLI_exists(homedir)) {
if (append_scriptsdir) { if (append_scriptsdir) {
BLI_make_file_string("/", scriptsdir, homedir, "scripts/"); BLI_make_file_string("/", scriptsdir, homedir, "scripts");
if (BLI_exists(scriptsdir)) return scriptsdir; if (BLI_exists(scriptsdir)) return scriptsdir;
} }
else return homedir; else return homedir;
@ -111,7 +111,7 @@ char *bpy_gethome(int append_scriptsdir)
/* last try for scripts dir: blender in cvs dir, scripts/ inside release/: */ /* last try for scripts dir: blender in cvs dir, scripts/ inside release/: */
if (append_scriptsdir) { if (append_scriptsdir) {
BLI_make_file_string("/", scriptsdir, bprogdir, "release/scripts/"); BLI_make_file_string("/", scriptsdir, bprogdir, "release/scripts");
if (BLI_exists(scriptsdir)) return scriptsdir; if (BLI_exists(scriptsdir)) return scriptsdir;
} }

@ -138,6 +138,8 @@ static uiBlock *script_scriptsmenu(void *arg_unused)
uiDefIconTextBlockBut(block, script_scripts_submenus, (void *)i, ICON_RIGHTARROW_THIN, BPyMenu_group_itoa(i), 0, yco-=20, menuwidth, 19, ""); uiDefIconTextBlockBut(block, script_scripts_submenus, (void *)i, ICON_RIGHTARROW_THIN, BPyMenu_group_itoa(i), 0, yco-=20, menuwidth, 19, "");
} }
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Update Menus", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "Use when a scripts folder or its contents are modified"); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Update Menus", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "Use when a scripts folder or its contents are modified");
if(curarea->headertype==HEADERTOP) { if(curarea->headertype==HEADERTOP) {