moinsetup

Change of moinsetup.py

58:a5aec502083f
moinsetup.py
     1.1 --- a/moinsetup.py	Sat Oct 15 23:58:51 2011 +0200
     1.2 +++ b/moinsetup.py	Tue Jul 10 16:23:54 2012 +0200
     1.3 @@ -3,7 +3,7 @@
     1.4  """
     1.5  A setup and configuration script for MoinMoin.
     1.6  
     1.7 -Copyright (C) 2010, 2011 Paul Boddie <paul@boddie.org.uk>
     1.8 +Copyright (C) 2010, 2011, 2012 Paul Boddie <paul@boddie.org.uk>
     1.9  
    1.10  This program is free software; you can redistribute it and/or modify it under
    1.11  the terms of the GNU General Public License as published by the Free Software
    1.12 @@ -57,23 +57,31 @@
    1.13  """
    1.14  
    1.15  apache_site_extra = """
    1.16 -Alias %(static_url_path)s "%(htdocs_dir)s/"
    1.17 +Alias %(static_url_resources_path)s "%(htdocs_dir)s/"
    1.18  """
    1.19  
    1.20  # Limited hosting .htaccess definitions require the following settings to be
    1.21 -# configured in the main Apache configuration files:
    1.22 +# configured in the main Apache configuration files for the directory where
    1.23 +# .htaccess is to be deployed:
    1.24 +#
    1.25 +# AllowOverride FileInfo Limit
    1.26  #
    1.27 -# Options ExecCGI FollowSymLinks Indexes SymLinksIfOwnerMatch
    1.28 -# AllowOverride FileInfo Limit
    1.29 +# The following settings are required for the directory where the moin.cgi
    1.30 +# script is to be deployed:
    1.31 +#
    1.32 +# Options ExecCGI FollowSymLinks SymLinksIfOwnerMatch
    1.33  # AddHandler cgi-script .cgi
    1.34 +#
    1.35 +# If a DirectoryIndex directive is also desired, the Indexes option must be set.
    1.36 +# Such a directive is not desirable where the static and dynamic resources are
    1.37 +# in different places, however.
    1.38  
    1.39  apache_htaccess_combined_mod_rewrite = """
    1.40 -DirectoryIndex moin.cgi
    1.41  RewriteEngine On
    1.42 -RewriteBase %(url_path)s
    1.43 +RewriteBase %(final_url_path)s
    1.44  RewriteCond %%{REQUEST_FILENAME} !-f
    1.45  RewriteCond %%{REQUEST_FILENAME} !-d
    1.46 -RewriteRule ^(.*) moin.cgi/$1 [PT,L,QSA]
    1.47 +RewriteRule ^(.*) %(url_path)s/moin.cgi/$1 [PT,L,QSA]
    1.48  """
    1.49  
    1.50  # Post-setup templates.
    1.51 @@ -91,6 +99,12 @@
    1.52  find '%(htdocs_dir)s' -type d | xargs setfacl -m u:%(web_user)s:rx
    1.53  """
    1.54  
    1.55 +postsetup_setfacl_logs = """
    1.56 +if [ -e "%(common_dir)s/data/*-log" ]; then
    1.57 +    setfacl -m g:%(web_group)s:rw %(common_dir)s/data/*-log
    1.58 +fi
    1.59 +"""
    1.60 +
    1.61  postsetup_chown_chmod = """#!/bin/sh
    1.62  
    1.63  chown -R %(this_user)s.%(web_group)s '%(common_dir)s/data'
    1.64 @@ -103,6 +117,12 @@
    1.65  chown -R %(this_user)s.%(web_group)s '%(htdocs_dir)s'
    1.66  """
    1.67  
    1.68 +postsetup_chown_logs = """
    1.69 +if [ -e "%(common_dir)s/data/*-log" ]; then
    1.70 +    chown %(this_user)s.%(web_group)s %(common_dir)s/data/*-log
    1.71 +fi
    1.72 +"""
    1.73 +
    1.74  # Utility functions.
    1.75  
    1.76  def readfile(filename):
    1.77 @@ -350,7 +370,8 @@
    1.78  
    1.79      def __init__(self, moin_distribution=None, prefix=None,
    1.80          site_packages=None, web_app_dir=None, web_static_dir=None, web_site_dir=None,
    1.81 -        common_dir=None, farm_config=None, site_config=None, url_path=None,
    1.82 +        common_dir=None, farm_config=None, site_config=None,
    1.83 +        url_path=None, static_url_path=None,
    1.84          superuser=None, site_name=None, site_identifier=None, front_page_name=None,
    1.85          theme_default=None):
    1.86  
    1.87 @@ -384,6 +405,8 @@
    1.88                                  (overrides the 'common_dir' setting)
    1.89            * url_path          - the URL path at which the Wiki will be made
    1.90                                  available (such as / or /mywiki)
    1.91 +          * static_url_path   - optional: the URL path at which static resources
    1.92 +                                will be made available (such as / or /mywiki)
    1.93            * superuser         - the name of the site's superuser (such as
    1.94                                  "AdminUser", can be omitted)
    1.95            * site_name         - the name of the site (such as "My Wiki")
    1.96 @@ -416,10 +439,8 @@
    1.97          if not url_path:
    1.98              raise TypeError, "The 'url_path' setting must be specified."
    1.99  
   1.100 -        if url_path != "/" and url_path.endswith("/"):
   1.101 -            self.url_path = url_path[:-1]
   1.102 -        else:
   1.103 -            self.url_path = url_path
   1.104 +        self.url_path = self._tidy_url_path(url_path)
   1.105 +        self.static_url_path = self._tidy_url_path(static_url_path)
   1.106  
   1.107          # Define and create specific directories.
   1.108          # Here are the configuration and actual Wiki data directories.
   1.109 @@ -464,14 +485,38 @@
   1.110          #
   1.111          # This allows multiple Wiki instances to have their own static resources
   1.112          # in the same hosting area.
   1.113 +        #
   1.114 +        # Where a separate static URL path has been given, the resources are
   1.115 +        # located under that path:
   1.116 +        #
   1.117 +        # /         -> /moin_static187
   1.118 +        # /hgwiki   -> /hgwiki/moin_static187
   1.119  
   1.120 -        self.static_url_path = self.url_path + (self.url_path != "/" and "-" or "") + self.get_static_identifier()
   1.121 +        # The final URL path is the principal location of the Wiki.
   1.122 +
   1.123 +        self.final_url_path = self.static_url_path or self.url_path
   1.124 +
   1.125 +        # The static URL resources path is the specific location of static
   1.126 +        # resources.
   1.127 +
   1.128 +        self.static_url_resources_path = \
   1.129 +            self.final_url_path + \
   1.130 +            (self.static_url_path
   1.131 +                and (self.static_url_path != "/"
   1.132 +                    and "/"
   1.133 +                    or "")
   1.134 +                or (self.final_url_path != "/"
   1.135 +                    and "-"
   1.136 +                    or "")) + \
   1.137 +            self.get_static_identifier()
   1.138 +
   1.139 +        self.static_dir_name = self.static_url_resources_path.split("/")[-1]
   1.140  
   1.141          # In limited hosting, the static resources directory is related to
   1.142 -        # the URL path.
   1.143 +        # the URL path, either a specified static URL path or the general path.
   1.144  
   1.145          if self.limited_hosting():
   1.146 -            self.htdocs_dir = join(self.web_static_dir or self.web_app_dir, self.static_url_path.lstrip("/"))
   1.147 +            self.htdocs_dir = join(self.web_static_dir or self.web_app_dir, self.static_dir_name)
   1.148  
   1.149          # Otherwise, a mapping is made to the directory.
   1.150          # This may be placed in a special static directory if desired.
   1.151 @@ -511,6 +556,12 @@
   1.152      def _get_abspath(self, d):
   1.153          return d and abspath(d) or None
   1.154  
   1.155 +    def _tidy_url_path(self, url_path):
   1.156 +        if url_path != "/" and url_path.endswith("/"):
   1.157 +            return url_path[:-1]
   1.158 +        else:
   1.159 +            return url_path
   1.160 +
   1.161      def get_moin_version(self):
   1.162  
   1.163          "Return the MoinMoin version."
   1.164 @@ -769,7 +820,7 @@
   1.165          # NOTE: with the version, but more specific locations are probably
   1.166          # NOTE: acceptable if less efficient.
   1.167  
   1.168 -        url_prefix_static = "%r" % self.static_url_path
   1.169 +        url_prefix_static = "%r" % self.static_url_resources_path
   1.170  
   1.171          # Use a farm configuration file.
   1.172  
   1.173 @@ -882,10 +933,12 @@
   1.174              if not site_file_configured:
   1.175                  note("Site file not configured: script name not changed.")
   1.176              else:
   1.177 +                url_path = self.final_url_path
   1.178 +
   1.179                  if self.moin_version.startswith("1.9"):
   1.180 -                    s = moin_cgi_fix_script_name.sub(r"\1\2 %r" % self.url_path, s)
   1.181 +                    s = moin_cgi_fix_script_name.sub(r"\1\2 %r" % url_path, s)
   1.182                  else:
   1.183 -                    s = moin_cgi_properties.sub(r"\1\2 %r" % {"script_name" : self.url_path}, s)
   1.184 +                    s = moin_cgi_properties.sub(r"\1\2 %r" % {"script_name" : url_path}, s)
   1.185  
   1.186          # NOTE: Use CGI for now.
   1.187  
   1.188 @@ -953,7 +1006,7 @@
   1.189          # Otherwise, use an .htaccess file.
   1.190  
   1.191          else:
   1.192 -            site_def = join(self.web_app_dir, ".htaccess")
   1.193 +            site_def = join(self.web_static_dir or self.web_app_dir, ".htaccess")
   1.194  
   1.195              s = apache_htaccess_combined_mod_rewrite % self.__dict__
   1.196  
   1.197 @@ -990,13 +1043,14 @@
   1.198          vars.update(self.__dict__)
   1.199          vars.update(locals())
   1.200  
   1.201 -        for postinst_script, start, extra in [
   1.202 -            (postinst_scripts[0], postsetup_chown_chmod, postsetup_chown_extra),
   1.203 -            (postinst_scripts[1], postsetup_setfacl, postsetup_setfacl_extra)
   1.204 +        for postinst_script, start, extra, logs in [
   1.205 +            (postinst_scripts[0], postsetup_chown_chmod, postsetup_chown_extra, postsetup_chown_logs),
   1.206 +            (postinst_scripts[1], postsetup_setfacl, postsetup_setfacl_extra, postsetup_setfacl_logs)
   1.207              ]:
   1.208  
   1.209              s = start % vars
   1.210              s += extra % vars
   1.211 +            s += logs % vars
   1.212  
   1.213              writefile(postinst_script, s)
   1.214              chmod(postinst_script, 0755)