moinsetup

Change of moinsetup.py

26:e1705f0445ec
moinsetup.py
     1.1 --- a/moinsetup.py	Sun Dec 19 22:24:17 2010 +0100
     1.2 +++ b/moinsetup.py	Wed Feb 16 22:40:37 2011 +0100
     1.3 @@ -12,7 +12,7 @@
     1.4  # Regular expressions for editing MoinMoin scripts and configuration files.
     1.5  
     1.6  def compile_definition(name):
     1.7 -    return re.compile(r"^(\s*)#*\s*(%s =).*$" % name, re.MULTILINE)
     1.8 +    return re.compile(r"^(\s*)#*\s*(%s =)\s*(.*)$" % name, re.MULTILINE)
     1.9  
    1.10  moin_cgi_prefix          = re.compile("^#sys\.path\.insert\(0, 'PREFIX.*$", re.MULTILINE)
    1.11  moin_cgi_wikiconfig      = re.compile("^#sys\.path\.insert\(0, '/path/to/wikiconfigdir.*$", re.MULTILINE)
    1.12 @@ -94,6 +94,19 @@
    1.13  
    1.14          return compile_definition(name)
    1.15  
    1.16 +    def get(self, name):
    1.17 +
    1.18 +        """
    1.19 +        Return the raw value of the last definition having the given 'name'.
    1.20 +        """
    1.21 +
    1.22 +        pattern = self.get_pattern(name)
    1.23 +        results = [match.group(3) for match in pattern.finditer(self.content)]
    1.24 +        if results:
    1.25 +            return results[-1]
    1.26 +        else:
    1.27 +            return None
    1.28 +
    1.29      def set(self, name, value, count=None, raw=0):
    1.30  
    1.31          """
    1.32 @@ -148,11 +161,19 @@
    1.33          """
    1.34  
    1.35          if raw:
    1.36 -            insertion = "\n    %s = %s\n"
    1.37 +            insertion = "%s = %s"
    1.38          else:
    1.39 -            insertion = "\n    %s = %r\n"
    1.40 +            insertion = "%s = %r"
    1.41 +
    1.42 +        self.insert_text(insertion % (name, value))
    1.43 +
    1.44 +    def insert_text(self, text):
    1.45  
    1.46 -        self.content += insertion % (name, value)
    1.47 +        "Insert the given 'text' at the end of the configuration."
    1.48 +
    1.49 +        if not self.content.endswith("\n"):
    1.50 +            self.content += "\n"
    1.51 +        self.content += "    %s\n" % text
    1.52  
    1.53      def close(self):
    1.54  
    1.55 @@ -176,6 +197,7 @@
    1.56          "make_site_files",
    1.57          "make_post_install_script",
    1.58          "reconfigure_moin",
    1.59 +        "set_auth_method",
    1.60  
    1.61          # Post-installation activities.
    1.62  
    1.63 @@ -640,7 +662,14 @@
    1.64  
    1.65      def reconfigure_moin(self, name=None, value=None, raw=0):
    1.66  
    1.67 -        "Edit the installed Wiki configuration file."
    1.68 +        """
    1.69 +        Edit the installed Wiki configuration file, setting a parameter with any
    1.70 +        given 'name' to the given 'value', treating the value as a raw
    1.71 +        expression (not a string) if 'raw' is set to a true value.
    1.72 +
    1.73 +        If 'name' and the remaining parameters are omitted, the default
    1.74 +        configuration activity is performed.
    1.75 +        """
    1.76  
    1.77          wikiconfig_py = join(self.conf_dir, "wikiconfig.py")
    1.78  
    1.79 @@ -659,12 +688,46 @@
    1.80          finally:
    1.81              wikiconfig.close()
    1.82  
    1.83 -    def install_theme(self, theme_dir):
    1.84 +    def set_auth_method(self, method_name):
    1.85 +
    1.86 +        """
    1.87 +        Edit the installed Wiki configuration file, configuring the
    1.88 +        authentication method having the given 'method_name'.
    1.89 +        """
    1.90 +
    1.91 +        wikiconfig_py = join(self.conf_dir, "wikiconfig.py")
    1.92 +
    1.93 +        status("Editing configuration from %s..." % wikiconfig_py)
    1.94 +
    1.95 +        wikiconfig = Configuration(wikiconfig_py)
    1.96 +
    1.97 +        try:
    1.98 +            if method_name.lower() == "openid":
    1.99 +                wikiconfig.insert_text("from MoinMoin.auth.openidrp import OpenIDAuth")
   1.100  
   1.101 -        "Install Wiki theme provided in the given 'theme_dir'."
   1.102 +                if wikiconfig.get("anonymous_session_lifetime"):
   1.103 +                    wikiconfig.replace("anonymous_session_lifetime", "1000", raw=1)
   1.104 +                else:
   1.105 +                    wikiconfig.set("anonymous_session_lifetime", "1000", raw=1)
   1.106 +
   1.107 +                auth = wikiconfig.get("auth")
   1.108 +                if auth:
   1.109 +                    wikiconfig.replace("auth", "%s + [OpenIDAuth()]" % auth, raw=1)
   1.110 +                else:
   1.111 +                    wikiconfig.set("auth", "[OpenIDAuth()]", raw=1)
   1.112 +
   1.113 +        finally:
   1.114 +            wikiconfig.close()
   1.115 +
   1.116 +    def install_theme(self, theme_dir, theme_name=None):
   1.117 +
   1.118 +        """
   1.119 +        Install Wiki theme provided in the given 'theme_dir' having the given
   1.120 +        optional 'theme_name' (if different from the 'theme_dir' name).
   1.121 +        """
   1.122  
   1.123          theme_dir = normpath(theme_dir)
   1.124 -        theme_name = split(theme_dir)[-1]
   1.125 +        theme_name = theme_name or split(theme_dir)[-1]
   1.126          theme_module = join(theme_dir, theme_name + extsep + "py")
   1.127  
   1.128          plugin_theme_dir = self.get_plugin_directory("theme")