1.1 --- a/moinsetup.py Sat Feb 19 02:03:42 2011 +0100
1.2 +++ b/moinsetup.py Tue Feb 22 00:08:36 2011 +0100
1.3 @@ -28,7 +28,7 @@
1.4 import shutil
1.5 import re
1.6
1.7 -__version__ = "0.1"
1.8 +__version__ = "0.2"
1.9
1.10 # Regular expressions for editing MoinMoin scripts and configuration files.
1.11
1.12 @@ -246,9 +246,9 @@
1.13 theme_master = "modernized"
1.14 extra_theme_css_files = ["SlideShow.css"]
1.15
1.16 - def __init__(self, moin_distribution, prefix, web_app_dir, web_site_dir,
1.17 + def __init__(self, moin_distribution, prefix, web_app_dir,
1.18 common_dir, url_path, superuser, site_name, front_page_name,
1.19 - theme_default=None):
1.20 + web_site_dir=None, web_static_dir=None, theme_default=None):
1.21
1.22 """
1.23 Initialise a Wiki installation using the following:
1.24 @@ -258,8 +258,6 @@
1.25 * prefix - the installation prefix (equivalent to /usr)
1.26 * web_app_dir - the directory where Web applications and scripts
1.27 reside (such as /home/www-user/cgi-bin)
1.28 - * web_site_dir - the directory where Web site definitions reside
1.29 - (such as /etc/apache2/sites-available)
1.30 * common_dir - the directory where the Wiki configuration,
1.31 resources and instance will reside (such as
1.32 /home/www-user/mywiki)
1.33 @@ -270,6 +268,11 @@
1.34 * site_name - the name of the site (such as "My Wiki")
1.35 * front_page_name - the front page name for the site (such as
1.36 "FrontPage" or a specific name for the site)
1.37 + * web_site_dir - optional: the directory where Web site
1.38 + definitions reside (such as
1.39 + /etc/apache2/sites-available)
1.40 + * web_static_dir - optional: the directory where static Web
1.41 + resources reside (such as /home/www-user/htdocs)
1.42 * theme_default - optional: the default theme (such as modern)
1.43 """
1.44
1.45 @@ -281,8 +284,8 @@
1.46
1.47 # NOTE: Support the detection of the Apache sites directory.
1.48
1.49 - self.prefix, self.web_app_dir, self.web_site_dir, self.common_dir = \
1.50 - map(abspath, (prefix, web_app_dir, web_site_dir, common_dir))
1.51 + self.prefix, self.web_app_dir, self.web_site_dir, self.web_static_dir, self.common_dir = \
1.52 + map(self._get_abspath, (prefix, web_app_dir, web_site_dir, web_static_dir, common_dir))
1.53
1.54 # Strip any trailing "/" from the URL path.
1.55
1.56 @@ -315,17 +318,33 @@
1.57
1.58 if self.moin_version.startswith("1.9"):
1.59 self.htdocs_dir = self.htdocs_dir_source = join(self.prefix_site_packages, "MoinMoin", "web", "static", "htdocs")
1.60 + self.static_url_path = self.url_path
1.61
1.62 # 1.8: moin/share/moin/htdocs (optionally copied to a Web directory)
1.63
1.64 else:
1.65 self.htdocs_dir_source = join(self.instance_dir, "share", "moin", "htdocs")
1.66
1.67 + # Add the static identifier to the URL path. For example:
1.68 + # / -> /moin_static187
1.69 + # /hgwiki -> /hgwiki-moin_static187
1.70 +
1.71 + self.static_url_path = self.url_path + (self.url_path != "/" and "-" or "") + self.get_static_identifier()
1.72 +
1.73 + # In limited hosting, the static resources directory is related to
1.74 + # the URL path.
1.75 +
1.76 if self.limited_hosting():
1.77 - self.htdocs_dir = join(self.web_app_dir, self.get_static_identifier())
1.78 + self.htdocs_dir = join(self.web_static_dir or self.web_app_dir, self.static_url_path.lstrip("/"))
1.79 +
1.80 + # Otherwise, a mapping is made to the directory.
1.81 +
1.82 else:
1.83 self.htdocs_dir = self.htdocs_dir_source
1.84
1.85 + def _get_abspath(self, d):
1.86 + return d and abspath(d) or None
1.87 +
1.88 def get_moin_version(self):
1.89
1.90 "Inspect the MoinMoin package information, returning the version."
1.91 @@ -373,14 +392,14 @@
1.92
1.93 "Return whether limited Web hosting is being used."
1.94
1.95 - return self.web_site_dir == self.web_app_dir
1.96 + return not self.web_site_dir
1.97
1.98 def ensure_directories(self):
1.99
1.100 "Make sure that all the directories are available."
1.101
1.102 - for d in (self.conf_dir, self.instance_dir, self.web_app_dir, self.web_site_dir):
1.103 - if not exists(d):
1.104 + for d in (self.conf_dir, self.instance_dir, self.web_app_dir, self.web_static_dir, self.web_site_dir):
1.105 + if d is not None and not exists(d):
1.106 os.makedirs(d)
1.107
1.108 def get_theme_directories(self, theme_name=None):
1.109 @@ -428,9 +447,8 @@
1.110 self.install_data()
1.111 self.configure_moin()
1.112 self.edit_moin_script()
1.113 - self.edit_moin_web_script()
1.114 self.add_superuser()
1.115 - self.make_site_files()
1.116 + self.edit_moin_web_script(self.make_site_files())
1.117 self.make_post_install_script()
1.118
1.119 def install_moin(self, data_only=0):
1.120 @@ -506,14 +524,8 @@
1.121 # NOTE: acceptable if less efficient.
1.122
1.123 if self.moin_version.startswith("1.9"):
1.124 - self.static_url_path = self.url_path
1.125 url_prefix_static = "%r + url_prefix_static" % self.static_url_path
1.126 else:
1.127 - # Add the static identifier to the URL path. For example:
1.128 - # / -> /moin_static187
1.129 - # /hgwiki -> /hgwiki/moin_static187
1.130 -
1.131 - self.static_url_path = self.url_path + (self.url_path != "/" and "-" or "") + self.get_static_identifier()
1.132 url_prefix_static = "%r" % self.static_url_path
1.133
1.134 # Copy the Wiki configuration file from the distribution.
1.135 @@ -569,7 +581,7 @@
1.136
1.137 writefile(moin_script, s)
1.138
1.139 - def edit_moin_web_script(self):
1.140 + def edit_moin_web_script(self, site_file_configured=1):
1.141
1.142 "Edit and install CGI script."
1.143
1.144 @@ -593,10 +605,13 @@
1.145 # URL rewriting.
1.146
1.147 if self.limited_hosting():
1.148 - if self.moin_version.startswith("1.9"):
1.149 - s = moin_cgi_fix_script_name.sub(r"\1\2 %r" % self.url_path, s)
1.150 + if not site_file_configured:
1.151 + note("Site file not configured: script name not changed.")
1.152 else:
1.153 - s = moin_cgi_properties.sub(r"\1\2 %r" % {"script_name" : self.url_path}, s)
1.154 + if self.moin_version.startswith("1.9"):
1.155 + s = moin_cgi_fix_script_name.sub(r"\1\2 %r" % self.url_path, s)
1.156 + else:
1.157 + s = moin_cgi_properties.sub(r"\1\2 %r" % {"script_name" : self.url_path}, s)
1.158
1.159 # NOTE: Use CGI for now.
1.160
1.161 @@ -648,17 +663,29 @@
1.162 if not self.moin_version.startswith("1.9"):
1.163 s += apache_site_extra_moin18 % self.__dict__
1.164
1.165 + status("Writing Apache site definitions to %s..." % site_def)
1.166 + writefile(site_def, s)
1.167 +
1.168 + note("Copy the site definitions to the appropriate sites directory if appropriate.")
1.169 + note("Then, make sure that the site is enabled by running the appropriate tools (such as a2ensite).")
1.170 +
1.171 + return 1
1.172 +
1.173 # Otherwise, use an .htaccess file.
1.174
1.175 else:
1.176 - site_def = join(self.web_site_dir, ".htaccess")
1.177 + site_def = join(self.web_app_dir, ".htaccess")
1.178
1.179 s = apache_htaccess_combined_mod_rewrite % self.__dict__
1.180
1.181 - status("Writing Apache site definitions to %s..." % site_def)
1.182 - writefile(site_def, s)
1.183 - note("Copy the site definitions to the appropriate sites directory if appropriate.")
1.184 - note("Then, make sure that the site is enabled by running the appropriate tools (such as a2ensite).")
1.185 + status("Writing .htaccess file to %s..." % site_def)
1.186 + try:
1.187 + writefile(site_def, s)
1.188 + except IOError:
1.189 + note("The .htaccess file could not be written. This will also affect the script name setting.")
1.190 + return 0
1.191 + else:
1.192 + return 1
1.193
1.194 def make_post_install_script(self):
1.195