moinsetup

Changeset

40:9a95862669f6
2011-08-28 Paul Boddie raw files shortlog changelog graph Made various changes to support a shared data directory such as those provided by system packages in places like /usr/share/moin, without a source distribution of MoinMoin being installed.
README.txt (file) moinsetup.cfg (file) moinsetup.py (file)
     1.1 --- a/README.txt	Sun Jun 26 00:33:55 2011 +0200
     1.2 +++ b/README.txt	Sun Aug 28 00:54:41 2011 +0200
     1.3 @@ -30,6 +30,10 @@
     1.4  moin_distribution   A path to a MoinMoin distribution directory, which can
     1.5                      also be a clone of a MoinMoin repository.
     1.6  
     1.7 +moin_data           A path to the MoinMoin shared data, which may be installed
     1.8 +                    from a system package in a directory such as
     1.9 +                    /usr/share/moin.
    1.10 +
    1.11  prefix              The directory prefix containing lib, bin and share
    1.12                      directories where MoinMoin is (or will be) installed.
    1.13                      Although this follows the layout of the /usr directory (on
    1.14 @@ -164,6 +168,13 @@
    1.15  CMDsyntax                   Tested with 0.91
    1.16                              Source: http://www.boddie.org.uk/david/Projects/Python/CMDSyntax/index.html
    1.17  
    1.18 +New in moinsetup 0.3 (Changes since moinsetup 0.2)
    1.19 +--------------------------------------------------
    1.20 +
    1.21 +  * Added a moin_data setting and made moin_distribution optional so that when
    1.22 +    MoinMoin is installed from a system package, the non-installation actions
    1.23 +    can still be performed.
    1.24 +
    1.25  New in moinsetup 0.2 (Changes since moinsetup 0.1)
    1.26  --------------------------------------------------
    1.27  
     2.1 --- a/moinsetup.cfg	Sun Jun 26 00:33:55 2011 +0200
     2.2 +++ b/moinsetup.cfg	Sun Aug 28 00:54:41 2011 +0200
     2.3 @@ -1,5 +1,6 @@
     2.4  [installation]
     2.5  moin_distribution = moin-1.9-hg
     2.6 +moin_data         =
     2.7  prefix            = moin
     2.8  web_app_dir       = webapps
     2.9  web_static_dir    =
     3.1 --- a/moinsetup.py	Sun Jun 26 00:33:55 2011 +0200
     3.2 +++ b/moinsetup.py	Sun Aug 28 00:54:41 2011 +0200
     3.3 @@ -29,7 +29,7 @@
     3.4  import re
     3.5  import tempfile
     3.6  
     3.7 -__version__ = "0.2"
     3.8 +__version__ = "0.3"
     3.9  
    3.10  # Regular expressions for editing MoinMoin scripts and configuration files.
    3.11  
    3.12 @@ -129,6 +129,12 @@
    3.13  
    3.14  # Classes.
    3.15  
    3.16 +class SetupException(Exception):
    3.17 +
    3.18 +    "An exception indicating a problem with a setup action."
    3.19 +
    3.20 +    pass
    3.21 +
    3.22  class Configuration:
    3.23  
    3.24      "A class representing the configuration."
    3.25 @@ -321,7 +327,7 @@
    3.26      theme_master = "modernized"
    3.27      extra_theme_css_files = ["SlideShow.css"]
    3.28  
    3.29 -    def __init__(self, moin_distribution, prefix, web_app_dir,
    3.30 +    def __init__(self, moin_distribution, moin_data, prefix, web_app_dir,
    3.31          common_dir, url_path, superuser, site_name, front_page_name,
    3.32          web_site_dir=None, web_static_dir=None, theme_default=None):
    3.33  
    3.34 @@ -330,6 +336,8 @@
    3.35  
    3.36            * moin_distribution - the directory containing a MoinMoin source
    3.37                                  distribution
    3.38 +          * moin_data         - the directory containing MoinMoin shared data
    3.39 +                                (can be omitted if 'moin_distribution' is given)
    3.40            * prefix            - the installation prefix (equivalent to /usr)
    3.41            * web_app_dir       - the directory where Web applications and scripts
    3.42                                  reside (such as /home/www-user/cgi-bin)
    3.43 @@ -352,6 +360,7 @@
    3.44          """
    3.45  
    3.46          self.moin_distribution = moin_distribution
    3.47 +        self.moin_data = moin_data
    3.48          self.superuser = superuser
    3.49          self.site_name = site_name
    3.50          self.front_page_name = front_page_name
    3.51 @@ -392,13 +401,26 @@
    3.52          # 1.9: moin/lib/python2.x/site-packages/MoinMoin/web/static/htdocs
    3.53  
    3.54          if self.moin_version.startswith("1.9"):
    3.55 -            self.htdocs_dir = self.htdocs_dir_source = join(self.prefix_site_packages, "MoinMoin", "web", "static", "htdocs")
    3.56 +
    3.57 +            # A shared data directory may be in use.
    3.58 +
    3.59 +            if self.moin_data:
    3.60 +                self.htdocs_dir = self.htdocs_dir_source = join(self.moin_data, "htdocs")
    3.61 +            else:
    3.62 +                self.htdocs_dir = self.htdocs_dir_source = join(self.prefix_site_packages, "MoinMoin", "web", "static", "htdocs")
    3.63 +
    3.64              self.static_url_path = self.url_path
    3.65  
    3.66          # 1.8: moin/share/moin/htdocs (optionally copied to a Web directory)
    3.67  
    3.68          else:
    3.69 -            self.htdocs_dir_source = join(self.instance_dir, "share", "moin", "htdocs")
    3.70 +
    3.71 +            # A shared data directory may be in use.
    3.72 +
    3.73 +            if self.moin_data:
    3.74 +                self.htdocs_dir_source = join(self.moin_data, "htdocs")
    3.75 +            else:
    3.76 +                self.htdocs_dir_source = join(self.instance_dir, "share", "moin", "htdocs")
    3.77  
    3.78              # Add the static identifier to the URL path. For example:
    3.79              # /         -> /moin_static187
    3.80 @@ -424,31 +446,43 @@
    3.81  
    3.82          "Inspect the MoinMoin package information, returning the version."
    3.83  
    3.84 -        this_dir = os.getcwd()
    3.85 -        os.chdir(self.moin_distribution)
    3.86 -
    3.87 -        try:
    3.88 +        if self.moin_distribution:
    3.89              try:
    3.90 -                f = open("PKG-INFO")
    3.91 +                this_dir = os.getcwd()
    3.92                  try:
    3.93 -                    for line in f.xreadlines():
    3.94 -                        columns = line.split()
    3.95 -                        if columns[0] == "Version:":
    3.96 -                            return columns[1]
    3.97 +                    os.chdir(self.moin_distribution)
    3.98 +                    f = open("PKG-INFO")
    3.99 +                    try:
   3.100 +                        for line in f.xreadlines():
   3.101 +                            columns = line.split()
   3.102 +                            if columns[0] == "Version:":
   3.103 +                                return columns[1]
   3.104  
   3.105 -                    return None
   3.106 +                        return None
   3.107 +
   3.108 +                    finally:
   3.109 +                        f.close()
   3.110  
   3.111                  finally:
   3.112 -                    f.close()
   3.113 +                    os.chdir(this_dir)
   3.114  
   3.115              except IOError:
   3.116 -                f = os.popen("%s -c 'from MoinMoin.version import release; print release'" % sys.executable)
   3.117 -                try:
   3.118 -                    return f.read().strip()
   3.119 -                finally:
   3.120 -                    f.close()
   3.121 +                pass
   3.122 +
   3.123 +        # Where no distribution information can be read, try and import an
   3.124 +        # installed version module.
   3.125 +
   3.126 +        f = os.popen("%s -c 'from MoinMoin.version import release; print release'" % sys.executable)
   3.127 +        try:
   3.128 +            return f.read().strip()
   3.129          finally:
   3.130 -            os.chdir(this_dir)
   3.131 +            f.close()
   3.132 +
   3.133 +    def get_moin_data(self):
   3.134 +
   3.135 +        "Return the location of MoinMoin data."
   3.136 +
   3.137 +        return self.moin_data or self.moin_distribution and join(self.moin_distribution, "wiki") or None
   3.138  
   3.139      def get_static_identifier(self):
   3.140  
   3.141 @@ -512,7 +546,13 @@
   3.142          "Set up a Wiki without installing MoinMoin."
   3.143  
   3.144          self.ensure_directories()
   3.145 -        self.install_moin(data_only=1)
   3.146 +
   3.147 +        try:
   3.148 +            self.install_moin(data_only=1)
   3.149 +        except SetupException:
   3.150 +            if not self.moin_data:
   3.151 +                raise
   3.152 +
   3.153          self._setup_wiki()
   3.154  
   3.155      def _setup_wiki(self):
   3.156 @@ -533,6 +573,9 @@
   3.157          # NOTE: Possibly check for an existing installation and skip repeated
   3.158          # NOTE: installation attempts.
   3.159  
   3.160 +        if not self.moin_distribution:
   3.161 +            raise SetupException, "Cannot install MoinMoin without a 'moin_distribution' setting being defined."
   3.162 +
   3.163          this_dir = os.getcwd()
   3.164          os.chdir(self.moin_distribution)
   3.165  
   3.166 @@ -555,12 +598,18 @@
   3.167  
   3.168          "Install Wiki data."
   3.169  
   3.170 +        moin_data = self.get_moin_data()
   3.171 +
   3.172 +        if not moin_data:
   3.173 +            raise SetupException, \
   3.174 +                "Cannot install MoinMoin data without either a 'moin_distribution' or a 'moin_data' setting being defined."
   3.175 +
   3.176          # The default wikiconfig assumes data and underlay in the same directory.
   3.177  
   3.178          status("Installing data and underlay in %s..." % self.conf_dir)
   3.179  
   3.180          for d in ("data", "underlay"):
   3.181 -            source = join(self.moin_distribution, "wiki", d)
   3.182 +            source = join(moin_data, d)
   3.183              source_tar = source + os.path.extsep + "tar"
   3.184              d_tar = source + os.path.extsep + "tar"
   3.185  
   3.186 @@ -590,6 +639,12 @@
   3.187  
   3.188          "Edit the Wiki configuration file."
   3.189  
   3.190 +        moin_data = self.get_moin_data()
   3.191 +
   3.192 +        if not moin_data:
   3.193 +            raise SetupException, \
   3.194 +                "Cannot configure MoinMoin without either a 'moin_distribution' or a 'moin_data' setting being defined."
   3.195 +
   3.196          # NOTE: Single Wiki only so far.
   3.197  
   3.198          # Static URLs seem to be different in MoinMoin 1.9.x.
   3.199 @@ -606,7 +661,7 @@
   3.200          # Copy the Wiki configuration file from the distribution.
   3.201  
   3.202          wikiconfig_py = join(self.conf_dir, "wikiconfig.py")
   3.203 -        shutil.copyfile(join(self.moin_distribution, "wiki", "config", "wikiconfig.py"), wikiconfig_py)
   3.204 +        shutil.copyfile(join(moin_data, "config", "wikiconfig.py"), wikiconfig_py)
   3.205  
   3.206          status("Editing configuration from %s..." % wikiconfig_py)
   3.207  
   3.208 @@ -663,14 +718,17 @@
   3.209          # NOTE: CGI only so far.
   3.210          # NOTE: Permissions should be checked.
   3.211  
   3.212 +        moin_data = self.get_moin_data()
   3.213 +
   3.214          if self.moin_version.startswith("1.9"):
   3.215 -            moin_cgi = join(self.instance_dir, "share", "moin", "server", "moin.fcgi")
   3.216 +            moin_cgi_script = "moin.fcgi"
   3.217          else:
   3.218 -            moin_cgi = join(self.instance_dir, "share", "moin", "server", "moin.cgi")
   3.219 +            moin_cgi_script = "moin.cgi"
   3.220  
   3.221 +        moin_cgi = join(moin_data, "server", moin_cgi_script)
   3.222          moin_cgi_installed = join(self.web_app_dir, "moin.cgi")
   3.223  
   3.224 -        status("Editing moin.cgi script from %s..." % moin_cgi)
   3.225 +        status("Editing moin.cgi script from %s, writing to %s..." % (moin_cgi, moin_cgi_installed))
   3.226  
   3.227          s = readfile(moin_cgi)
   3.228          s = moin_cgi_prefix.sub("sys.path.insert(0, %r)" % self.prefix_site_packages, s)