1.1 --- a/TO_DO.txt Sun Dec 19 22:24:17 2010 +0100
1.2 +++ b/TO_DO.txt Wed Feb 16 22:40:37 2011 +0100
1.3 @@ -1,4 +1,3 @@
1.4 -Perhaps switch to a configuration file for all the parameters.
1.5 Avoid reconfiguration of existing moin script.
1.6 Site directory detection.
1.7 Enabled/available site listings.
2.1 --- a/moinsetup.py Sun Dec 19 22:24:17 2010 +0100
2.2 +++ b/moinsetup.py Wed Feb 16 22:40:37 2011 +0100
2.3 @@ -12,7 +12,7 @@
2.4 # Regular expressions for editing MoinMoin scripts and configuration files.
2.5
2.6 def compile_definition(name):
2.7 - return re.compile(r"^(\s*)#*\s*(%s =).*$" % name, re.MULTILINE)
2.8 + return re.compile(r"^(\s*)#*\s*(%s =)\s*(.*)$" % name, re.MULTILINE)
2.9
2.10 moin_cgi_prefix = re.compile("^#sys\.path\.insert\(0, 'PREFIX.*$", re.MULTILINE)
2.11 moin_cgi_wikiconfig = re.compile("^#sys\.path\.insert\(0, '/path/to/wikiconfigdir.*$", re.MULTILINE)
2.12 @@ -94,6 +94,19 @@
2.13
2.14 return compile_definition(name)
2.15
2.16 + def get(self, name):
2.17 +
2.18 + """
2.19 + Return the raw value of the last definition having the given 'name'.
2.20 + """
2.21 +
2.22 + pattern = self.get_pattern(name)
2.23 + results = [match.group(3) for match in pattern.finditer(self.content)]
2.24 + if results:
2.25 + return results[-1]
2.26 + else:
2.27 + return None
2.28 +
2.29 def set(self, name, value, count=None, raw=0):
2.30
2.31 """
2.32 @@ -148,11 +161,19 @@
2.33 """
2.34
2.35 if raw:
2.36 - insertion = "\n %s = %s\n"
2.37 + insertion = "%s = %s"
2.38 else:
2.39 - insertion = "\n %s = %r\n"
2.40 + insertion = "%s = %r"
2.41 +
2.42 + self.insert_text(insertion % (name, value))
2.43 +
2.44 + def insert_text(self, text):
2.45
2.46 - self.content += insertion % (name, value)
2.47 + "Insert the given 'text' at the end of the configuration."
2.48 +
2.49 + if not self.content.endswith("\n"):
2.50 + self.content += "\n"
2.51 + self.content += " %s\n" % text
2.52
2.53 def close(self):
2.54
2.55 @@ -176,6 +197,7 @@
2.56 "make_site_files",
2.57 "make_post_install_script",
2.58 "reconfigure_moin",
2.59 + "set_auth_method",
2.60
2.61 # Post-installation activities.
2.62
2.63 @@ -640,7 +662,14 @@
2.64
2.65 def reconfigure_moin(self, name=None, value=None, raw=0):
2.66
2.67 - "Edit the installed Wiki configuration file."
2.68 + """
2.69 + Edit the installed Wiki configuration file, setting a parameter with any
2.70 + given 'name' to the given 'value', treating the value as a raw
2.71 + expression (not a string) if 'raw' is set to a true value.
2.72 +
2.73 + If 'name' and the remaining parameters are omitted, the default
2.74 + configuration activity is performed.
2.75 + """
2.76
2.77 wikiconfig_py = join(self.conf_dir, "wikiconfig.py")
2.78
2.79 @@ -659,12 +688,46 @@
2.80 finally:
2.81 wikiconfig.close()
2.82
2.83 - def install_theme(self, theme_dir):
2.84 + def set_auth_method(self, method_name):
2.85 +
2.86 + """
2.87 + Edit the installed Wiki configuration file, configuring the
2.88 + authentication method having the given 'method_name'.
2.89 + """
2.90 +
2.91 + wikiconfig_py = join(self.conf_dir, "wikiconfig.py")
2.92 +
2.93 + status("Editing configuration from %s..." % wikiconfig_py)
2.94 +
2.95 + wikiconfig = Configuration(wikiconfig_py)
2.96 +
2.97 + try:
2.98 + if method_name.lower() == "openid":
2.99 + wikiconfig.insert_text("from MoinMoin.auth.openidrp import OpenIDAuth")
2.100
2.101 - "Install Wiki theme provided in the given 'theme_dir'."
2.102 + if wikiconfig.get("anonymous_session_lifetime"):
2.103 + wikiconfig.replace("anonymous_session_lifetime", "1000", raw=1)
2.104 + else:
2.105 + wikiconfig.set("anonymous_session_lifetime", "1000", raw=1)
2.106 +
2.107 + auth = wikiconfig.get("auth")
2.108 + if auth:
2.109 + wikiconfig.replace("auth", "%s + [OpenIDAuth()]" % auth, raw=1)
2.110 + else:
2.111 + wikiconfig.set("auth", "[OpenIDAuth()]", raw=1)
2.112 +
2.113 + finally:
2.114 + wikiconfig.close()
2.115 +
2.116 + def install_theme(self, theme_dir, theme_name=None):
2.117 +
2.118 + """
2.119 + Install Wiki theme provided in the given 'theme_dir' having the given
2.120 + optional 'theme_name' (if different from the 'theme_dir' name).
2.121 + """
2.122
2.123 theme_dir = normpath(theme_dir)
2.124 - theme_name = split(theme_dir)[-1]
2.125 + theme_name = theme_name or split(theme_dir)[-1]
2.126 theme_module = join(theme_dir, theme_name + extsep + "py")
2.127
2.128 plugin_theme_dir = self.get_plugin_directory("theme")