moinsetup

Changeset

9:18ce9b375d50
2010-05-22 Paul Boddie raw files shortlog changelog graph 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.
TO_DO.txt (file) moinsetup.py (file)
     1.1 --- a/TO_DO.txt	Thu May 13 22:48:11 2010 +0200
     1.2 +++ b/TO_DO.txt	Sat May 22 22:17:47 2010 +0200
     1.3 @@ -4,3 +4,6 @@
     1.4  Support Xapian search.
     1.5  Support OpenID and other authentication methods.
     1.6    Remember anonymous_session_lifetime for 1.8.x and cookie_lifetime for 1.9.x.
     1.7 +Theme installation:
     1.8 +  1.8 has static theme resources in moin/share/moin/htdocs
     1.9 +  1.9 has static theme resources in moin/lib/python2.x/site-packages/MoinMoin/web/static
     2.1 --- a/moinsetup.py	Thu May 13 22:48:11 2010 +0200
     2.2 +++ b/moinsetup.py	Sat May 22 22:17:47 2010 +0200
     2.3 @@ -1,6 +1,6 @@
     2.4  #!/usr/bin/env python
     2.5  
     2.6 -from os.path import abspath, exists, join, split
     2.7 +from os.path import abspath, exists, extsep, join, normpath, split
     2.8  from getpass import getpass
     2.9  import os
    2.10  import sys
    2.11 @@ -14,13 +14,15 @@
    2.12  
    2.13  moin_cgi_prefix                 = re.compile("^#sys.path.insert\(0, 'PREFIX.*$", re.MULTILINE)
    2.14  moin_cgi_wikiconfig             = re.compile("^#sys.path.insert\(0, '/path/to/wikiconfigdir.*$", re.MULTILINE)
    2.15 -wikiconfig_py_site_name         = compile_definition("site_name")
    2.16 +
    2.17 +wikiconfig_py_site_name         = compile_definition("site_?name")
    2.18  wikiconfig_py_url_prefix_static = compile_definition("url_prefix_static")
    2.19  wikiconfig_py_superuser         = compile_definition("superuser")
    2.20  wikiconfig_py_acl_rights_before = compile_definition("acl_rights_before")
    2.21  wikiconfig_py_page_front_page   = compile_definition("page_front_page")
    2.22  wikiconfig_py_data_dir          = compile_definition("data_dir")
    2.23  wikiconfig_py_data_underlay_dir = compile_definition("data_underlay_dir")
    2.24 +wikiconfig_py_theme_default     = compile_definition("theme_default")
    2.25  
    2.26  # Templates for Apache site definitions.
    2.27  
    2.28 @@ -64,7 +66,8 @@
    2.29      web_group = "www-data"
    2.30  
    2.31      def __init__(self, moin_distribution, prefix, web_app_dir, web_site_dir,
    2.32 -        common_dir, url_path, site_name, front_page_name, superuser):
    2.33 +        common_dir, url_path, superuser, site_name, front_page_name,
    2.34 +        theme_default=None):
    2.35  
    2.36          """
    2.37          Initialise a Wiki installation using the following:
    2.38 @@ -81,17 +84,19 @@
    2.39                                  /home/www-user/mywiki)
    2.40            * url_path          - the URL path at which the Wiki will be made
    2.41                                  available (such as / or /mywiki)
    2.42 +          * superuser         - the name of the site's superuser (such as
    2.43 +                                "AdminUser")
    2.44            * site_name         - the name of the site (such as "My Wiki")
    2.45            * front_page_name   - the front page name for the site (such as
    2.46                                  "FrontPage" or a specific name for the site)
    2.47 -          * superuser         - the name of the site's superuser (such as
    2.48 -                                "AdminUser")
    2.49 +          * theme_default     - optional: the default theme (such as modern)
    2.50          """
    2.51  
    2.52          self.moin_distribution = moin_distribution
    2.53 +        self.superuser = superuser
    2.54          self.site_name = site_name
    2.55          self.front_page_name = front_page_name
    2.56 -        self.superuser = superuser
    2.57 +        self.theme_default = theme_default
    2.58  
    2.59          # NOTE: Support the detection of the Apache sites directory.
    2.60  
    2.61 @@ -110,14 +115,22 @@
    2.62          self.conf_dir = join(self.common_dir, "conf")
    2.63          self.instance_dir = join(self.common_dir, "wikidata")
    2.64  
    2.65 -        # For MoinMoin 1.8.x and earlier.
    2.66 +        # Define useful directories.
    2.67  
    2.68 -        self.htdocs_dir = join(self.instance_dir, "share", "moin", "htdocs")
    2.69 +        self.prefix_site_packages = join(self.prefix, "lib", "python%s.%s" % sys.version_info[:2], "site-packages")
    2.70  
    2.71          # Find the version.
    2.72  
    2.73          self.moin_version = self.get_moin_version()
    2.74  
    2.75 +        # 1.8: moin/share/moin/htdocs
    2.76 +        # 1.9: moin/lib/python2.x/site-packages/MoinMoin/web/static/htdocs
    2.77 +
    2.78 +        if self.moin_version.startswith("1.9"):
    2.79 +            self.htdocs_dir = join(self.prefix_site_packages, "MoinMoin", "web", "static", "htdocs")
    2.80 +        else:
    2.81 +            self.htdocs_dir = join(self.instance_dir, "share", "moin", "htdocs")
    2.82 +
    2.83      def get_moin_version(self):
    2.84  
    2.85          "Inspect the MoinMoin package information, returning the version."
    2.86 @@ -156,6 +169,8 @@
    2.87              if not exists(d):
    2.88                  os.makedirs(d)
    2.89  
    2.90 +    # Main methods.
    2.91 +
    2.92      def setup(self):
    2.93  
    2.94          "Set up the installation."
    2.95 @@ -235,11 +250,9 @@
    2.96          status("Editing configuration from %s..." % wikiconfig_py)
    2.97  
    2.98          s = readfile(wikiconfig_py)
    2.99 -        s = wikiconfig_py_site_name.sub(r"\1\2 %r" % self.site_name, s)
   2.100          s = wikiconfig_py_url_prefix_static.sub(url_prefix_static_sub, s)
   2.101          s = wikiconfig_py_superuser.sub(r"\1\2 %r" % [self.superuser], s)
   2.102          s = wikiconfig_py_acl_rights_before.sub(r"\1\2 %r" % (u"%s:read,write,delete,revert,admin" % self.superuser), s)
   2.103 -        s = wikiconfig_py_page_front_page.sub(r"\1\2 %r" % self.front_page_name, s, count=1)
   2.104  
   2.105          if not self.moin_version.startswith("1.9"):
   2.106              data_dir = join(self.conf_dir, "data")
   2.107 @@ -248,8 +261,25 @@
   2.108              s = wikiconfig_py_data_dir.sub(r"\1\2 %r" % data_dir, s)
   2.109              s = wikiconfig_py_data_underlay_dir.sub(r"\1\2 %r" % data_underlay_dir, s)
   2.110  
   2.111 +        s = self._configure_moin(s)
   2.112 +
   2.113          writefile(join(self.conf_dir, "wikiconfig.py"), s)
   2.114  
   2.115 +    def _configure_moin(self, s):
   2.116 +
   2.117 +        """
   2.118 +        Configure Moin, taking the configuration file's contents as 's' and
   2.119 +        returning the edited contents.
   2.120 +        """
   2.121 +
   2.122 +        s = wikiconfig_py_site_name.sub(r"\1\2 %r" % self.site_name, s)
   2.123 +        s = wikiconfig_py_page_front_page.sub(r"\1\2 %r" % self.front_page_name, s, count=1)
   2.124 +
   2.125 +        if self.theme_default is not None:
   2.126 +            s = wikiconfig_py_theme_default.sub(r"\1\2 %r" % self.theme_default, s)
   2.127 +
   2.128 +        return s
   2.129 +
   2.130      def edit_moin_scripts(self):
   2.131  
   2.132          "Edit the moin script and the CGI script."
   2.133 @@ -342,9 +372,53 @@
   2.134          os.chmod(postinst_script, 0755)
   2.135          note("Run %s as root to set file ownership and permissions." % postinst_script)
   2.136  
   2.137 +    # Accessory methods.
   2.138 +
   2.139 +    def reconfigure_moin(self):
   2.140 +
   2.141 +        "Edit the installed Wiki configuration file."
   2.142 +
   2.143 +        wikiconfig_py = join(self.conf_dir, "wikiconfig.py")
   2.144 +
   2.145 +        status("Editing configuration from %s..." % wikiconfig_py)
   2.146 +
   2.147 +        s = readfile(wikiconfig_py)
   2.148 +        s = self._configure_moin(s)
   2.149 +        writefile(wikiconfig_py, s)
   2.150 +
   2.151 +    def install_theme(self, theme_dir):
   2.152 +
   2.153 +        "Install Wiki theme provided in the given 'theme_dir'."
   2.154 +
   2.155 +        theme_dir = normpath(theme_dir)
   2.156 +        theme_name = split(theme_dir)[-1]
   2.157 +        theme_module = join(theme_dir, theme_name + extsep + "py")
   2.158 +
   2.159 +        data_dir = join(self.conf_dir, "data")
   2.160 +        plugin_theme_dir = join(data_dir, "plugin", "theme")
   2.161 +
   2.162 +        # Copy the theme module.
   2.163 +
   2.164 +        status("Copying theme module to %s..." % plugin_theme_dir)
   2.165 +
   2.166 +        shutil.copy(theme_module, plugin_theme_dir)
   2.167 +
   2.168 +        # Copy the resources.
   2.169 +
   2.170 +        resources_dir = join(self.htdocs_dir, theme_name)
   2.171 +
   2.172 +        status("Copying theme resources to %s..." % resources_dir)
   2.173 +
   2.174 +        for d in ("css", "img"):
   2.175 +            target_dir = join(resources_dir, d)
   2.176 +            if exists(target_dir):
   2.177 +                status("Replacing %s..." % target_dir)
   2.178 +                shutil.rmtree(target_dir)
   2.179 +            shutil.copytree(join(theme_dir, d), target_dir)
   2.180 +
   2.181  # Command line option syntax.
   2.182  
   2.183 -syntax_description = "<argument> ... [ --method=METHOD ]"
   2.184 +syntax_description = "<argument> ... [ --method=METHOD [ <method-argument> ... ] ]"
   2.185  
   2.186  # Main program.
   2.187  
   2.188 @@ -361,6 +435,7 @@
   2.189          # Obtain as many arguments as needed for the configuration.
   2.190  
   2.191          arguments = args["argument"]
   2.192 +        method_arguments = args.get("method-argument", [])
   2.193  
   2.194          # Attempt to initialise the configuration.
   2.195  
   2.196 @@ -381,6 +456,6 @@
   2.197      else:
   2.198          method = installation.setup
   2.199  
   2.200 -    method()
   2.201 +    method(*method_arguments)
   2.202  
   2.203  # vim: tabstop=4 expandtab shiftwidth=4