1.1 --- a/moinsetup.py Wed Feb 23 01:36:12 2011 +0100
1.2 +++ b/moinsetup.py Fri Apr 15 23:08:37 2011 +0200
1.3 @@ -36,13 +36,18 @@
1.4 def compile_definition(name):
1.5 return re.compile(r"^(\s*)#*\s*(%s =)\s*(.*)$" % name, re.MULTILINE)
1.6
1.7 -moin_cgi_prefix = re.compile("^#sys\.path\.insert\(0, 'PREFIX.*$", re.MULTILINE)
1.8 -moin_cgi_wikiconfig = re.compile("^#sys\.path\.insert\(0, '/path/to/wikiconfigdir.*$", re.MULTILINE)
1.9 +wikiconfig_import = re.compile(r"^(\s*)#*\s*"
1.10 + r"(from\s+)(?P<module>\S+)"
1.11 + r"(\s+import\s+)(?P<names>(?:\S|[^,\s])+(?:\s*,\s*(?:\S|[^,\s])+)*)"
1.12 + r"(\s*)$", re.MULTILINE)
1.13 +
1.14 +moin_cgi_prefix = re.compile(r"^#sys\.path\.insert\(0, 'PREFIX.*$", re.MULTILINE)
1.15 +moin_cgi_wikiconfig = re.compile(r"^#sys\.path\.insert\(0, '/path/to/wikiconfigdir.*$", re.MULTILINE)
1.16 moin_cgi_properties = compile_definition("properties")
1.17 moin_cgi_fix_script_name = compile_definition("fix_script_name")
1.18 -moin_cgi_force_cgi = re.compile("^#(os.environ\['FCGI_FORCE_CGI'\].*)$", re.MULTILINE)
1.19 +moin_cgi_force_cgi = re.compile(r"^#(os.environ\['FCGI_FORCE_CGI'\].*)$", re.MULTILINE)
1.20
1.21 -css_import_stylesheet = re.compile("(\s*@import\s+[\"'])(.*?)([\"']\s*;)")
1.22 +css_import_stylesheet = re.compile(r"(\s*@import\s+[\"'])(.*?)([\"']\s*;)")
1.23
1.24 # Templates for Apache site definitions.
1.25
1.26 @@ -224,6 +229,47 @@
1.27 self.content += "\n"
1.28 self.content += " %s\n" % text
1.29
1.30 + def set_import(self, imported_module, imported_names):
1.31 +
1.32 + """
1.33 + Set up an import of the given 'imported_module' exposing the given
1.34 + 'imported_names'.
1.35 + """
1.36 +
1.37 + s = self.content
1.38 + after_point = 0
1.39 + first_point = None
1.40 +
1.41 + for module_import in wikiconfig_import.finditer(s):
1.42 + before, from_keyword, module, import_keyword, names, after = module_import.groups()
1.43 + before_point, after_point = module_import.span()
1.44 +
1.45 + if first_point is None:
1.46 + first_point = after_point
1.47 +
1.48 + names = [name.strip() for name in names.split(",")]
1.49 +
1.50 + # Test the import for a reference to the requested imported module.
1.51 +
1.52 + if imported_module == module:
1.53 + for name in imported_names:
1.54 + if name not in names:
1.55 + names.append(name)
1.56 +
1.57 + self.content = s[:before_point] + (
1.58 + "%s%s%s%s%s%s" % (before, from_keyword, module, import_keyword, ", ".join(names), after)
1.59 + ) + s[after_point:]
1.60 + break
1.61 +
1.62 + # Where no import references the imported module, insert a reference
1.63 + # into the configuration.
1.64 +
1.65 + else:
1.66 + # Add the import after the first one.
1.67 +
1.68 + if first_point is not None:
1.69 + self.content = s[:first_point] + ("\nfrom %s import %s" % (imported_module, ", ".join(imported_names))) + s[first_point:]
1.70 +
1.71 def close(self):
1.72
1.73 "Close the file, writing the content."
1.74 @@ -802,19 +848,48 @@
1.75 wikiconfig = Configuration(wikiconfig_py)
1.76
1.77 try:
1.78 + # OpenID authentication.
1.79 +
1.80 if method_name.lower() == "openid":
1.81 - wikiconfig.insert_text("from MoinMoin.auth.openidrp import OpenIDAuth")
1.82 + wikiconfig.set_import("MoinMoin.auth.openidrp", ["OpenIDAuth"])
1.83
1.84 - if wikiconfig.get("anonymous_session_lifetime"):
1.85 - wikiconfig.replace("anonymous_session_lifetime", "1000", raw=1)
1.86 + if self.moin_version.startswith("1.9"):
1.87 + if wikiconfig.get("cookie_lifetime"):
1.88 + wikiconfig.replace("cookie_lifetime", "(12, 12)", raw=1)
1.89 + else:
1.90 + wikiconfig.set("cookie_lifetime", "(12, 12)", raw=1)
1.91 else:
1.92 - wikiconfig.set("anonymous_session_lifetime", "1000", raw=1)
1.93 + if wikiconfig.get("anonymous_session_lifetime"):
1.94 + wikiconfig.replace("anonymous_session_lifetime", "1000", raw=1)
1.95 + else:
1.96 + wikiconfig.set("anonymous_session_lifetime", "1000", raw=1)
1.97 +
1.98 + auth_object = "OpenIDAuth()"
1.99 +
1.100 + # Default Moin authentication.
1.101 +
1.102 + elif method_name.lower() in ("moin", "default"):
1.103 + wikiconfig.set_import("MoinMoin.auth", ["MoinAuth"])
1.104 + auth_object = "MoinAuth()"
1.105 +
1.106 + # REMOTE_USER authentication.
1.107
1.108 - auth = wikiconfig.get("auth")
1.109 - if auth:
1.110 - wikiconfig.replace("auth", "%s + [OpenIDAuth()]" % auth, raw=1)
1.111 - else:
1.112 - wikiconfig.set("auth", "[OpenIDAuth()]", raw=1)
1.113 + elif method_name.lower() in ("given", "remote-user"):
1.114 + wikiconfig.set_import("MoinMoin.auth.http", ["HTTPAuth"])
1.115 + auth_object = "HTTPAuth(autocreate=True)"
1.116 +
1.117 + # Other methods are not currently supported.
1.118 +
1.119 + else:
1.120 + return
1.121 +
1.122 + # Edit the authentication setting.
1.123 +
1.124 + auth = wikiconfig.get("auth")
1.125 + if auth:
1.126 + wikiconfig.replace("auth", "%s + [%s]" % (auth, auth_object), raw=1)
1.127 + else:
1.128 + wikiconfig.set("auth", "[%s]" % auth_object, raw=1)
1.129
1.130 finally:
1.131 wikiconfig.close()