# HG changeset patch # User Paul Boddie # Date 1274559467 -7200 # Node ID 18ce9b375d508d3c632722fe629a0b49349fa3e4 # Parent b6c4091689f52ea955db3c4117fce0f348dab56a Added support for installing themes and for setting the default theme. Re-ordered the arguments, putting superuser before the site name and front page name, adding the default theme as an optional argument. diff -r b6c4091689f5 -r 18ce9b375d50 TO_DO.txt --- a/TO_DO.txt Thu May 13 22:48:11 2010 +0200 +++ b/TO_DO.txt Sat May 22 22:17:47 2010 +0200 @@ -4,3 +4,6 @@ Support Xapian search. Support OpenID and other authentication methods. Remember anonymous_session_lifetime for 1.8.x and cookie_lifetime for 1.9.x. +Theme installation: + 1.8 has static theme resources in moin/share/moin/htdocs + 1.9 has static theme resources in moin/lib/python2.x/site-packages/MoinMoin/web/static diff -r b6c4091689f5 -r 18ce9b375d50 moinsetup.py --- a/moinsetup.py Thu May 13 22:48:11 2010 +0200 +++ b/moinsetup.py Sat May 22 22:17:47 2010 +0200 @@ -1,6 +1,6 @@ #!/usr/bin/env python -from os.path import abspath, exists, join, split +from os.path import abspath, exists, extsep, join, normpath, split from getpass import getpass import os import sys @@ -14,13 +14,15 @@ 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 = compile_definition("site_name") + +wikiconfig_py_site_name = compile_definition("site_?name") wikiconfig_py_url_prefix_static = compile_definition("url_prefix_static") wikiconfig_py_superuser = compile_definition("superuser") wikiconfig_py_acl_rights_before = compile_definition("acl_rights_before") wikiconfig_py_page_front_page = compile_definition("page_front_page") wikiconfig_py_data_dir = compile_definition("data_dir") wikiconfig_py_data_underlay_dir = compile_definition("data_underlay_dir") +wikiconfig_py_theme_default = compile_definition("theme_default") # Templates for Apache site definitions. @@ -64,7 +66,8 @@ web_group = "www-data" def __init__(self, moin_distribution, prefix, web_app_dir, web_site_dir, - common_dir, url_path, site_name, front_page_name, superuser): + common_dir, url_path, superuser, site_name, front_page_name, + theme_default=None): """ Initialise a Wiki installation using the following: @@ -81,17 +84,19 @@ /home/www-user/mywiki) * url_path - the URL path at which the Wiki will be made available (such as / or /mywiki) + * superuser - the name of the site's superuser (such as + "AdminUser") * 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") + * theme_default - optional: the default theme (such as modern) """ self.moin_distribution = moin_distribution + self.superuser = superuser self.site_name = site_name self.front_page_name = front_page_name - self.superuser = superuser + self.theme_default = theme_default # NOTE: Support the detection of the Apache sites directory. @@ -110,14 +115,22 @@ self.conf_dir = join(self.common_dir, "conf") self.instance_dir = join(self.common_dir, "wikidata") - # For MoinMoin 1.8.x and earlier. + # Define useful directories. - self.htdocs_dir = join(self.instance_dir, "share", "moin", "htdocs") + self.prefix_site_packages = join(self.prefix, "lib", "python%s.%s" % sys.version_info[:2], "site-packages") # Find the version. self.moin_version = self.get_moin_version() + # 1.8: moin/share/moin/htdocs + # 1.9: moin/lib/python2.x/site-packages/MoinMoin/web/static/htdocs + + if self.moin_version.startswith("1.9"): + self.htdocs_dir = join(self.prefix_site_packages, "MoinMoin", "web", "static", "htdocs") + else: + self.htdocs_dir = join(self.instance_dir, "share", "moin", "htdocs") + def get_moin_version(self): "Inspect the MoinMoin package information, returning the version." @@ -156,6 +169,8 @@ if not exists(d): os.makedirs(d) + # Main methods. + def setup(self): "Set up the installation." @@ -235,11 +250,9 @@ status("Editing configuration from %s..." % wikiconfig_py) s = readfile(wikiconfig_py) - s = wikiconfig_py_site_name.sub(r"\1\2 %r" % self.site_name, s) s = wikiconfig_py_url_prefix_static.sub(url_prefix_static_sub, s) s = wikiconfig_py_superuser.sub(r"\1\2 %r" % [self.superuser], s) s = wikiconfig_py_acl_rights_before.sub(r"\1\2 %r" % (u"%s:read,write,delete,revert,admin" % self.superuser), s) - s = wikiconfig_py_page_front_page.sub(r"\1\2 %r" % self.front_page_name, s, count=1) if not self.moin_version.startswith("1.9"): data_dir = join(self.conf_dir, "data") @@ -248,8 +261,25 @@ s = wikiconfig_py_data_dir.sub(r"\1\2 %r" % data_dir, s) s = wikiconfig_py_data_underlay_dir.sub(r"\1\2 %r" % data_underlay_dir, s) + s = self._configure_moin(s) + writefile(join(self.conf_dir, "wikiconfig.py"), s) + def _configure_moin(self, s): + + """ + Configure Moin, taking the configuration file's contents as 's' and + returning the edited contents. + """ + + s = wikiconfig_py_site_name.sub(r"\1\2 %r" % self.site_name, s) + s = wikiconfig_py_page_front_page.sub(r"\1\2 %r" % self.front_page_name, s, count=1) + + if self.theme_default is not None: + s = wikiconfig_py_theme_default.sub(r"\1\2 %r" % self.theme_default, s) + + return s + def edit_moin_scripts(self): "Edit the moin script and the CGI script." @@ -342,9 +372,53 @@ os.chmod(postinst_script, 0755) note("Run %s as root to set file ownership and permissions." % postinst_script) + # Accessory methods. + + def reconfigure_moin(self): + + "Edit the installed Wiki configuration file." + + wikiconfig_py = join(self.conf_dir, "wikiconfig.py") + + status("Editing configuration from %s..." % wikiconfig_py) + + s = readfile(wikiconfig_py) + s = self._configure_moin(s) + writefile(wikiconfig_py, s) + + def install_theme(self, theme_dir): + + "Install Wiki theme provided in the given 'theme_dir'." + + theme_dir = normpath(theme_dir) + theme_name = split(theme_dir)[-1] + theme_module = join(theme_dir, theme_name + extsep + "py") + + data_dir = join(self.conf_dir, "data") + plugin_theme_dir = join(data_dir, "plugin", "theme") + + # Copy the theme module. + + status("Copying theme module to %s..." % plugin_theme_dir) + + shutil.copy(theme_module, plugin_theme_dir) + + # Copy the resources. + + resources_dir = join(self.htdocs_dir, theme_name) + + status("Copying theme resources to %s..." % resources_dir) + + for d in ("css", "img"): + target_dir = join(resources_dir, d) + if exists(target_dir): + status("Replacing %s..." % target_dir) + shutil.rmtree(target_dir) + shutil.copytree(join(theme_dir, d), target_dir) + # Command line option syntax. -syntax_description = " ... [ --method=METHOD ]" +syntax_description = " ... [ --method=METHOD [ ... ] ]" # Main program. @@ -361,6 +435,7 @@ # Obtain as many arguments as needed for the configuration. arguments = args["argument"] + method_arguments = args.get("method-argument", []) # Attempt to initialise the configuration. @@ -381,6 +456,6 @@ else: method = installation.setup - method() + method(*method_arguments) # vim: tabstop=4 expandtab shiftwidth=4