[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16999] trunk/blender: == Python ==

Willian Padovani Germano wpgermano at gmail.com
Fri Oct 10 00:28:44 CEST 2008


Revision: 16999
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16999
Author:   ianwill
Date:     2008-10-10 00:28:44 +0200 (Fri, 10 Oct 2008)

Log Message:
-----------
== Python  ==

Bug: [#17734] Loading a python script's help dosn't work

reported by Rian Tut (thanks).

Actual problem: scripts with spaces in their filenames were not supported by the code that registers scripts in menus and runs them. Added support w/o breaking eventual, rare scripts that parse the Bpymenus file. They will still need an update to support filenames with spaces, like done here for these scripts: Scripts Help Browser and Scripts Config Editor.

PS: tested on Linux. Please test on other platforms: just make sure scripts still appear in menus (the File->Export, for example), even after re-registering them (Scripts window -> Scripts Menu -> Update Menus) and that the Scripts Help Browser still works.

Modified Paths:
--------------
    trunk/blender/release/scripts/config.py
    trunk/blender/release/scripts/help_browser.py
    trunk/blender/source/blender/python/BPY_menus.c

Modified: trunk/blender/release/scripts/config.py
===================================================================
--- trunk/blender/release/scripts/config.py	2008-10-09 21:39:26 UTC (rev 16998)
+++ trunk/blender/release/scripts/config.py	2008-10-09 22:28:44 UTC (rev 16999)
@@ -246,6 +246,10 @@
 			fields = fields[2].split()
 			if len(fields) > 1:
 				fname = fields[1].split(sep)[-1]
+				i = 1
+				while not fname.endswith('.py'):
+					i += 1
+					fname = "%s %s" % (fname, fields[i])
 				ALL_SCRIPTS[fname] = (menuname, group_len - 1)
 	return True
 

Modified: trunk/blender/release/scripts/help_browser.py
===================================================================
--- trunk/blender/release/scripts/help_browser.py	2008-10-09 21:39:26 UTC (rev 16998)
+++ trunk/blender/release/scripts/help_browser.py	2008-10-09 22:28:44 UTC (rev 16999)
@@ -448,11 +448,19 @@
 
 def parse_script_line(l):
 
+	tip = 'No tooltip'
 	try:
 		pieces = l.split("'")
 		name = pieces[1].replace('...','')
-		version, fname, userdir = pieces[2].strip().split()
-		tip = pieces[3]
+		data = pieces[2].strip().split()
+		version = data[0]
+		userdir = data[-1]
+		fname = data[1]
+		i = 1
+		while not fname.endswith('.py'):
+			i += 1
+			fname = '%s %s' % (fname, data[i])
+		if len(pieces) > 3: tip = pieces[3]
 	except:
 		return None
 

Modified: trunk/blender/source/blender/python/BPY_menus.c
===================================================================
--- trunk/blender/source/blender/python/BPY_menus.c	2008-10-09 21:39:26 UTC (rev 16998)
+++ trunk/blender/source/blender/python/BPY_menus.c	2008-10-09 22:28:44 UTC (rev 16999)
@@ -479,7 +479,7 @@
 	char line[255], w1[255], w2[255], tooltip[255], *tip;
 	char upythondir[FILE_MAX];
 	char *homedir = NULL;
-	int parsing, version, is_userdir;
+	int parsing, version, w2_len, is_userdir;
 	short group;
 	BPyMenu *pymenu = NULL;
 
@@ -554,17 +554,32 @@
 			else if( line[0] == '\n' )
 				continue;
 			else if( line[0] == '\'' ) {	/* menu entry */
-				parsing =
+/*				parsing =
 					sscanf( line,
 						"'%[^']' %d %s %d '%[^']'\n",
 						w1, &version, w2, &is_userdir,
 						tooltip );
-
-				if( parsing <= 0 ) {	/* invalid line, get rid of it */
+*/
+				/* previously filenames with spaces were not supported;
+				 * this adds support for that w/o breaking the existing
+				 * few, exotic scripts that parse the Bpymenus file */
+				parsing = sscanf( line,
+						"'%[^']' %d %[^'\n] '%[^']'\n",
+						w1, &version, w2, tooltip );
+				if( parsing <= 0 ) { /* invalid line, get rid of it */
 					fgets( line, 255, fp );
-				} else if( parsing == 5 )
+				} else if( parsing == 4 )
 					tip = tooltip;	/* has tooltip */
 
+				w2_len = strlen(w2);
+				if( w2[w2_len-1] == ' ') {
+					w2[w2_len-1] = '\0';
+					w2_len -= 1;
+				}
+				if( w2[w2_len-1] == '1') is_userdir = 1;
+				else is_userdir = 0;
+				w2[w2_len-2] = '\0';
+
 				pymenu = bpymenu_AddEntry( group,
 							   ( short ) version,
 							   w1, w2, is_userdir,
@@ -693,14 +708,8 @@
 }
 
 /* bpymenu_ParseFile:
- * recursively scans folders looking for scripts to register.
+ * parse a given .py file looking for a proper header.
  *
- * This function scans the scripts directory looking for .py files with the
- * right header and menu info, using that to fill the bpymenu structs.
- * is_userdir defines if the script is in the default scripts dir or the
- * user defined one (U.pythondir: is_userdir == 1).
- * Speed is important.
- *
  * The first line of the script must be '#!BPY'.
  * The header registration lines must appear between the first pair of
  * '\"\"\"' and follow this order (the single-quotes are part of





More information about the Bf-blender-cvs mailing list