# HG changeset patch # User Paul Boddie # Date 1272675298 -7200 # Node ID 6046269893c6347da0bf2d7cac594c177f86ef70 # Parent 0c1be594e7b06520a355a71337261dbcad88babf 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. diff -r 0c1be594e7b0 -r 6046269893c6 moinsetup.py --- a/moinsetup.py Tue Apr 13 00:26:25 2010 +0200 +++ b/moinsetup.py Sat May 01 02:54:58 2010 +0200 @@ -6,10 +6,17 @@ import shutil import re +# Regular expressions for editing MoinMoin scripts and configuration files. + moin_cgi_prefix = re.compile("^#sys.path.insert\(0, 'PREFIX.*$", re.MULTILINE) moin_cgi_wikiconfig = re.compile("^#sys.path.insert\(0, '/path/to/wikiconfigdir.*$", re.MULTILINE) wikiconfig_py_site_name = re.compile(r"^(\s*sitename =).*$", re.MULTILINE) wikiconfig_py_url_prefix_static = re.compile(r"^(\s*)#(url_prefix_static =).*$", re.MULTILINE) +wikiconfig_py_superuser = re.compile(r"^(\s*)#(superuser =).*$", re.MULTILINE) +wikiconfig_py_acl_rights_before = re.compile(r"^(\s*)#(acl_rights_before =).*$", re.MULTILINE) +wikiconfig_py_page_front_page = re.compile(r"^(\s*)#(page_front_page =).*$", re.MULTILINE) + +# Templates for Apache site definitions. apache_site = """ ScriptAlias %(url_path)s "%(web_app_dir)s/moin.cgi" @@ -19,6 +26,8 @@ Alias %(static_path)s "%(prefix)s/share/moin/htdocs/" """ +# Utility functions. + def readfile(filename): f = open(filename) try: @@ -39,7 +48,9 @@ def note(message): print message -def setup(moin_distribution, prefix, web_app_dir, common_dir, url_path, site_name): +# NOTE: Support the detection of the Apache sites directory. + +def setup(moin_distribution, prefix, web_app_dir, web_site_dir, common_dir, url_path, site_name, front_page_name, superuser): """ Set up a Wiki installation using the following: @@ -49,20 +60,26 @@ * prefix - the installation prefix (equivalent to /usr) * web_app_dir - the directory where Web applications and scripts reside (such as /home/www-user/cgi-bin) + * web_site_dir - the directory where Web site definitions reside + (such as /etc/apache2/sites-available) * common_dir - the directory where the Wiki configuration, resources and instance will reside (such as /home/www-user/mywiki) * url_path - the URL path at which the Wiki will be made available (such as / or /mywiki) - * site_name - the name of the site (such as My Wiki) + * site_name - the name of the site (such as "My Wiki") + * front_page_name - the front page name for the site (such as + "FrontPage" or a specific name for the site) + * superuser - the name of the site's superuser (such as + "AdminUser") """ - prefix, web_app_dir, common_dir = map(abspath, (prefix, web_app_dir, common_dir)) + prefix, web_app_dir, web_site_dir, common_dir = map(abspath, (prefix, web_app_dir, web_site_dir, common_dir)) conf_dir = join(common_dir, "conf") instance_dir = join(common_dir, "wikidata") - for d in (conf_dir, instance_dir, web_app_dir): + for d in (conf_dir, instance_dir, web_app_dir, web_site_dir): if not exists(d): os.makedirs(d) @@ -97,6 +114,9 @@ s = readfile(wikiconfig_py) s = wikiconfig_py_site_name.sub(r"\1 %r" % site_name, s) s = wikiconfig_py_url_prefix_static.sub(r"\1\2 %r + url_prefix_static" % url_path, s) + s = wikiconfig_py_superuser.sub(r"\1\2 %r" % [superuser], s) + s = wikiconfig_py_acl_rights_before.sub(r"\1\2 %r" % (u"%s:read,write,delete,revert,admin" % superuser), s) + s = wikiconfig_py_page_front_page.sub(r"\1\2 %r" % front_page_name, s, count=1) writefile(join(conf_dir, "wikiconfig.py"), s) # Edit moin script. @@ -128,22 +148,31 @@ os.system("chmod a+rx '%s'" % moin_cgi_installed) # Configure server. - # NOTE: Need to detect Apache sites directory. # NOTE: Need to work with older MoinMoin versions. # NOTE: Using local namespace for substitution. - status("Writing Apache site definition to %s..." % site_name) + site_def = join(web_site_dir, site_name) + status("Writing Apache site definition to %s..." % site_def) - writefile(site_name, apache_site % locals()) + writefile(site_def, apache_site % locals()) # General notes. + # NOTE: Need to detect Web server user. + + web_user = "www-data" + web_group = "www-data" for d in ("data", "underlay"): - note("chown -R www-data.www-data '%s'" % join(conf_dir, d)) + note("chown -R %s.%s '%s'" % (web_user, web_group, join(conf_dir, d))) + +# Main program. if __name__ == "__main__": + + # Obtain as many arguments as needed for the setup function. + try: - n = 6 + n = 9 # number of setup function arguments args = sys.argv[1:n+1] args[n-1] except (IndexError, ValueError):