moinsetup

Changeset

25:46b79e2490e8
2010-12-19 Paul Boddie raw files shortlog changelog graph Added methods for making page packages and installing them. Simplified the command syntax slightly.
moinsetup.py (file)
     1.1 --- a/moinsetup.py	Fri Nov 19 01:22:39 2010 +0100
     1.2 +++ b/moinsetup.py	Sun Dec 19 22:24:17 2010 +0100
     1.3 @@ -3,6 +3,7 @@
     1.4  from os.path import abspath, exists, extsep, isdir, join, normpath, split
     1.5  from getpass import getpass
     1.6  from glob import glob
     1.7 +from zipfile import ZipFile
     1.8  import os
     1.9  import sys
    1.10  import shutil
    1.11 @@ -175,13 +176,21 @@
    1.12          "make_site_files",
    1.13          "make_post_install_script",
    1.14          "reconfigure_moin",
    1.15 +
    1.16 +        # Post-installation activities.
    1.17 +
    1.18          "install_theme",
    1.19          "install_extension_package",
    1.20          "install_plugins",
    1.21          "install_actions",
    1.22          "install_macros",
    1.23          "install_theme_resources",
    1.24 -        "edit_theme_stylesheet"
    1.25 +        "edit_theme_stylesheet",
    1.26 +
    1.27 +        # Other activities.
    1.28 +
    1.29 +        "make_page_package",
    1.30 +        "install_page_package",
    1.31          )
    1.32  
    1.33      # NOTE: Need to detect Web server user.
    1.34 @@ -240,11 +249,12 @@
    1.35              self.url_path = url_path
    1.36  
    1.37          # Define and create specific directories.
    1.38 +        # Here are the configuration and actual Wiki data directories.
    1.39  
    1.40          self.conf_dir = join(self.common_dir, "conf")
    1.41          self.instance_dir = join(self.common_dir, "wikidata")
    1.42  
    1.43 -        # Define useful directories.
    1.44 +        # Define the place where the MoinMoin package will actually reside.
    1.45  
    1.46          self.prefix_site_packages = join(self.prefix, "lib", "python%s.%s" % sys.version_info[:2], "site-packages")
    1.47  
    1.48 @@ -839,6 +849,49 @@
    1.49                      status("Adding %s to %s in theme %s..." % (imported_stylesheet, theme_stylesheet, theme_name))
    1.50                      writefile(theme_stylesheet_filename, s)
    1.51  
    1.52 +    def make_page_package(self, page_directory, package_filename):
    1.53 +
    1.54 +        """
    1.55 +        Make a package containing the pages in 'page_directory', using the
    1.56 +        filenames as the page names, and writing the package to a file with the
    1.57 +        given 'package_filename'.
    1.58 +        """
    1.59 +
    1.60 +        package = ZipFile(package_filename, "w")
    1.61 +
    1.62 +        try:
    1.63 +            script = ["MoinMoinPackage|1"]
    1.64 +
    1.65 +            for filename in os.listdir(page_directory):
    1.66 +                package.write(join(page_directory, filename), filename)
    1.67 +                script.append("AddRevision|%s|%s" % (filename, filename))
    1.68 +
    1.69 +            package.writestr("MOIN_PACKAGE", "\n".join(script))
    1.70 +
    1.71 +        finally:
    1.72 +            package.close()
    1.73 +
    1.74 +    def install_page_package(self, package_filename):
    1.75 +
    1.76 +        """
    1.77 +        Install a package from the file with the given 'package_filename'.
    1.78 +        """
    1.79 +
    1.80 +        path = os.environ.get("PYTHONPATH", "")
    1.81 +
    1.82 +        if path:
    1.83 +            os.environ["PYTHONPATH"] = path + ":" + self.prefix_site_packages + ":" + self.conf_dir
    1.84 +        else:
    1.85 +            os.environ["PYTHONPATH"] = self.prefix_site_packages + ":" + self.conf_dir
    1.86 +
    1.87 +        installer = join(self.prefix_site_packages, "MoinMoin", "packages.py")
    1.88 +        os.system("python %s i %s" % (installer, package_filename))
    1.89 +
    1.90 +        if path:
    1.91 +            os.environ["PYTHONPATH"] = path
    1.92 +        else:
    1.93 +            del os.environ["PYTHONPATH"]
    1.94 +
    1.95  def show_methods():
    1.96      print "Methods:"
    1.97      print
    1.98 @@ -849,7 +902,7 @@
    1.99  
   1.100  # Command line option syntax.
   1.101  
   1.102 -syntax_description = "[ -f <config-filename> ] --method=METHOD [ <method-argument> ... ]"
   1.103 +syntax_description = "[ -f <config-filename> ] ( <method> | --method=METHOD ) [ <method-argument> ... ]"
   1.104  
   1.105  # Main program.
   1.106