moinsetup

Changeset

18:79d05f365e2b
2010-06-07 Paul Boddie raw files shortlog changelog graph Added methods to install actions, macros, general plugins and additional theme materials.
TO_DO.txt (file) moinsetup.py (file)
     1.1 --- a/TO_DO.txt	Wed May 26 02:32:05 2010 +0200
     1.2 +++ b/TO_DO.txt	Mon Jun 07 01:18:35 2010 +0200
     1.3 @@ -5,3 +5,4 @@
     1.4  Support Xapian search.
     1.5  Support OpenID and other authentication methods.
     1.6    Remember anonymous_session_lifetime for 1.8.x and cookie_lifetime for 1.9.x.
     1.7 +Support integration of additional theme material with themes.
     2.1 --- a/moinsetup.py	Wed May 26 02:32:05 2010 +0200
     2.2 +++ b/moinsetup.py	Mon Jun 07 01:18:35 2010 +0200
     2.3 @@ -2,6 +2,7 @@
     2.4  
     2.5  from os.path import abspath, exists, extsep, isdir, join, normpath, split
     2.6  from getpass import getpass
     2.7 +from glob import glob
     2.8  import os
     2.9  import sys
    2.10  import shutil
    2.11 @@ -280,6 +281,13 @@
    2.12  
    2.13          return "moin_static%s" % self.moin_version.replace(".", "")
    2.14  
    2.15 +    def get_plugin_directory(self, plugin_type):
    2.16 +
    2.17 +        "Return the directory for plugins of the given 'plugin_type'."
    2.18 +
    2.19 +        data_dir = join(self.conf_dir, "data")
    2.20 +        return join(data_dir, "plugin", plugin_type)
    2.21 +
    2.22      def limited_hosting(self):
    2.23  
    2.24          "Return whether limited Web hosting is being used."
    2.25 @@ -597,8 +605,7 @@
    2.26          theme_name = split(theme_dir)[-1]
    2.27          theme_module = join(theme_dir, theme_name + extsep + "py")
    2.28  
    2.29 -        data_dir = join(self.conf_dir, "data")
    2.30 -        plugin_theme_dir = join(data_dir, "plugin", "theme")
    2.31 +        plugin_theme_dir = self.get_plugin_directory("theme")
    2.32  
    2.33          # Copy the theme module.
    2.34  
    2.35 @@ -634,6 +641,68 @@
    2.36              if exists(css_file_path):
    2.37                  shutil.copy(css_file_path, target_dir)
    2.38  
    2.39 +    def install_plugins(self, plugins_dir, plugin_type):
    2.40 +
    2.41 +        """
    2.42 +        Install Wiki actions provided in the given 'plugins_dir' of the
    2.43 +        specified 'plugin_type'.
    2.44 +        """
    2.45 +
    2.46 +        plugin_target_dir = self.get_plugin_directory(plugin_type)
    2.47 +
    2.48 +        # Copy the modules.
    2.49 +
    2.50 +        status("Copying %s modules to %s..." % (plugin_type, plugin_target_dir))
    2.51 +
    2.52 +        for module in glob(join(plugins_dir, "*%spy" % extsep)):
    2.53 +            shutil.copy(module, plugin_target_dir)
    2.54 +
    2.55 +    def install_actions(self, actions_dir):
    2.56 +
    2.57 +        "Install Wiki actions provided in the given 'actions_dir'."
    2.58 +
    2.59 +        self.install_plugins(actions_dir, "action")
    2.60 +
    2.61 +    def install_macros(self, macros_dir):
    2.62 +
    2.63 +        "Install Wiki macros provided in the given 'macros_dir'."
    2.64 +
    2.65 +        self.install_plugins(macros_dir, "macro")
    2.66 +
    2.67 +    def install_theme_resources(self, theme_resources_dir, theme_name=None):
    2.68 +
    2.69 +        """
    2.70 +        Install theme resources provided in the given 'theme_resources_dir'. If
    2.71 +        a specific 'theme_name' is given, only that theme will be given the
    2.72 +        specified resources.
    2.73 +        """
    2.74 +
    2.75 +        # Copy the resources.
    2.76 +
    2.77 +        filenames = theme_name and [theme_name] or os.listdir(self.htdocs_dir)
    2.78 +
    2.79 +        for filename in filenames:
    2.80 +            theme_dir = join(self.htdocs_dir, filename)
    2.81 +
    2.82 +            if not exists(theme_dir) or not isdir(theme_dir):
    2.83 +                continue
    2.84 +
    2.85 +            copied = 0
    2.86 +
    2.87 +            for d in ("css", "img"):
    2.88 +                source_dir = join(theme_resources_dir, d)
    2.89 +                target_dir = join(theme_dir, d)
    2.90 +
    2.91 +                if not exists(target_dir):
    2.92 +                    continue
    2.93 +
    2.94 +                for resource in glob(join(source_dir, "*%s*" % extsep)):
    2.95 +                    shutil.copy(resource, target_dir)
    2.96 +                    copied = 1
    2.97 +
    2.98 +            if copied:
    2.99 +                status("Copied theme resources into %s..." % theme_dir)
   2.100 +
   2.101  # Command line option syntax.
   2.102  
   2.103  syntax_description = "<argument> ... [ --method=METHOD [ <method-argument> ... ] ]"