# HG changeset patch # User Paul Boddie # Date 1298329716 -3600 # Node ID 5bdd693e33927fd6628fa9e755716b6e7e547fc9 # Parent 058b81935416083cfe61647962777a7eb931bbe0 Introduced a static resources directory setting, and made this new setting and the site directory setting optional. Moved static URL and resource directory definition into the initialiser, making limited hosting use the same kind of static URL identifier for the root directory of static resources as the more general hosting uses in an Alias definition. Introduced detection of .htaccess writing problems, preventing redefinition of the script name in moin.cgi until the problems are rectified. diff -r 058b81935416 -r 5bdd693e3392 moinsetup.py --- a/moinsetup.py Sat Feb 19 02:03:42 2011 +0100 +++ b/moinsetup.py Tue Feb 22 00:08:36 2011 +0100 @@ -28,7 +28,7 @@ import shutil import re -__version__ = "0.1" +__version__ = "0.2" # Regular expressions for editing MoinMoin scripts and configuration files. @@ -246,9 +246,9 @@ theme_master = "modernized" extra_theme_css_files = ["SlideShow.css"] - def __init__(self, moin_distribution, prefix, web_app_dir, web_site_dir, + def __init__(self, moin_distribution, prefix, web_app_dir, common_dir, url_path, superuser, site_name, front_page_name, - theme_default=None): + web_site_dir=None, web_static_dir=None, theme_default=None): """ Initialise a Wiki installation using the following: @@ -258,8 +258,6 @@ * 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) - * web_site_dir - the directory where Web site definitions reside - (such as /etc/apache2/sites-available) * common_dir - the directory where the Wiki configuration, resources and instance will reside (such as /home/www-user/mywiki) @@ -270,6 +268,11 @@ * site_name - the name of the site (such as "My Wiki") * front_page_name - the front page name for the site (such as "FrontPage" or a specific name for the site) + * web_site_dir - optional: the directory where Web site + definitions reside (such as + /etc/apache2/sites-available) + * web_static_dir - optional: the directory where static Web + resources reside (such as /home/www-user/htdocs) * theme_default - optional: the default theme (such as modern) """ @@ -281,8 +284,8 @@ # NOTE: Support the detection of the Apache sites directory. - self.prefix, self.web_app_dir, self.web_site_dir, self.common_dir = \ - map(abspath, (prefix, web_app_dir, web_site_dir, common_dir)) + self.prefix, self.web_app_dir, self.web_site_dir, self.web_static_dir, self.common_dir = \ + map(self._get_abspath, (prefix, web_app_dir, web_site_dir, web_static_dir, common_dir)) # Strip any trailing "/" from the URL path. @@ -315,17 +318,33 @@ if self.moin_version.startswith("1.9"): 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") + # Add the static identifier to the URL path. For example: + # / -> /moin_static187 + # /hgwiki -> /hgwiki-moin_static187 + + self.static_url_path = self.url_path + (self.url_path != "/" and "-" or "") + self.get_static_identifier() + + # In limited hosting, the static resources directory is related to + # the URL path. + if self.limited_hosting(): - self.htdocs_dir = join(self.web_app_dir, self.get_static_identifier()) + self.htdocs_dir = join(self.web_static_dir or self.web_app_dir, self.static_url_path.lstrip("/")) + + # Otherwise, a mapping is made to the directory. + else: self.htdocs_dir = self.htdocs_dir_source + def _get_abspath(self, d): + return d and abspath(d) or None + def get_moin_version(self): "Inspect the MoinMoin package information, returning the version." @@ -373,14 +392,14 @@ "Return whether limited Web hosting is being used." - return self.web_site_dir == self.web_app_dir + return not self.web_site_dir def ensure_directories(self): "Make sure that all the directories are available." - for d in (self.conf_dir, self.instance_dir, self.web_app_dir, self.web_site_dir): - if not exists(d): + for d in (self.conf_dir, self.instance_dir, self.web_app_dir, self.web_static_dir, self.web_site_dir): + if d is not None and not exists(d): os.makedirs(d) def get_theme_directories(self, theme_name=None): @@ -428,9 +447,8 @@ self.install_data() self.configure_moin() self.edit_moin_script() - self.edit_moin_web_script() self.add_superuser() - self.make_site_files() + self.edit_moin_web_script(self.make_site_files()) self.make_post_install_script() def install_moin(self, data_only=0): @@ -506,14 +524,8 @@ # NOTE: acceptable if less efficient. if self.moin_version.startswith("1.9"): - self.static_url_path = self.url_path url_prefix_static = "%r + url_prefix_static" % self.static_url_path else: - # Add the static identifier to the URL path. For example: - # / -> /moin_static187 - # /hgwiki -> /hgwiki/moin_static187 - - self.static_url_path = self.url_path + (self.url_path != "/" and "-" or "") + self.get_static_identifier() url_prefix_static = "%r" % self.static_url_path # Copy the Wiki configuration file from the distribution. @@ -569,7 +581,7 @@ writefile(moin_script, s) - def edit_moin_web_script(self): + def edit_moin_web_script(self, site_file_configured=1): "Edit and install CGI script." @@ -593,10 +605,13 @@ # URL rewriting. if self.limited_hosting(): - if self.moin_version.startswith("1.9"): - s = moin_cgi_fix_script_name.sub(r"\1\2 %r" % self.url_path, s) + if not site_file_configured: + note("Site file not configured: script name not changed.") else: - s = moin_cgi_properties.sub(r"\1\2 %r" % {"script_name" : self.url_path}, s) + if self.moin_version.startswith("1.9"): + s = moin_cgi_fix_script_name.sub(r"\1\2 %r" % self.url_path, s) + else: + s = moin_cgi_properties.sub(r"\1\2 %r" % {"script_name" : self.url_path}, s) # NOTE: Use CGI for now. @@ -648,17 +663,29 @@ if not self.moin_version.startswith("1.9"): s += apache_site_extra_moin18 % self.__dict__ + status("Writing Apache site definitions to %s..." % site_def) + writefile(site_def, s) + + note("Copy the site definitions to the appropriate sites directory if appropriate.") + note("Then, make sure that the site is enabled by running the appropriate tools (such as a2ensite).") + + return 1 + # Otherwise, use an .htaccess file. else: - site_def = join(self.web_site_dir, ".htaccess") + site_def = join(self.web_app_dir, ".htaccess") s = apache_htaccess_combined_mod_rewrite % self.__dict__ - status("Writing Apache site definitions to %s..." % site_def) - writefile(site_def, s) - note("Copy the site definitions to the appropriate sites directory if appropriate.") - note("Then, make sure that the site is enabled by running the appropriate tools (such as a2ensite).") + status("Writing .htaccess file to %s..." % site_def) + try: + writefile(site_def, s) + except IOError: + note("The .htaccess file could not be written. This will also affect the script name setting.") + return 0 + else: + return 1 def make_post_install_script(self):