# HG changeset patch # User Paul Boddie # Date 1297892437 -3600 # Node ID e1705f0445ec11a67253ab443cd6de34c99fcb53 # Parent 46b79e2490e8fe86333037b0b5167c8267ec5c5e Added support for getting configuration setting values. Added a method to set/add authentication methods to the configuration. diff -r 46b79e2490e8 -r e1705f0445ec TO_DO.txt --- a/TO_DO.txt Sun Dec 19 22:24:17 2010 +0100 +++ b/TO_DO.txt Wed Feb 16 22:40:37 2011 +0100 @@ -1,4 +1,3 @@ -Perhaps switch to a configuration file for all the parameters. Avoid reconfiguration of existing moin script. Site directory detection. Enabled/available site listings. diff -r 46b79e2490e8 -r e1705f0445ec moinsetup.py --- a/moinsetup.py Sun Dec 19 22:24:17 2010 +0100 +++ b/moinsetup.py Wed Feb 16 22:40:37 2011 +0100 @@ -12,7 +12,7 @@ # Regular expressions for editing MoinMoin scripts and configuration files. def compile_definition(name): - return re.compile(r"^(\s*)#*\s*(%s =).*$" % name, re.MULTILINE) + return re.compile(r"^(\s*)#*\s*(%s =)\s*(.*)$" % name, re.MULTILINE) moin_cgi_prefix = re.compile("^#sys\.path\.insert\(0, 'PREFIX.*$", re.MULTILINE) moin_cgi_wikiconfig = re.compile("^#sys\.path\.insert\(0, '/path/to/wikiconfigdir.*$", re.MULTILINE) @@ -94,6 +94,19 @@ return compile_definition(name) + def get(self, name): + + """ + Return the raw value of the last definition having the given 'name'. + """ + + pattern = self.get_pattern(name) + results = [match.group(3) for match in pattern.finditer(self.content)] + if results: + return results[-1] + else: + return None + def set(self, name, value, count=None, raw=0): """ @@ -148,11 +161,19 @@ """ if raw: - insertion = "\n %s = %s\n" + insertion = "%s = %s" else: - insertion = "\n %s = %r\n" + insertion = "%s = %r" + + self.insert_text(insertion % (name, value)) + + def insert_text(self, text): - self.content += insertion % (name, value) + "Insert the given 'text' at the end of the configuration." + + if not self.content.endswith("\n"): + self.content += "\n" + self.content += " %s\n" % text def close(self): @@ -176,6 +197,7 @@ "make_site_files", "make_post_install_script", "reconfigure_moin", + "set_auth_method", # Post-installation activities. @@ -640,7 +662,14 @@ def reconfigure_moin(self, name=None, value=None, raw=0): - "Edit the installed Wiki configuration file." + """ + Edit the installed Wiki configuration file, setting a parameter with any + given 'name' to the given 'value', treating the value as a raw + expression (not a string) if 'raw' is set to a true value. + + If 'name' and the remaining parameters are omitted, the default + configuration activity is performed. + """ wikiconfig_py = join(self.conf_dir, "wikiconfig.py") @@ -659,12 +688,46 @@ finally: wikiconfig.close() - def install_theme(self, theme_dir): + def set_auth_method(self, method_name): + + """ + Edit the installed Wiki configuration file, configuring the + authentication method having the given 'method_name'. + """ + + wikiconfig_py = join(self.conf_dir, "wikiconfig.py") + + status("Editing configuration from %s..." % wikiconfig_py) + + wikiconfig = Configuration(wikiconfig_py) + + try: + if method_name.lower() == "openid": + wikiconfig.insert_text("from MoinMoin.auth.openidrp import OpenIDAuth") - "Install Wiki theme provided in the given 'theme_dir'." + if wikiconfig.get("anonymous_session_lifetime"): + wikiconfig.replace("anonymous_session_lifetime", "1000", raw=1) + else: + wikiconfig.set("anonymous_session_lifetime", "1000", raw=1) + + auth = wikiconfig.get("auth") + if auth: + wikiconfig.replace("auth", "%s + [OpenIDAuth()]" % auth, raw=1) + else: + wikiconfig.set("auth", "[OpenIDAuth()]", raw=1) + + finally: + wikiconfig.close() + + def install_theme(self, theme_dir, theme_name=None): + + """ + Install Wiki theme provided in the given 'theme_dir' having the given + optional 'theme_name' (if different from the 'theme_dir' name). + """ theme_dir = normpath(theme_dir) - theme_name = split(theme_dir)[-1] + theme_name = theme_name or split(theme_dir)[-1] theme_module = join(theme_dir, theme_name + extsep + "py") plugin_theme_dir = self.get_plugin_directory("theme")