1.1 --- a/moinsetup.py Sun Jun 26 00:33:55 2011 +0200
1.2 +++ b/moinsetup.py Sun Aug 28 00:54:41 2011 +0200
1.3 @@ -29,7 +29,7 @@
1.4 import re
1.5 import tempfile
1.6
1.7 -__version__ = "0.2"
1.8 +__version__ = "0.3"
1.9
1.10 # Regular expressions for editing MoinMoin scripts and configuration files.
1.11
1.12 @@ -129,6 +129,12 @@
1.13
1.14 # Classes.
1.15
1.16 +class SetupException(Exception):
1.17 +
1.18 + "An exception indicating a problem with a setup action."
1.19 +
1.20 + pass
1.21 +
1.22 class Configuration:
1.23
1.24 "A class representing the configuration."
1.25 @@ -321,7 +327,7 @@
1.26 theme_master = "modernized"
1.27 extra_theme_css_files = ["SlideShow.css"]
1.28
1.29 - def __init__(self, moin_distribution, prefix, web_app_dir,
1.30 + def __init__(self, moin_distribution, moin_data, prefix, web_app_dir,
1.31 common_dir, url_path, superuser, site_name, front_page_name,
1.32 web_site_dir=None, web_static_dir=None, theme_default=None):
1.33
1.34 @@ -330,6 +336,8 @@
1.35
1.36 * moin_distribution - the directory containing a MoinMoin source
1.37 distribution
1.38 + * moin_data - the directory containing MoinMoin shared data
1.39 + (can be omitted if 'moin_distribution' is given)
1.40 * prefix - the installation prefix (equivalent to /usr)
1.41 * web_app_dir - the directory where Web applications and scripts
1.42 reside (such as /home/www-user/cgi-bin)
1.43 @@ -352,6 +360,7 @@
1.44 """
1.45
1.46 self.moin_distribution = moin_distribution
1.47 + self.moin_data = moin_data
1.48 self.superuser = superuser
1.49 self.site_name = site_name
1.50 self.front_page_name = front_page_name
1.51 @@ -392,13 +401,26 @@
1.52 # 1.9: moin/lib/python2.x/site-packages/MoinMoin/web/static/htdocs
1.53
1.54 if self.moin_version.startswith("1.9"):
1.55 - self.htdocs_dir = self.htdocs_dir_source = join(self.prefix_site_packages, "MoinMoin", "web", "static", "htdocs")
1.56 +
1.57 + # A shared data directory may be in use.
1.58 +
1.59 + if self.moin_data:
1.60 + self.htdocs_dir = self.htdocs_dir_source = join(self.moin_data, "htdocs")
1.61 + else:
1.62 + self.htdocs_dir = self.htdocs_dir_source = join(self.prefix_site_packages, "MoinMoin", "web", "static", "htdocs")
1.63 +
1.64 self.static_url_path = self.url_path
1.65
1.66 # 1.8: moin/share/moin/htdocs (optionally copied to a Web directory)
1.67
1.68 else:
1.69 - self.htdocs_dir_source = join(self.instance_dir, "share", "moin", "htdocs")
1.70 +
1.71 + # A shared data directory may be in use.
1.72 +
1.73 + if self.moin_data:
1.74 + self.htdocs_dir_source = join(self.moin_data, "htdocs")
1.75 + else:
1.76 + self.htdocs_dir_source = join(self.instance_dir, "share", "moin", "htdocs")
1.77
1.78 # Add the static identifier to the URL path. For example:
1.79 # / -> /moin_static187
1.80 @@ -424,31 +446,43 @@
1.81
1.82 "Inspect the MoinMoin package information, returning the version."
1.83
1.84 - this_dir = os.getcwd()
1.85 - os.chdir(self.moin_distribution)
1.86 -
1.87 - try:
1.88 + if self.moin_distribution:
1.89 try:
1.90 - f = open("PKG-INFO")
1.91 + this_dir = os.getcwd()
1.92 try:
1.93 - for line in f.xreadlines():
1.94 - columns = line.split()
1.95 - if columns[0] == "Version:":
1.96 - return columns[1]
1.97 + os.chdir(self.moin_distribution)
1.98 + f = open("PKG-INFO")
1.99 + try:
1.100 + for line in f.xreadlines():
1.101 + columns = line.split()
1.102 + if columns[0] == "Version:":
1.103 + return columns[1]
1.104
1.105 - return None
1.106 + return None
1.107 +
1.108 + finally:
1.109 + f.close()
1.110
1.111 finally:
1.112 - f.close()
1.113 + os.chdir(this_dir)
1.114
1.115 except IOError:
1.116 - f = os.popen("%s -c 'from MoinMoin.version import release; print release'" % sys.executable)
1.117 - try:
1.118 - return f.read().strip()
1.119 - finally:
1.120 - f.close()
1.121 + pass
1.122 +
1.123 + # Where no distribution information can be read, try and import an
1.124 + # installed version module.
1.125 +
1.126 + f = os.popen("%s -c 'from MoinMoin.version import release; print release'" % sys.executable)
1.127 + try:
1.128 + return f.read().strip()
1.129 finally:
1.130 - os.chdir(this_dir)
1.131 + f.close()
1.132 +
1.133 + def get_moin_data(self):
1.134 +
1.135 + "Return the location of MoinMoin data."
1.136 +
1.137 + return self.moin_data or self.moin_distribution and join(self.moin_distribution, "wiki") or None
1.138
1.139 def get_static_identifier(self):
1.140
1.141 @@ -512,7 +546,13 @@
1.142 "Set up a Wiki without installing MoinMoin."
1.143
1.144 self.ensure_directories()
1.145 - self.install_moin(data_only=1)
1.146 +
1.147 + try:
1.148 + self.install_moin(data_only=1)
1.149 + except SetupException:
1.150 + if not self.moin_data:
1.151 + raise
1.152 +
1.153 self._setup_wiki()
1.154
1.155 def _setup_wiki(self):
1.156 @@ -533,6 +573,9 @@
1.157 # NOTE: Possibly check for an existing installation and skip repeated
1.158 # NOTE: installation attempts.
1.159
1.160 + if not self.moin_distribution:
1.161 + raise SetupException, "Cannot install MoinMoin without a 'moin_distribution' setting being defined."
1.162 +
1.163 this_dir = os.getcwd()
1.164 os.chdir(self.moin_distribution)
1.165
1.166 @@ -555,12 +598,18 @@
1.167
1.168 "Install Wiki data."
1.169
1.170 + moin_data = self.get_moin_data()
1.171 +
1.172 + if not moin_data:
1.173 + raise SetupException, \
1.174 + "Cannot install MoinMoin data without either a 'moin_distribution' or a 'moin_data' setting being defined."
1.175 +
1.176 # The default wikiconfig assumes data and underlay in the same directory.
1.177
1.178 status("Installing data and underlay in %s..." % self.conf_dir)
1.179
1.180 for d in ("data", "underlay"):
1.181 - source = join(self.moin_distribution, "wiki", d)
1.182 + source = join(moin_data, d)
1.183 source_tar = source + os.path.extsep + "tar"
1.184 d_tar = source + os.path.extsep + "tar"
1.185
1.186 @@ -590,6 +639,12 @@
1.187
1.188 "Edit the Wiki configuration file."
1.189
1.190 + moin_data = self.get_moin_data()
1.191 +
1.192 + if not moin_data:
1.193 + raise SetupException, \
1.194 + "Cannot configure MoinMoin without either a 'moin_distribution' or a 'moin_data' setting being defined."
1.195 +
1.196 # NOTE: Single Wiki only so far.
1.197
1.198 # Static URLs seem to be different in MoinMoin 1.9.x.
1.199 @@ -606,7 +661,7 @@
1.200 # Copy the Wiki configuration file from the distribution.
1.201
1.202 wikiconfig_py = join(self.conf_dir, "wikiconfig.py")
1.203 - shutil.copyfile(join(self.moin_distribution, "wiki", "config", "wikiconfig.py"), wikiconfig_py)
1.204 + shutil.copyfile(join(moin_data, "config", "wikiconfig.py"), wikiconfig_py)
1.205
1.206 status("Editing configuration from %s..." % wikiconfig_py)
1.207
1.208 @@ -663,14 +718,17 @@
1.209 # NOTE: CGI only so far.
1.210 # NOTE: Permissions should be checked.
1.211
1.212 + moin_data = self.get_moin_data()
1.213 +
1.214 if self.moin_version.startswith("1.9"):
1.215 - moin_cgi = join(self.instance_dir, "share", "moin", "server", "moin.fcgi")
1.216 + moin_cgi_script = "moin.fcgi"
1.217 else:
1.218 - moin_cgi = join(self.instance_dir, "share", "moin", "server", "moin.cgi")
1.219 + moin_cgi_script = "moin.cgi"
1.220
1.221 + moin_cgi = join(moin_data, "server", moin_cgi_script)
1.222 moin_cgi_installed = join(self.web_app_dir, "moin.cgi")
1.223
1.224 - status("Editing moin.cgi script from %s..." % moin_cgi)
1.225 + status("Editing moin.cgi script from %s, writing to %s..." % (moin_cgi, moin_cgi_installed))
1.226
1.227 s = readfile(moin_cgi)
1.228 s = moin_cgi_prefix.sub("sys.path.insert(0, %r)" % self.prefix_site_packages, s)