moinsetup

Changeset

24:fcb96dada0ea
2010-11-19 Paul Boddie raw files shortlog changelog graph Introduced configuration file usage instead of having to specify everything as command line arguments. Fixed MoinMoin 1.9 CGI usage enforcement in moin.cgi.
moinsetup.cfg (file) moinsetup.py (file)
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/moinsetup.cfg	Fri Nov 19 01:22:39 2010 +0100
     1.3 @@ -0,0 +1,13 @@
     1.4 +[installation]
     1.5 +moin_distribution = moin-1.9-hg
     1.6 +prefix            = moin
     1.7 +web_app_dir       = webapps
     1.8 +web_site_dir      = sites-available
     1.9 +common_dir        = wiki
    1.10 +
    1.11 +[site]
    1.12 +url_path          = /
    1.13 +superuser         = AdminUser
    1.14 +site_name         = My Wiki
    1.15 +front_page_name   = FrontPage
    1.16 +theme_default     = modern
     2.1 --- a/moinsetup.py	Thu Jul 01 00:47:02 2010 +0200
     2.2 +++ b/moinsetup.py	Fri Nov 19 01:22:39 2010 +0100
     2.3 @@ -542,10 +542,14 @@
     2.4          if self.limited_hosting():
     2.5              if self.moin_version.startswith("1.9"):
     2.6                  s = moin_cgi_fix_script_name.sub(r"\1\2 %r" % self.url_path, s)
     2.7 -                s = moin_cgi_force_cgi.sub(r"\1", s)
     2.8              else:
     2.9                  s = moin_cgi_properties.sub(r"\1\2 %r" % {"script_name" : self.url_path}, s)
    2.10  
    2.11 +        # NOTE: Use CGI for now.
    2.12 +
    2.13 +        if self.moin_version.startswith("1.9"):
    2.14 +            s = moin_cgi_force_cgi.sub(r"\1", s)
    2.15 +
    2.16          writefile(moin_cgi_installed, s)
    2.17          os.system("chmod a+rx '%s'" % moin_cgi_installed)
    2.18  
    2.19 @@ -835,13 +839,22 @@
    2.20                      status("Adding %s to %s in theme %s..." % (imported_stylesheet, theme_stylesheet, theme_name))
    2.21                      writefile(theme_stylesheet_filename, s)
    2.22  
    2.23 +def show_methods():
    2.24 +    print "Methods:"
    2.25 +    print
    2.26 +    for method_name in Installation.method_names:
    2.27 +        doc = getattr(Installation, method_name).__doc__.strip()
    2.28 +        print "%-30s%-s" % (method_name, format(doc, 30))
    2.29 +    print
    2.30 +
    2.31  # Command line option syntax.
    2.32  
    2.33 -syntax_description = "<argument> ... --method=METHOD [ <method-argument> ... ]"
    2.34 +syntax_description = "[ -f <config-filename> ] --method=METHOD [ <method-argument> ... ]"
    2.35  
    2.36  # Main program.
    2.37  
    2.38  if __name__ == "__main__":
    2.39 +    from ConfigParser import ConfigParser
    2.40      import sys, cmdsyntax
    2.41  
    2.42      # Check the command syntax.
    2.43 @@ -850,38 +863,51 @@
    2.44      try:
    2.45          matches = syntax.get_args(sys.argv[1:])
    2.46          args = matches[0]
    2.47 +    except IndexError:
    2.48 +        print "Syntax:"
    2.49 +        print sys.argv[0], syntax_description
    2.50 +        print
    2.51 +        show_methods()
    2.52 +        sys.exit(1)
    2.53  
    2.54 -        # Obtain as many arguments as needed for the configuration.
    2.55 +    # Obtain configuration details.
    2.56  
    2.57 -        arguments = args["argument"]
    2.58 +    try:
    2.59 +        config_filename = args.get("config-filename", "moinsetup.cfg")
    2.60 +        config = ConfigParser()
    2.61 +        config.read(config_filename)
    2.62 +
    2.63 +        # Obtain as many arguments as needed from the configuration.
    2.64 +
    2.65 +        config_arguments = dict(config.items("installation") + config.items("site"))
    2.66          method_arguments = args.get("method-argument", [])
    2.67  
    2.68          # Attempt to initialise the configuration.
    2.69  
    2.70 -        installation = Installation(*arguments)
    2.71 +        installation = Installation(**config_arguments)
    2.72  
    2.73 -    except (IndexError, TypeError):
    2.74 -        print "Syntax:"
    2.75 -        print sys.argv[0], syntax_description
    2.76 +    except TypeError:
    2.77 +        print "Configuration settings:"
    2.78          print
    2.79 -        print "Arguments:"
    2.80          print Installation.__init__.__doc__
    2.81          print
    2.82 -        print "Methods:"
    2.83 -        print
    2.84 -        for method_name in Installation.method_names:
    2.85 -            doc = getattr(Installation, method_name).__doc__.strip()
    2.86 -            print "%-30s%-s" % (method_name, format(doc, 30))
    2.87 -        print
    2.88          sys.exit(1)
    2.89  
    2.90 -    # Obtain and perform the method.
    2.91 +    # Obtain the method.
    2.92  
    2.93 -    if args.has_key("method"):
    2.94 +    try:
    2.95          method = getattr(installation, args["method"])
    2.96 -    else:
    2.97 -        method = installation.setup
    2.98 +    except AttributeError:
    2.99 +        show_methods()
   2.100 +        sys.exit(1)
   2.101  
   2.102 -    method(*method_arguments)
   2.103 +    try:
   2.104 +        method(*method_arguments)
   2.105 +    except TypeError:
   2.106 +        print "Method documentation:"
   2.107 +        print
   2.108 +        print method.__doc__
   2.109 +        print
   2.110 +        raise
   2.111  
   2.112  # vim: tabstop=4 expandtab shiftwidth=4