1.1 --- a/docs/wiki/Administration Tue Dec 20 23:33:05 2016 +0100
1.2 +++ b/docs/wiki/Administration Thu Jan 26 17:16:21 2017 +0100
1.3 @@ -132,6 +132,23 @@
1.4 operating system distribution. The `tools/install.sh` script runs the above
1.5 tool as part of the installation process.
1.6
1.7 +== Adding Storage Modules ==
1.8 +
1.9 +Storage modules reside in the `imiptools.stores` package. Extra modules can be
1.10 +installed in this package by adding files or directories to the `stores`
1.11 +directory within the software installation.
1.12 +
1.13 +After adding modules, a tool must be run to register the new modules:
1.14 +
1.15 +{{{
1.16 +tools/update_storage_modules.py
1.17 +}}}
1.18 +
1.19 +It is envisaged that the installation of additional storage modules and the
1.20 +use of this tool will be performed by the packaging system provided by an
1.21 +operating system distribution. The `tools/install.sh` script runs the above
1.22 +tool as part of the installation process.
1.23 +
1.24 == Copying Stores and Changing Store Types ==
1.25
1.26 A rudimentary tool is provided that can copy data between stores, even those of
2.1 --- a/imiptools/stores/__init__.py Tue Dec 20 23:33:05 2016 +0100
2.2 +++ b/imiptools/stores/__init__.py Thu Jan 26 17:16:21 2017 +0100
2.3 @@ -3,7 +3,7 @@
2.4 """
2.5 General support for calendar data storage.
2.6
2.7 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
2.8 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
2.9
2.10 This program is free software; you can redistribute it and/or modify it under
2.11 the terms of the GNU General Public License as published by the Free Software
2.12 @@ -19,15 +19,7 @@
2.13 this program. If not, see <http://www.gnu.org/licenses/>.
2.14 """
2.15
2.16 -from imiptools.stores import file
2.17 -from imiptools.stores.database import stores as database_stores
2.18 -
2.19 -# Build a catalogue of store types.
2.20 -
2.21 -stores = {
2.22 - "file" : file,
2.23 - }
2.24 -stores.update(database_stores)
2.25 +from imiptools.stores.manifest import stores
2.26
2.27 # Access functions.
2.28
2.29 @@ -35,7 +27,7 @@
2.30 return stores[store_type].Store(store_dir)
2.31
2.32 def get_publisher(publishing_dir):
2.33 - return file.Publisher(publishing_dir)
2.34 + return stores["file"].Publisher(publishing_dir)
2.35
2.36 def get_journal(store_type, journal_dir):
2.37 return stores[store_type].Journal(journal_dir)
3.1 --- a/imiptools/stores/database/__init__.py Tue Dec 20 23:33:05 2016 +0100
3.2 +++ b/imiptools/stores/database/__init__.py Thu Jan 26 17:16:21 2017 +0100
3.3 @@ -1,28 +0,0 @@
3.4 -#!/usr/bin/env python
3.5 -
3.6 -"""
3.7 -General support for database stores.
3.8 -
3.9 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
3.10 -
3.11 -This program is free software; you can redistribute it and/or modify it under
3.12 -the terms of the GNU General Public License as published by the Free Software
3.13 -Foundation; either version 3 of the License, or (at your option) any later
3.14 -version.
3.15 -
3.16 -This program is distributed in the hope that it will be useful, but WITHOUT
3.17 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
3.18 -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
3.19 -details.
3.20 -
3.21 -You should have received a copy of the GNU General Public License along with
3.22 -this program. If not, see <http://www.gnu.org/licenses/>.
3.23 -"""
3.24 -
3.25 -from imiptools.stores.database import postgresql
3.26 -
3.27 -stores = {
3.28 - "postgresql" : postgresql,
3.29 - }
3.30 -
3.31 -# vim: tabstop=4 expandtab shiftwidth=4
4.1 --- a/tools/install.sh Tue Dec 20 23:33:05 2016 +0100
4.2 +++ b/tools/install.sh Thu Jan 26 17:16:21 2017 +0100
4.3 @@ -3,7 +3,7 @@
4.4 # This tool installs the imip-agent software and message resources. It is
4.5 # configured by the contents of the config.sh script.
4.6 #
4.7 -# Copyright (C) 2014, 2015, 2016 Paul Boddie <paul@boddie.org.uk>
4.8 +# Copyright (C) 2014, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
4.9 #
4.10 # This program is free software; you can redistribute it and/or modify it under
4.11 # the terms of the GNU General Public License as published by the Free Software
4.12 @@ -122,7 +122,8 @@
4.13 # Tools
4.14
4.15 TOOLS="copy_store.py fix.sh init.sh init_user.sh make_freebusy.py set_delegates.py "\
4.16 -"set_quota_groups.py set_quota_limits.py update_quotas.py update_scheduling_modules.py"
4.17 +"set_quota_groups.py set_quota_limits.py update_quotas.py update_scheduling_modules.py "\
4.18 +"update_storage_modules.py"
4.19
4.20 if [ ! -e "$INSTALL_DIR/tools" ]; then
4.21 mkdir -p "$INSTALL_DIR/tools"
4.22 @@ -170,3 +171,7 @@
4.23 # Run the scheduling module update tool to regenerate the manifest module.
4.24
4.25 PYTHONPATH="$INSTALL_DIR" "$INSTALL_DIR/tools/update_scheduling_modules.py"
4.26 +
4.27 +# Run the storage module update tool to regenerate the manifest module.
4.28 +
4.29 +PYTHONPATH="$INSTALL_DIR" "$INSTALL_DIR/tools/update_storage_modules.py"
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/tools/update_storage_modules.py Thu Jan 26 17:16:21 2017 +0100
5.3 @@ -0,0 +1,86 @@
5.4 +#!/usr/bin/env python
5.5 +
5.6 +"""
5.7 +Update the storage modules import manifest.
5.8 +
5.9 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
5.10 +
5.11 +This program is free software; you can redistribute it and/or modify it under
5.12 +the terms of the GNU General Public License as published by the Free Software
5.13 +Foundation; either version 3 of the License, or (at your option) any later
5.14 +version.
5.15 +
5.16 +This program is distributed in the hope that it will be useful, but WITHOUT
5.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
5.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
5.19 +details.
5.20 +
5.21 +You should have received a copy of the GNU General Public License along with
5.22 +this program. If not, see <http://www.gnu.org/licenses/>.
5.23 +"""
5.24 +
5.25 +from glob import glob
5.26 +from os import listdir
5.27 +from os.path import commonprefix, isdir, join, split, splitext
5.28 +import imiptools.stores
5.29 +
5.30 +reserved = ["__init__.py", "common.py", "manifest.py"]
5.31 +
5.32 +def get_extensions(dirname):
5.33 + filenames = []
5.34 + for filename in glob(join(dirname, "*.py")):
5.35 + leafname = split(filename)[-1]
5.36 + if leafname not in reserved:
5.37 + filenames.append(filename)
5.38 + return filenames
5.39 +
5.40 +# The main program generating a new version of the manifest module.
5.41 +
5.42 +if __name__ == "__main__":
5.43 + dirname = join(split(imiptools.stores.__file__)[0], "")
5.44 + manifest = join(dirname, "manifest.py")
5.45 +
5.46 + # Get all Python files in the stores directory, filtering out the
5.47 + # reserved files that do not provide storage functions.
5.48 +
5.49 + filenames = get_extensions(dirname)
5.50 +
5.51 + # Get all extensions from directories in the stores directory.
5.52 +
5.53 + for filename in listdir(dirname):
5.54 + filename = join(dirname, filename)
5.55 + if isdir(filename):
5.56 + filenames += get_extensions(filename)
5.57 +
5.58 + # Open the manifest module and write code to import and combine the
5.59 + # functions from each module.
5.60 +
5.61 + f = open(manifest, "w")
5.62 + try:
5.63 + print >>f, """\
5.64 +stores = {}
5.65 +"""
5.66 +
5.67 + for filename in filenames:
5.68 + relative = filename[len(commonprefix([filename, dirname])):]
5.69 +
5.70 + # NOTE: Converting POSIX paths to module paths.
5.71 +
5.72 + module = splitext(relative)[0].replace("/", ".")
5.73 + module_parts = module.rsplit(".", 1)
5.74 +
5.75 + # Get subpackage location and module.
5.76 +
5.77 + module_parents = len(module_parts) > 1 and module_parts[0]
5.78 + module_name = module_parts[-1]
5.79 +
5.80 + print >>f, """\
5.81 +from imiptools.stores%s import %s
5.82 +stores[%r] = %s
5.83 +""" % (module_parents and ".%s" % module_parents or "",
5.84 + module_name, module_name, module_name)
5.85 +
5.86 + finally:
5.87 + f.close()
5.88 +
5.89 +# vim: tabstop=4 expandtab shiftwidth=4