# HG changeset patch # User Paul Boddie # Date 1290126159 -3600 # Node ID fcb96dada0ea8f8f43bff56fccb18cf21451cc0a # Parent 0ff99cb88bb1e0019aee4e2a0a5b7f478dcafa77 Introduced configuration file usage instead of having to specify everything as command line arguments. Fixed MoinMoin 1.9 CGI usage enforcement in moin.cgi. diff -r 0ff99cb88bb1 -r fcb96dada0ea moinsetup.cfg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/moinsetup.cfg Fri Nov 19 01:22:39 2010 +0100 @@ -0,0 +1,13 @@ +[installation] +moin_distribution = moin-1.9-hg +prefix = moin +web_app_dir = webapps +web_site_dir = sites-available +common_dir = wiki + +[site] +url_path = / +superuser = AdminUser +site_name = My Wiki +front_page_name = FrontPage +theme_default = modern diff -r 0ff99cb88bb1 -r fcb96dada0ea moinsetup.py --- a/moinsetup.py Thu Jul 01 00:47:02 2010 +0200 +++ b/moinsetup.py Fri Nov 19 01:22:39 2010 +0100 @@ -542,10 +542,14 @@ if self.limited_hosting(): if self.moin_version.startswith("1.9"): s = moin_cgi_fix_script_name.sub(r"\1\2 %r" % self.url_path, s) - s = moin_cgi_force_cgi.sub(r"\1", s) else: s = moin_cgi_properties.sub(r"\1\2 %r" % {"script_name" : self.url_path}, s) + # NOTE: Use CGI for now. + + if self.moin_version.startswith("1.9"): + s = moin_cgi_force_cgi.sub(r"\1", s) + writefile(moin_cgi_installed, s) os.system("chmod a+rx '%s'" % moin_cgi_installed) @@ -835,13 +839,22 @@ status("Adding %s to %s in theme %s..." % (imported_stylesheet, theme_stylesheet, theme_name)) writefile(theme_stylesheet_filename, s) +def show_methods(): + print "Methods:" + print + for method_name in Installation.method_names: + doc = getattr(Installation, method_name).__doc__.strip() + print "%-30s%-s" % (method_name, format(doc, 30)) + print + # Command line option syntax. -syntax_description = " ... --method=METHOD [ ... ]" +syntax_description = "[ -f ] --method=METHOD [ ... ]" # Main program. if __name__ == "__main__": + from ConfigParser import ConfigParser import sys, cmdsyntax # Check the command syntax. @@ -850,38 +863,51 @@ try: matches = syntax.get_args(sys.argv[1:]) args = matches[0] + except IndexError: + print "Syntax:" + print sys.argv[0], syntax_description + print + show_methods() + sys.exit(1) - # Obtain as many arguments as needed for the configuration. + # Obtain configuration details. - arguments = args["argument"] + try: + config_filename = args.get("config-filename", "moinsetup.cfg") + config = ConfigParser() + config.read(config_filename) + + # Obtain as many arguments as needed from the configuration. + + config_arguments = dict(config.items("installation") + config.items("site")) method_arguments = args.get("method-argument", []) # Attempt to initialise the configuration. - installation = Installation(*arguments) + installation = Installation(**config_arguments) - except (IndexError, TypeError): - print "Syntax:" - print sys.argv[0], syntax_description + except TypeError: + print "Configuration settings:" print - print "Arguments:" print Installation.__init__.__doc__ print - print "Methods:" - print - for method_name in Installation.method_names: - doc = getattr(Installation, method_name).__doc__.strip() - print "%-30s%-s" % (method_name, format(doc, 30)) - print sys.exit(1) - # Obtain and perform the method. + # Obtain the method. - if args.has_key("method"): + try: method = getattr(installation, args["method"]) - else: - method = installation.setup + except AttributeError: + show_methods() + sys.exit(1) - method(*method_arguments) + try: + method(*method_arguments) + except TypeError: + print "Method documentation:" + print + print method.__doc__ + print + raise # vim: tabstop=4 expandtab shiftwidth=4