[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29250] trunk/blender/source/blender: - [ #22492] [29159] commit breaks importing of script file that has a reload to self in it
Campbell Barton
ideasman42 at gmail.com
Sat Jun 5 23:20:00 CEST 2010
Revision: 29250
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29250
Author: campbellbarton
Date: 2010-06-05 23:19:59 +0200 (Sat, 05 Jun 2010)
Log Message:
-----------
- [#22492] [29159] commit breaks importing of script file that has a reload to self in it
broke when including the blend path in the modules filename.
- new function BLI_path_basename(), matches pythons os.path.basename().
replace a number of cases where BLI_split_dirfile was being used to get the filename only.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/image.c
trunk/blender/source/blender/blenkernel/intern/text.c
trunk/blender/source/blender/blenlib/BLI_path_util.h
trunk/blender/source/blender/blenlib/intern/bpath.c
trunk/blender/source/blender/blenlib/intern/path_util.c
trunk/blender/source/blender/editors/space_image/image_ops.c
trunk/blender/source/blender/editors/space_sequencer/sequencer_add.c
trunk/blender/source/blender/python/generic/bpy_internal_import.c
trunk/blender/source/blender/windowmanager/intern/wm_operators.c
Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c 2010-06-05 20:23:47 UTC (rev 29249)
+++ trunk/blender/source/blender/blenkernel/intern/image.c 2010-06-05 21:19:59 UTC (rev 29250)
@@ -440,10 +440,8 @@
{
/* on save, type is changed to FILE in editsima.c */
Image *ima;
- char filename[sizeof(ibuf->name)];
- BLI_split_dirfile(ibuf->name, NULL, filename);
- ima= image_alloc(filename, IMA_SRC_FILE, IMA_TYPE_IMAGE);
+ ima= image_alloc(BLI_path_basename(ibuf->name), IMA_SRC_FILE, IMA_TYPE_IMAGE);
if (ima) {
BLI_strncpy(ima->name, ibuf->name, FILE_MAX);
Modified: trunk/blender/source/blender/blenkernel/intern/text.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/text.c 2010-06-05 20:23:47 UTC (rev 29249)
+++ trunk/blender/source/blender/blenkernel/intern/text.c 2010-06-05 21:19:59 UTC (rev 29250)
@@ -232,7 +232,6 @@
int i, llen, len, res;
unsigned char *buffer;
TextLine *tmp;
- char sfile[FILE_MAXFILE];
char str[FILE_MAXDIR+FILE_MAXFILE];
struct stat st;
@@ -240,7 +239,6 @@
BLI_strncpy(str, text->name, FILE_MAXDIR+FILE_MAXFILE);
BLI_path_abs(str, G.sce);
- BLI_split_dirfile(str, NULL, sfile);
fp= fopen(str, "r");
if(fp==NULL) return 0;
@@ -331,19 +329,17 @@
unsigned char *buffer;
TextLine *tmp;
Text *ta;
- char sfile[FILE_MAXFILE];
char str[FILE_MAXDIR+FILE_MAXFILE];
struct stat st;
BLI_strncpy(str, file, FILE_MAXDIR+FILE_MAXFILE);
if (relpath) /* can be NULL (bg mode) */
BLI_path_abs(str, relpath);
- BLI_split_dirfile(str, NULL, sfile);
fp= fopen(str, "r");
if(fp==NULL) return NULL;
- ta= alloc_libblock(&G.main->text, ID_TXT, sfile);
+ ta= alloc_libblock(&G.main->text, ID_TXT, BLI_path_basename(str));
ta->id.us= 1;
ta->lines.first= ta->lines.last= NULL;
Modified: trunk/blender/source/blender/blenlib/BLI_path_util.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_path_util.h 2010-06-05 20:23:47 UTC (rev 29249)
+++ trunk/blender/source/blender/blenlib/BLI_path_util.h 2010-06-05 21:19:59 UTC (rev 29250)
@@ -53,6 +53,7 @@
void BLI_make_existing_file(char *name);
void BLI_split_dirfile(const char *string, char *dir, char *file);
void BLI_join_dirfile(char *string, const char *dir, const char *file);
+char *BLI_path_basename(char *path);
int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char *base_dir, const char *src_dir, const char *dest_dir);
void BLI_getlastdir(const char* dir, char *last, int maxlen);
int BLI_testextensie(const char *str, const char *ext);
Modified: trunk/blender/source/blender/blenlib/intern/bpath.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/bpath.c 2010-06-05 20:23:47 UTC (rev 29249)
+++ trunk/blender/source/blender/blenlib/intern/bpath.c 2010-06-05 21:19:59 UTC (rev 29250)
@@ -661,7 +661,7 @@
char filepath[FILE_MAX], *libpath;
int filesize, recur_depth;
- char dirname[FILE_MAX], filename[FILE_MAX], filename_new[FILE_MAX];
+ char dirname[FILE_MAX], filename_new[FILE_MAX];
//XXX waitcursor( 1 );
@@ -686,9 +686,8 @@
/* can the dir be opened? */
filesize = -1;
recur_depth = 0;
- BLI_split_dirfile(filepath, NULL, filename); /* the file to find */
- findFileRecursive(filename_new, dirname, filename, &filesize, &recur_depth);
+ findFileRecursive(filename_new, dirname, BLI_path_basename(filepath), &filesize, &recur_depth);
if (filesize == -1) { /* could not open dir */
printf("Could not open dir \"%s\"\n", dirname);
return;
Modified: trunk/blender/source/blender/blenlib/intern/path_util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/path_util.c 2010-06-05 20:23:47 UTC (rev 29249)
+++ trunk/blender/source/blender/blenlib/intern/path_util.c 2010-06-05 21:19:59 UTC (rev 29250)
@@ -1172,6 +1172,12 @@
}
}
+/* like pythons os.path.basename( ) */
+char *BLI_path_basename(char *path)
+{
+ const char *filename= BLI_last_slash(path);
+ return filename ? filename + 1 : path;
+}
/*
Produce image export path.
Modified: trunk/blender/source/blender/editors/space_image/image_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_ops.c 2010-06-05 20:23:47 UTC (rev 29249)
+++ trunk/blender/source/blender/editors/space_image/image_ops.c 2010-06-05 21:19:59 UTC (rev 29250)
@@ -862,7 +862,6 @@
BKE_image_release_renderresult(scene, ima);
}
else if (BKE_write_ibuf(scene, ibuf, path, sima->imtypenr, scene->r.subimtype, scene->r.quality)) {
- char *name;
if(relative)
BLI_path_rel(path, G.sce); /* only after saving */
@@ -895,10 +894,8 @@
ima->type= IMA_TYPE_IMAGE;
}
- name = BLI_last_slash(path);
-
/* name image as how we saved it */
- rename_id(&ima->id, name ? name + 1 : path);
+ rename_id(&ima->id, BLI_path_basename(path));
}
}
else
Modified: trunk/blender/source/blender/editors/space_sequencer/sequencer_add.c
===================================================================
--- trunk/blender/source/blender/editors/space_sequencer/sequencer_add.c 2010-06-05 20:23:47 UTC (rev 29249)
+++ trunk/blender/source/blender/editors/space_sequencer/sequencer_add.c 2010-06-05 21:19:59 UTC (rev 29250)
@@ -421,7 +421,7 @@
RNA_END;
}
else {
- BLI_split_dirfile(seq_load.path, NULL, se->name);
+ BLI_strncpy(se->name, BLI_path_basename(seq_load.path), sizeof(se->name));
if(seq_load.start_frame < seq_load.end_frame) {
seq->endstill= seq_load.end_frame - seq_load.start_frame;
}
Modified: trunk/blender/source/blender/python/generic/bpy_internal_import.c
===================================================================
--- trunk/blender/source/blender/python/generic/bpy_internal_import.c 2010-06-05 20:23:47 UTC (rev 29249)
+++ trunk/blender/source/blender/python/generic/bpy_internal_import.c 2010-06-05 21:19:59 UTC (rev 29250)
@@ -34,6 +34,7 @@
#include "BKE_main.h"
#include "BKE_global.h" /* grr, only for G.sce */
#include "BLI_listbase.h"
+#include "BLI_path_util.h"
#include <stddef.h>
static Main *bpy_import_main= NULL;
@@ -129,8 +130,8 @@
PyObject *bpy_text_reimport( PyObject *module, int *found )
{
Text *text;
- const char *txtname;
const char *name;
+ char *filepath;
char *buf = NULL;
//XXX Main *maggie= bpy_import_main ? bpy_import_main:G.main;
Main *maggie= bpy_import_main;
@@ -143,14 +144,14 @@
*found= 0;
/* get name, filename from the module itself */
+ if((name= PyModule_GetName(module)) == NULL)
+ return NULL;
- txtname = PyModule_GetFilename( module );
- name = PyModule_GetName( module );
- if( !txtname || !name)
+ if((filepath= (char *)PyModule_GetFilename(module)) == NULL)
return NULL;
/* look up the text object */
- text= BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2);
+ text= BLI_findstring(&maggie->text, BLI_path_basename(filepath), offsetof(ID, name) + 2);
/* uh-oh.... didn't find it */
if( !text )
Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c 2010-06-05 20:23:47 UTC (rev 29249)
+++ trunk/blender/source/blender/windowmanager/intern/wm_operators.c 2010-06-05 21:19:59 UTC (rev 29250)
@@ -1212,10 +1212,7 @@
col = uiLayoutColumn(split, 0);
uiItemL(col, "Recent", 0);
for(recent = G.recent_files.first, i=0; (i<5) && (recent); recent = recent->next, i++) {
- char *display_name= BLI_last_slash(recent->filename);
- if(display_name) display_name++; /* skip the slash */
- else display_name= recent->filename;
- uiItemStringO(col, display_name, ICON_FILE_BLEND, "WM_OT_open_mainfile", "path", recent->filename);
+ uiItemStringO(col, BLI_path_basename(recent->filename), ICON_FILE_BLEND, "WM_OT_open_mainfile", "path", recent->filename);
}
uiItemS(col);
uiItemO(col, NULL, ICON_RECOVER_LAST, "WM_OT_recover_last_session");
More information about the Bf-blender-cvs
mailing list