# HG changeset patch # User Paul Boddie # Date 1273782787 -7200 # Node ID 6bf43fcaff8198f0a869d42d1b8b1029aad05bdc # Parent e6544f4f8e00e0cbbb36d70b01ad42dc84cd6282 Introduced cmdsyntax usage in order to support more convenient option parsing and selection of individual actions. diff -r e6544f4f8e00 -r 6bf43fcaff81 moinsetup.py --- a/moinsetup.py Sat May 08 18:52:31 2010 +0200 +++ b/moinsetup.py Thu May 13 22:33:07 2010 +0200 @@ -114,10 +114,6 @@ self.htdocs_dir = join(self.instance_dir, "share", "moin", "htdocs") - # Miscellaneous configuration options. - - self.superuser_client_host = "127.0.0.1" - # Find the version. self.moin_version = self.get_moin_version() @@ -341,21 +337,49 @@ os.chmod(postinst_script, 0755) note("Run %s as root to set file ownership and permissions." % postinst_script) +# Command line option syntax. + +syntax_description = " ... [ --method=METHOD ]" + # Main program. if __name__ == "__main__": + import sys, cmdsyntax - # Obtain as many arguments as needed for the setup function. + # Check the command syntax. + syntax = cmdsyntax.Syntax(syntax_description) try: - n = 9 # number of Installation initialiser arguments - args = sys.argv[1:n+1] - args[n-1] - except (IndexError, ValueError): + matches = syntax.get_args(sys.argv[1:]) + args = matches[0] + except IndexError: + print "Syntax:" + print sys.argv[0], syntax_description + print + print "Arguments:" print Installation.__init__.__doc__ sys.exit(1) - installation = Installation(*args) - installation.setup() + # Obtain as many arguments as needed for the configuration. + + arguments = args["argument"] + + try: + installation = Installation(*arguments) + except TypeError: + print sys.argv[0], syntax_description + print + print "Arguments:" + print Installation.__init__.__doc__ + sys.exit(1) + + # Obtain and perform the method. + + if args.has_key("method"): + method = getattr(installation, args["method"]) + else: + method = installation.setup + + method() # vim: tabstop=4 expandtab shiftwidth=4