# HG changeset patch # User Paul Boddie # Date 1314485681 -7200 # Node ID 9a95862669f6190a9c2ab8f73ea7b167a2416b8f # Parent 8f5249daf6bcd165c6ea3c5cd6a45db47ac8e736 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. diff -r 8f5249daf6bc -r 9a95862669f6 README.txt --- a/README.txt Sun Jun 26 00:33:55 2011 +0200 +++ b/README.txt Sun Aug 28 00:54:41 2011 +0200 @@ -30,6 +30,10 @@ moin_distribution A path to a MoinMoin distribution directory, which can also be a clone of a MoinMoin repository. +moin_data A path to the MoinMoin shared data, which may be installed + from a system package in a directory such as + /usr/share/moin. + prefix The directory prefix containing lib, bin and share directories where MoinMoin is (or will be) installed. Although this follows the layout of the /usr directory (on @@ -164,6 +168,13 @@ CMDsyntax Tested with 0.91 Source: http://www.boddie.org.uk/david/Projects/Python/CMDSyntax/index.html +New in moinsetup 0.3 (Changes since moinsetup 0.2) +-------------------------------------------------- + + * Added a moin_data setting and made moin_distribution optional so that when + MoinMoin is installed from a system package, the non-installation actions + can still be performed. + New in moinsetup 0.2 (Changes since moinsetup 0.1) -------------------------------------------------- diff -r 8f5249daf6bc -r 9a95862669f6 moinsetup.cfg --- a/moinsetup.cfg Sun Jun 26 00:33:55 2011 +0200 +++ b/moinsetup.cfg Sun Aug 28 00:54:41 2011 +0200 @@ -1,5 +1,6 @@ [installation] moin_distribution = moin-1.9-hg +moin_data = prefix = moin web_app_dir = webapps web_static_dir = diff -r 8f5249daf6bc -r 9a95862669f6 moinsetup.py --- a/moinsetup.py Sun Jun 26 00:33:55 2011 +0200 +++ b/moinsetup.py Sun Aug 28 00:54:41 2011 +0200 @@ -29,7 +29,7 @@ import re import tempfile -__version__ = "0.2" +__version__ = "0.3" # Regular expressions for editing MoinMoin scripts and configuration files. @@ -129,6 +129,12 @@ # Classes. +class SetupException(Exception): + + "An exception indicating a problem with a setup action." + + pass + class Configuration: "A class representing the configuration." @@ -321,7 +327,7 @@ theme_master = "modernized" extra_theme_css_files = ["SlideShow.css"] - def __init__(self, moin_distribution, prefix, web_app_dir, + def __init__(self, moin_distribution, moin_data, prefix, web_app_dir, common_dir, url_path, superuser, site_name, front_page_name, web_site_dir=None, web_static_dir=None, theme_default=None): @@ -330,6 +336,8 @@ * moin_distribution - the directory containing a MoinMoin source distribution + * moin_data - the directory containing MoinMoin shared data + (can be omitted if 'moin_distribution' is given) * 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) @@ -352,6 +360,7 @@ """ self.moin_distribution = moin_distribution + self.moin_data = moin_data self.superuser = superuser self.site_name = site_name self.front_page_name = front_page_name @@ -392,13 +401,26 @@ # 1.9: moin/lib/python2.x/site-packages/MoinMoin/web/static/htdocs if self.moin_version.startswith("1.9"): - self.htdocs_dir = self.htdocs_dir_source = join(self.prefix_site_packages, "MoinMoin", "web", "static", "htdocs") + + # A shared data directory may be in use. + + if self.moin_data: + self.htdocs_dir = self.htdocs_dir_source = join(self.moin_data, "htdocs") + else: + self.htdocs_dir = self.htdocs_dir_source = join(self.prefix_site_packages, "MoinMoin", "web", "static", "htdocs") + self.static_url_path = self.url_path # 1.8: moin/share/moin/htdocs (optionally copied to a Web directory) else: - self.htdocs_dir_source = join(self.instance_dir, "share", "moin", "htdocs") + + # A shared data directory may be in use. + + if self.moin_data: + self.htdocs_dir_source = join(self.moin_data, "htdocs") + else: + self.htdocs_dir_source = join(self.instance_dir, "share", "moin", "htdocs") # Add the static identifier to the URL path. For example: # / -> /moin_static187 @@ -424,31 +446,43 @@ "Inspect the MoinMoin package information, returning the version." - this_dir = os.getcwd() - os.chdir(self.moin_distribution) - - try: + if self.moin_distribution: try: - f = open("PKG-INFO") + this_dir = os.getcwd() try: - for line in f.xreadlines(): - columns = line.split() - if columns[0] == "Version:": - return columns[1] + os.chdir(self.moin_distribution) + f = open("PKG-INFO") + try: + for line in f.xreadlines(): + columns = line.split() + if columns[0] == "Version:": + return columns[1] - return None + return None + + finally: + f.close() finally: - f.close() + os.chdir(this_dir) except IOError: - f = os.popen("%s -c 'from MoinMoin.version import release; print release'" % sys.executable) - try: - return f.read().strip() - finally: - f.close() + pass + + # Where no distribution information can be read, try and import an + # installed version module. + + f = os.popen("%s -c 'from MoinMoin.version import release; print release'" % sys.executable) + try: + return f.read().strip() finally: - os.chdir(this_dir) + f.close() + + def get_moin_data(self): + + "Return the location of MoinMoin data." + + return self.moin_data or self.moin_distribution and join(self.moin_distribution, "wiki") or None def get_static_identifier(self): @@ -512,7 +546,13 @@ "Set up a Wiki without installing MoinMoin." self.ensure_directories() - self.install_moin(data_only=1) + + try: + self.install_moin(data_only=1) + except SetupException: + if not self.moin_data: + raise + self._setup_wiki() def _setup_wiki(self): @@ -533,6 +573,9 @@ # NOTE: Possibly check for an existing installation and skip repeated # NOTE: installation attempts. + if not self.moin_distribution: + raise SetupException, "Cannot install MoinMoin without a 'moin_distribution' setting being defined." + this_dir = os.getcwd() os.chdir(self.moin_distribution) @@ -555,12 +598,18 @@ "Install Wiki data." + moin_data = self.get_moin_data() + + if not moin_data: + raise SetupException, \ + "Cannot install MoinMoin data without either a 'moin_distribution' or a 'moin_data' setting being defined." + # The default wikiconfig assumes data and underlay in the same directory. status("Installing data and underlay in %s..." % self.conf_dir) for d in ("data", "underlay"): - source = join(self.moin_distribution, "wiki", d) + source = join(moin_data, d) source_tar = source + os.path.extsep + "tar" d_tar = source + os.path.extsep + "tar" @@ -590,6 +639,12 @@ "Edit the Wiki configuration file." + moin_data = self.get_moin_data() + + if not moin_data: + raise SetupException, \ + "Cannot configure MoinMoin without either a 'moin_distribution' or a 'moin_data' setting being defined." + # NOTE: Single Wiki only so far. # Static URLs seem to be different in MoinMoin 1.9.x. @@ -606,7 +661,7 @@ # Copy the Wiki configuration file from the distribution. wikiconfig_py = join(self.conf_dir, "wikiconfig.py") - shutil.copyfile(join(self.moin_distribution, "wiki", "config", "wikiconfig.py"), wikiconfig_py) + shutil.copyfile(join(moin_data, "config", "wikiconfig.py"), wikiconfig_py) status("Editing configuration from %s..." % wikiconfig_py) @@ -663,14 +718,17 @@ # NOTE: CGI only so far. # NOTE: Permissions should be checked. + moin_data = self.get_moin_data() + if self.moin_version.startswith("1.9"): - moin_cgi = join(self.instance_dir, "share", "moin", "server", "moin.fcgi") + moin_cgi_script = "moin.fcgi" else: - moin_cgi = join(self.instance_dir, "share", "moin", "server", "moin.cgi") + moin_cgi_script = "moin.cgi" + moin_cgi = join(moin_data, "server", moin_cgi_script) moin_cgi_installed = join(self.web_app_dir, "moin.cgi") - status("Editing moin.cgi script from %s..." % moin_cgi) + status("Editing moin.cgi script from %s, writing to %s..." % (moin_cgi, moin_cgi_installed)) s = readfile(moin_cgi) s = moin_cgi_prefix.sub("sys.path.insert(0, %r)" % self.prefix_site_packages, s)