moinsetup

Changeset

1:6046269893c6
2010-05-01 Paul Boddie raw files shortlog changelog graph Added support for a Web sites directory (such as sites-available), along with configuration editing for the superuser, ACLs and the site's front page name.
moinsetup.py (file)
     1.1 --- a/moinsetup.py	Tue Apr 13 00:26:25 2010 +0200
     1.2 +++ b/moinsetup.py	Sat May 01 02:54:58 2010 +0200
     1.3 @@ -6,10 +6,17 @@
     1.4  import shutil
     1.5  import re
     1.6  
     1.7 +# Regular expressions for editing MoinMoin scripts and configuration files.
     1.8 +
     1.9  moin_cgi_prefix = re.compile("^#sys.path.insert\(0, 'PREFIX.*$", re.MULTILINE)
    1.10  moin_cgi_wikiconfig = re.compile("^#sys.path.insert\(0, '/path/to/wikiconfigdir.*$", re.MULTILINE)
    1.11  wikiconfig_py_site_name = re.compile(r"^(\s*sitename =).*$", re.MULTILINE)
    1.12  wikiconfig_py_url_prefix_static = re.compile(r"^(\s*)#(url_prefix_static =).*$", re.MULTILINE)
    1.13 +wikiconfig_py_superuser = re.compile(r"^(\s*)#(superuser =).*$", re.MULTILINE)
    1.14 +wikiconfig_py_acl_rights_before = re.compile(r"^(\s*)#(acl_rights_before =).*$", re.MULTILINE)
    1.15 +wikiconfig_py_page_front_page = re.compile(r"^(\s*)#(page_front_page =).*$", re.MULTILINE)
    1.16 +
    1.17 +# Templates for Apache site definitions.
    1.18  
    1.19  apache_site = """
    1.20  ScriptAlias %(url_path)s "%(web_app_dir)s/moin.cgi"
    1.21 @@ -19,6 +26,8 @@
    1.22  Alias %(static_path)s "%(prefix)s/share/moin/htdocs/"
    1.23  """
    1.24  
    1.25 +# Utility functions.
    1.26 +
    1.27  def readfile(filename):
    1.28      f = open(filename)
    1.29      try:
    1.30 @@ -39,7 +48,9 @@
    1.31  def note(message):
    1.32      print message
    1.33  
    1.34 -def setup(moin_distribution, prefix, web_app_dir, common_dir, url_path, site_name):
    1.35 +# NOTE: Support the detection of the Apache sites directory.
    1.36 +
    1.37 +def setup(moin_distribution, prefix, web_app_dir, web_site_dir, common_dir, url_path, site_name, front_page_name, superuser):
    1.38  
    1.39      """
    1.40      Set up a Wiki installation using the following:
    1.41 @@ -49,20 +60,26 @@
    1.42        * prefix            - the installation prefix (equivalent to /usr)
    1.43        * web_app_dir       - the directory where Web applications and scripts
    1.44                              reside (such as /home/www-user/cgi-bin)
    1.45 +      * web_site_dir      - the directory where Web site definitions reside
    1.46 +                            (such as /etc/apache2/sites-available)
    1.47        * common_dir        - the directory where the Wiki configuration,
    1.48                              resources and instance will reside (such as
    1.49                              /home/www-user/mywiki)
    1.50        * url_path          - the URL path at which the Wiki will be made
    1.51                              available (such as / or /mywiki)
    1.52 -      * site_name         - the name of the site (such as My Wiki)
    1.53 +      * site_name         - the name of the site (such as "My Wiki")
    1.54 +      * front_page_name   - the front page name for the site (such as
    1.55 +                            "FrontPage" or a specific name for the site)
    1.56 +      * superuser         - the name of the site's superuser (such as
    1.57 +                            "AdminUser")
    1.58      """
    1.59  
    1.60 -    prefix, web_app_dir, common_dir = map(abspath, (prefix, web_app_dir, common_dir))
    1.61 +    prefix, web_app_dir, web_site_dir, common_dir = map(abspath, (prefix, web_app_dir, web_site_dir, common_dir))
    1.62  
    1.63      conf_dir = join(common_dir, "conf")
    1.64      instance_dir = join(common_dir, "wikidata")
    1.65  
    1.66 -    for d in (conf_dir, instance_dir, web_app_dir):
    1.67 +    for d in (conf_dir, instance_dir, web_app_dir, web_site_dir):
    1.68          if not exists(d):
    1.69              os.makedirs(d)
    1.70  
    1.71 @@ -97,6 +114,9 @@
    1.72      s = readfile(wikiconfig_py)
    1.73      s = wikiconfig_py_site_name.sub(r"\1 %r" % site_name, s)
    1.74      s = wikiconfig_py_url_prefix_static.sub(r"\1\2 %r + url_prefix_static" % url_path, s)
    1.75 +    s = wikiconfig_py_superuser.sub(r"\1\2 %r" % [superuser], s)
    1.76 +    s = wikiconfig_py_acl_rights_before.sub(r"\1\2 %r" % (u"%s:read,write,delete,revert,admin" % superuser), s)
    1.77 +    s = wikiconfig_py_page_front_page.sub(r"\1\2 %r" % front_page_name, s, count=1)
    1.78      writefile(join(conf_dir, "wikiconfig.py"), s)
    1.79  
    1.80      # Edit moin script.
    1.81 @@ -128,22 +148,31 @@
    1.82      os.system("chmod a+rx '%s'" % moin_cgi_installed)
    1.83  
    1.84      # Configure server.
    1.85 -    # NOTE: Need to detect Apache sites directory.
    1.86      # NOTE: Need to work with older MoinMoin versions.
    1.87      # NOTE: Using local namespace for substitution.
    1.88  
    1.89 -    status("Writing Apache site definition to %s..." % site_name)
    1.90 +    site_def = join(web_site_dir, site_name)
    1.91 +    status("Writing Apache site definition to %s..." % site_def)
    1.92  
    1.93 -    writefile(site_name, apache_site % locals())
    1.94 +    writefile(site_def, apache_site % locals())
    1.95  
    1.96      # General notes.
    1.97 +    # NOTE: Need to detect Web server user.
    1.98 +
    1.99 +    web_user = "www-data"
   1.100 +    web_group = "www-data"
   1.101  
   1.102      for d in ("data", "underlay"):
   1.103 -        note("chown -R www-data.www-data '%s'" % join(conf_dir, d))
   1.104 +        note("chown -R %s.%s '%s'" % (web_user, web_group, join(conf_dir, d)))
   1.105 +
   1.106 +# Main program.
   1.107  
   1.108  if __name__ == "__main__":
   1.109 +
   1.110 +    # Obtain as many arguments as needed for the setup function.
   1.111 +
   1.112      try:
   1.113 -        n = 6
   1.114 +        n = 9 # number of setup function arguments
   1.115          args = sys.argv[1:n+1]
   1.116          args[n-1]
   1.117      except (IndexError, ValueError):