moinsetup

Changeset

7:6bf43fcaff81
2010-05-13 Paul Boddie raw files shortlog changelog graph Introduced cmdsyntax usage in order to support more convenient option parsing and selection of individual actions.
moinsetup.py (file)
     1.1 --- a/moinsetup.py	Sat May 08 18:52:31 2010 +0200
     1.2 +++ b/moinsetup.py	Thu May 13 22:33:07 2010 +0200
     1.3 @@ -114,10 +114,6 @@
     1.4  
     1.5          self.htdocs_dir = join(self.instance_dir, "share", "moin", "htdocs")
     1.6  
     1.7 -        # Miscellaneous configuration options.
     1.8 -
     1.9 -        self.superuser_client_host = "127.0.0.1"
    1.10 -
    1.11          # Find the version.
    1.12  
    1.13          self.moin_version = self.get_moin_version()
    1.14 @@ -341,21 +337,49 @@
    1.15          os.chmod(postinst_script, 0755)
    1.16          note("Run %s as root to set file ownership and permissions." % postinst_script)
    1.17  
    1.18 +# Command line option syntax.
    1.19 +
    1.20 +syntax_description = "<argument> ... [ --method=METHOD ]"
    1.21 +
    1.22  # Main program.
    1.23  
    1.24  if __name__ == "__main__":
    1.25 +    import sys, cmdsyntax
    1.26  
    1.27 -    # Obtain as many arguments as needed for the setup function.
    1.28 +    # Check the command syntax.
    1.29  
    1.30 +    syntax = cmdsyntax.Syntax(syntax_description)
    1.31      try:
    1.32 -        n = 9 # number of Installation initialiser arguments
    1.33 -        args = sys.argv[1:n+1]
    1.34 -        args[n-1]
    1.35 -    except (IndexError, ValueError):
    1.36 +        matches = syntax.get_args(sys.argv[1:])
    1.37 +        args = matches[0]
    1.38 +    except IndexError:
    1.39 +        print "Syntax:"
    1.40 +        print sys.argv[0], syntax_description
    1.41 +        print
    1.42 +        print "Arguments:"
    1.43          print Installation.__init__.__doc__
    1.44          sys.exit(1)
    1.45  
    1.46 -    installation = Installation(*args)
    1.47 -    installation.setup()
    1.48 +    # Obtain as many arguments as needed for the configuration.
    1.49 +
    1.50 +    arguments = args["argument"]
    1.51 +
    1.52 +    try:
    1.53 +        installation = Installation(*arguments)
    1.54 +    except TypeError:
    1.55 +        print sys.argv[0], syntax_description
    1.56 +        print
    1.57 +        print "Arguments:"
    1.58 +        print Installation.__init__.__doc__
    1.59 +        sys.exit(1)
    1.60 +
    1.61 +    # Obtain and perform the method.
    1.62 +
    1.63 +    if args.has_key("method"):
    1.64 +        method = getattr(installation, args["method"])
    1.65 +    else:
    1.66 +        method = installation.setup
    1.67 +
    1.68 +    method()
    1.69  
    1.70  # vim: tabstop=4 expandtab shiftwidth=4