# HG changeset patch # User Sverre Rabbelier # Date 1257175438 -3600 # Node ID 6e100e1946806e53551e43f6c1028a4656306d72 # Parent edae0fb956c9d205d5a8b63887d639cf8db9b1c9 Convert gen_app_yaml.py to optparse This allows for example the -f flag to be specified as the second argument. Also add a '-i|--interactive' flag which asks for the application name interactively. diff -r edae0fb956c9 -r 6e100e194680 scripts/gen_app_yaml.py --- a/scripts/gen_app_yaml.py Mon Nov 02 16:13:32 2009 +0100 +++ b/scripts/gen_app_yaml.py Mon Nov 02 16:23:58 2009 +0100 @@ -14,17 +14,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""A script to generate the app.yaml from the template with an application -name filled in. +"""gen_app_yaml.py [-f] (-i | APPLICATION_NAME) -Usage: - gen_app_yaml.py [-f] APPLICATION_NAME +A script to generate the app.yaml from the template with an application +name filled in. Arguments: APPLICATION_NAME: the name to use for the application (no underscores) - -Flags: - -f: overwrite an existing app.yaml (default=false) """ from __future__ import with_statement @@ -37,6 +33,7 @@ import os import sys +from optparse import OptionParser def generateAppYaml(application_name, force=False): @@ -84,21 +81,25 @@ """Main program. """ - if not args: - usage("No arguments supplied.") + parser = OptionParser(usage=__doc__) + parser.add_option("-f", "--force", action="store_true", default=False, + help="Overwrite existing app.yaml") + parser.add_option("-i", "--interactive", action="store_true", default=False, + help="Ask for the application name interactively") - if args[0] == '-f': - force = True - args = args[1:] + options, args = parser.parse_args(args) + + if options.interactive: + if args: + parser.error("Cannot combine application name with -i") + sys.stdout.write("Application name: ") + application_name = sys.stdin.readline().strip() else: - force = False + if len(args) != 1: + parser.error("No application name supplied.") + application_name = args[0] - if len(args) != 1: - usage("No application name supplied.") - - application_name = args[0] - generateAppYaml(application_name, force=force) - + generateAppYaml(application_name, force=options.force) if __name__ == '__main__': main(sys.argv[1:]) # strip off the binary name