[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35789] trunk/blender: optparse module is deprecated, use new argparse module in background job template.
Campbell Barton
ideasman42 at gmail.com
Sat Mar 26 04:43:02 CET 2011
Revision: 35789
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35789
Author: campbellbarton
Date: 2011-03-26 03:42:59 +0000 (Sat, 26 Mar 2011)
Log Message:
-----------
optparse module is deprecated, use new argparse module in background job template.
correction to example in doc too.
Modified Paths:
--------------
trunk/blender/doc/python_api/examples/bpy.data.py
trunk/blender/release/scripts/templates/background_job.py
Modified: trunk/blender/doc/python_api/examples/bpy.data.py
===================================================================
--- trunk/blender/doc/python_api/examples/bpy.data.py 2011-03-26 00:28:10 UTC (rev 35788)
+++ trunk/blender/doc/python_api/examples/bpy.data.py 2011-03-26 03:42:59 UTC (rev 35789)
@@ -14,7 +14,7 @@
if "Cube" in bpy.data.meshes:
mesh = bpy.data.meshes["Cube"]
print("removing mesh", mesh)
- bpy.data.meshes.unlink(mesh)
+ bpy.data.meshes.remove(mesh)
# write images into a file next to the blend
@@ -22,6 +22,6 @@
file = open(os.path.splitext(bpy.data.filepath)[0] + ".txt", 'w')
for image in bpy.data.images:
- file.write("%s %dx%d\n" % (image.filepath, image.size[0], image.size[1]))
+ file.write("%s %d x %d\n" % (image.filepath, image.size[0], image.size[1]))
file.close()
Modified: trunk/blender/release/scripts/templates/background_job.py
===================================================================
--- trunk/blender/release/scripts/templates/background_job.py 2011-03-26 00:28:10 UTC (rev 35788)
+++ trunk/blender/release/scripts/templates/background_job.py 2011-03-26 03:42:59 UTC (rev 35789)
@@ -66,7 +66,7 @@
import sys # to get command line args
-import optparse # to parse options for us and print a nice help message
+import argparse # to parse options for us and print a nice help message
def main():
@@ -84,16 +84,18 @@
usage_text = "Run blender in background mode with this script:"
usage_text += " blender --background --python " + __file__ + " -- [options]"
- parser = optparse.OptionParser(usage=usage_text)
+ print(usage_text)
+ parser = argparse.ArgumentParser(description=usage_text)
+
# Example background utility, add some text and renders or saves it (with options)
# Possible types are: string, int, long, choice, float and complex.
- parser.add_option("-t", "--text", dest="body_text", help="This text will be used to render an image", type="string")
+ parser.add_argument("-t", "--text", dest="body_text", help="This text will be used to render an image", type=str, required=True)
- parser.add_option("-s", "--save", dest="save_path", help="Save the generated file to the specified path", metavar='FILE')
- parser.add_option("-r", "--render", dest="render_path", help="Render an image to the specified path", metavar='FILE')
+ parser.add_argument("-s", "--save", dest="save_path", help="Save the generated file to the specified path", metavar='FILE')
+ parser.add_argument("-r", "--render", dest="render_path", help="Render an image to the specified path", metavar='FILE')
- options, args = parser.parse_args(argv) # In this example we wont use the args
+ options = parser.parse_args(argv) # In this example we wont use the args
if not argv:
parser.print_help()
More information about the Bf-blender-cvs
mailing list