moinsetup

Change of moinsetup.py

24:fcb96dada0ea
moinsetup.py
     1.1 --- a/moinsetup.py	Thu Jul 01 00:47:02 2010 +0200
     1.2 +++ b/moinsetup.py	Fri Nov 19 01:22:39 2010 +0100
     1.3 @@ -542,10 +542,14 @@
     1.4          if self.limited_hosting():
     1.5              if self.moin_version.startswith("1.9"):
     1.6                  s = moin_cgi_fix_script_name.sub(r"\1\2 %r" % self.url_path, s)
     1.7 -                s = moin_cgi_force_cgi.sub(r"\1", s)
     1.8              else:
     1.9                  s = moin_cgi_properties.sub(r"\1\2 %r" % {"script_name" : self.url_path}, s)
    1.10  
    1.11 +        # NOTE: Use CGI for now.
    1.12 +
    1.13 +        if self.moin_version.startswith("1.9"):
    1.14 +            s = moin_cgi_force_cgi.sub(r"\1", s)
    1.15 +
    1.16          writefile(moin_cgi_installed, s)
    1.17          os.system("chmod a+rx '%s'" % moin_cgi_installed)
    1.18  
    1.19 @@ -835,13 +839,22 @@
    1.20                      status("Adding %s to %s in theme %s..." % (imported_stylesheet, theme_stylesheet, theme_name))
    1.21                      writefile(theme_stylesheet_filename, s)
    1.22  
    1.23 +def show_methods():
    1.24 +    print "Methods:"
    1.25 +    print
    1.26 +    for method_name in Installation.method_names:
    1.27 +        doc = getattr(Installation, method_name).__doc__.strip()
    1.28 +        print "%-30s%-s" % (method_name, format(doc, 30))
    1.29 +    print
    1.30 +
    1.31  # Command line option syntax.
    1.32  
    1.33 -syntax_description = "<argument> ... --method=METHOD [ <method-argument> ... ]"
    1.34 +syntax_description = "[ -f <config-filename> ] --method=METHOD [ <method-argument> ... ]"
    1.35  
    1.36  # Main program.
    1.37  
    1.38  if __name__ == "__main__":
    1.39 +    from ConfigParser import ConfigParser
    1.40      import sys, cmdsyntax
    1.41  
    1.42      # Check the command syntax.
    1.43 @@ -850,38 +863,51 @@
    1.44      try:
    1.45          matches = syntax.get_args(sys.argv[1:])
    1.46          args = matches[0]
    1.47 +    except IndexError:
    1.48 +        print "Syntax:"
    1.49 +        print sys.argv[0], syntax_description
    1.50 +        print
    1.51 +        show_methods()
    1.52 +        sys.exit(1)
    1.53  
    1.54 -        # Obtain as many arguments as needed for the configuration.
    1.55 +    # Obtain configuration details.
    1.56  
    1.57 -        arguments = args["argument"]
    1.58 +    try:
    1.59 +        config_filename = args.get("config-filename", "moinsetup.cfg")
    1.60 +        config = ConfigParser()
    1.61 +        config.read(config_filename)
    1.62 +
    1.63 +        # Obtain as many arguments as needed from the configuration.
    1.64 +
    1.65 +        config_arguments = dict(config.items("installation") + config.items("site"))
    1.66          method_arguments = args.get("method-argument", [])
    1.67  
    1.68          # Attempt to initialise the configuration.
    1.69  
    1.70 -        installation = Installation(*arguments)
    1.71 +        installation = Installation(**config_arguments)
    1.72  
    1.73 -    except (IndexError, TypeError):
    1.74 -        print "Syntax:"
    1.75 -        print sys.argv[0], syntax_description
    1.76 +    except TypeError:
    1.77 +        print "Configuration settings:"
    1.78          print
    1.79 -        print "Arguments:"
    1.80          print Installation.__init__.__doc__
    1.81          print
    1.82 -        print "Methods:"
    1.83 -        print
    1.84 -        for method_name in Installation.method_names:
    1.85 -            doc = getattr(Installation, method_name).__doc__.strip()
    1.86 -            print "%-30s%-s" % (method_name, format(doc, 30))
    1.87 -        print
    1.88          sys.exit(1)
    1.89  
    1.90 -    # Obtain and perform the method.
    1.91 +    # Obtain the method.
    1.92  
    1.93 -    if args.has_key("method"):
    1.94 +    try:
    1.95          method = getattr(installation, args["method"])
    1.96 -    else:
    1.97 -        method = installation.setup
    1.98 +    except AttributeError:
    1.99 +        show_methods()
   1.100 +        sys.exit(1)
   1.101  
   1.102 -    method(*method_arguments)
   1.103 +    try:
   1.104 +        method(*method_arguments)
   1.105 +    except TypeError:
   1.106 +        print "Method documentation:"
   1.107 +        print
   1.108 +        print method.__doc__
   1.109 +        print
   1.110 +        raise
   1.111  
   1.112  # vim: tabstop=4 expandtab shiftwidth=4