From 04e32be958bb90be2824c083eba8f983d9133f76 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 26 Mar 2011 03:42:59 +0000 Subject: optparse module is deprecated, use new argparse module in background job template. correction to example in doc too. --- release/scripts/templates/background_job.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'release/scripts') diff --git a/release/scripts/templates/background_job.py b/release/scripts/templates/background_job.py index 0337f8f4922..90ddba8a91d 100644 --- a/release/scripts/templates/background_job.py +++ b/release/scripts/templates/background_job.py @@ -66,7 +66,7 @@ def example_function(body_text, save_path, render_path): 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 @@ def main(): 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() -- cgit v1.2.3