# HG changeset patch # User Paul Boddie # Date 1486329384 -3600 # Node ID d2c6bd93269aeee0bd3b94ab4264ecce82584637 # Parent 2b62bfd72d3f09234f24ae5c0eb285a9adb37880 Replaced the manually-built manifests for scheduling and storage extensions with automatic detection of such modules, removing the tools previously used to define the available modules, and updating the documentation and installation script. This should avoid mutable files that might make packaging difficult and simplify package maintenance. diff -r 2b62bfd72d3f -r d2c6bd93269a docs/wiki/Administration --- a/docs/wiki/Administration Tue Jan 31 16:18:55 2017 +0100 +++ b/docs/wiki/Administration Sun Feb 05 22:16:24 2017 +0100 @@ -121,34 +121,12 @@ in this package by adding files to the `scheduling` directory within the software installation. -After adding modules, a tool must be run to register the new modules: - -{{{ -tools/update_scheduling_modules.py -}}} - -It is envisaged that the installation of additional scheduling modules and the -use of this tool will be performed by the packaging system provided by an -operating system distribution. The `tools/install.sh` script runs the above -tool as part of the installation process. - == Adding Storage Modules == Storage modules reside in the `imiptools.stores` package. Extra modules can be -installed in this package by adding files or directories to the `stores` +installed in this package by adding files or directories to the `stores` directory within the software installation. -After adding modules, a tool must be run to register the new modules: - -{{{ -tools/update_storage_modules.py -}}} - -It is envisaged that the installation of additional storage modules and the -use of this tool will be performed by the packaging system provided by an -operating system distribution. The `tools/install.sh` script runs the above -tool as part of the installation process. - == Copying Stores and Changing Store Types == A rudimentary tool is provided that can copy data between stores, even those of diff -r 2b62bfd72d3f -r d2c6bd93269a imiptools/handlers/scheduling/manifest.py --- a/imiptools/handlers/scheduling/manifest.py Tue Jan 31 16:18:55 2017 +0100 +++ b/imiptools/handlers/scheduling/manifest.py Sun Feb 05 22:16:24 2017 +0100 @@ -1,45 +1,52 @@ +#!/usr/bin/env python + +""" +Scheduling functions manifest. + +Copyright (C) 2017 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from imiptools.imports import get_extensions +from os.path import split + +reserved = ["__init__", "common", "manifest"] + +# Obtain details of this module's package. + +dirname = split(__file__)[0] +package = __name__.rsplit(".", 1)[0] + +# Define an attribute mapping names to modules. + +modules = {} +get_extensions(dirname, package, modules, reserved) + +# Define attributes mapping names to functions. + confirmation_functions = {} locking_functions = {} retraction_functions = {} scheduling_functions = {} unlocking_functions = {} -from imiptools.handlers.scheduling.access import ( - confirmation_functions as c, - locking_functions as l, - retraction_functions as r, - scheduling_functions as s, - unlocking_functions as u) - -confirmation_functions.update(c) -locking_functions.update(l) -retraction_functions.update(r) -scheduling_functions.update(s) -unlocking_functions.update(u) - -from imiptools.handlers.scheduling.freebusy import ( - confirmation_functions as c, - locking_functions as l, - retraction_functions as r, - scheduling_functions as s, - unlocking_functions as u) +for module in modules.values(): + confirmation_functions.update(module.confirmation_functions) + locking_functions.update(module.locking_functions) + retraction_functions.update(module.retraction_functions) + scheduling_functions.update(module.scheduling_functions) + unlocking_functions.update(module.unlocking_functions) -confirmation_functions.update(c) -locking_functions.update(l) -retraction_functions.update(r) -scheduling_functions.update(s) -unlocking_functions.update(u) - -from imiptools.handlers.scheduling.quota import ( - confirmation_functions as c, - locking_functions as l, - retraction_functions as r, - scheduling_functions as s, - unlocking_functions as u) - -confirmation_functions.update(c) -locking_functions.update(l) -retraction_functions.update(r) -scheduling_functions.update(s) -unlocking_functions.update(u) - +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 2b62bfd72d3f -r d2c6bd93269a imiptools/imports.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/imiptools/imports.py Sun Feb 05 22:16:24 2017 +0100 @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +""" +Import utilities. + +Copyright (C) 2017 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from os.path import isdir, join, splitext +from os import listdir +from importlib import import_module + +def get_extensions(dirname, modname, stores, reserved): + + "Import extensions inside 'dirname'." + + for filename in listdir(dirname): + pathname = join(dirname, filename) + + # Descend into directories. + + if isdir(pathname): + get_extensions(pathname, "%s.%s" % (modname, filename), + stores, reserved) + continue + + # Identify modules and import them. + + leafname, ext = splitext(filename) + + if ext == ".py" and leafname not in reserved: + stores[leafname] = import_module("%s.%s" % (modname, leafname)) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 2b62bfd72d3f -r d2c6bd93269a imiptools/stores/manifest.py --- a/imiptools/stores/manifest.py Tue Jan 31 16:18:55 2017 +0100 +++ b/imiptools/stores/manifest.py Sun Feb 05 22:16:24 2017 +0100 @@ -1,8 +1,37 @@ -stores = {} +#!/usr/bin/env python + +""" +Store manifest. + +Copyright (C) 2017 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. -from imiptools.stores import file -stores['file'] = file +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from imiptools.imports import get_extensions +from os.path import split + +reserved = ["__init__", "common", "manifest"] -from imiptools.stores.database import postgresql -stores['postgresql'] = postgresql +# Obtain details of this module's package. + +dirname = split(__file__)[0] +package = __name__.rsplit(".", 1)[0] +# Define an attribute mapping names to modules. + +stores = {} +get_extensions(dirname, package, stores, reserved) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 2b62bfd72d3f -r d2c6bd93269a tools/install.sh --- a/tools/install.sh Tue Jan 31 16:18:55 2017 +0100 +++ b/tools/install.sh Sun Feb 05 22:16:24 2017 +0100 @@ -44,6 +44,8 @@ cp $AGENTS "$INSTALL_DIR" cp $MODULES "$INSTALL_DIR" +# Package modules. + for DIR in "$INSTALL_DIR/imiptools" \ "$INSTALL_DIR/imiptools/stores" \ "$INSTALL_DIR/imiptools/stores/database" \ @@ -54,7 +56,8 @@ fi done -# Remove any symbolic link to the config module. +# Remove any symbolic link to the config module. This linking is no longer +# supported, anyway. if [ -h "$INSTALL_DIR/imiptools/config.py" ]; then rm "$INSTALL_DIR/imiptools/config.py" @@ -138,8 +141,9 @@ # Tools TOOLS="copy_store.py fix.sh init.sh init_user.sh make_freebusy.py set_delegates.py "\ -"set_quota_groups.py set_quota_limits.py update_quotas.py update_scheduling_modules.py "\ -"update_storage_modules.py" +"set_quota_groups.py set_quota_limits.py update_quotas.py" + +OLD_TOOLS="update_scheduling_modules.py update_storage_modules.py" if [ ! -e "$INSTALL_DIR/tools" ]; then mkdir -p "$INSTALL_DIR/tools" @@ -149,6 +153,12 @@ cp "tools/$TOOL" "$INSTALL_DIR/tools/" done +for TOOL in $OLD_TOOLS; do + if [ -e "$INSTALL_DIR/tools/$TOOL" ]; then + rm "$INSTALL_DIR/tools/$TOOL" + fi +done + # Web manager interface. if [ ! -e "$WEB_INSTALL_DIR" ]; then @@ -183,11 +193,3 @@ done fi fi - -# Run the scheduling module update tool to regenerate the manifest module. - -PYTHONPATH="$INSTALL_DIR" "$INSTALL_DIR/tools/update_scheduling_modules.py" - -# Run the storage module update tool to regenerate the manifest module. - -PYTHONPATH="$INSTALL_DIR" "$INSTALL_DIR/tools/update_storage_modules.py" diff -r 2b62bfd72d3f -r d2c6bd93269a tools/update_scheduling_modules.py --- a/tools/update_scheduling_modules.py Tue Jan 31 16:18:55 2017 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -#!/usr/bin/env python - -""" -Update the scheduling modules import manifest. - -Copyright (C) 2016, 2017 Paul Boddie - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; either version 3 of the License, or (at your option) any later -version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see . -""" - -from glob import glob -from os.path import join, split, splitext -import imp - -reserved = ["__init__.py", "common.py", "manifest.py"] - -# The main program generating a new version of the manifest module. - -if __name__ == "__main__": - _f, dirname, _d = imp.find_module("imiptools/handlers") - dirname = join(dirname, "scheduling") - - # Get all Python files in the scheduling directory, filtering out the - # reserved files that do not provide scheduling functions. - - filenames = [] - found = glob(join(dirname, "*.py")) - found.sort() - - for filename in found: - filename = split(filename)[-1] - if filename not in reserved: - filenames.append(filename) - - # Open the manifest module and write code to import and combine the - # functions from each module. - - f = open(join(dirname, "manifest.py"), "w") - try: - print >>f, """\ -confirmation_functions = {} -locking_functions = {} -retraction_functions = {} -scheduling_functions = {} -unlocking_functions = {} -""" - - for filename in filenames: - module = splitext(filename)[0] - - print >>f, """\ -from imiptools.handlers.scheduling.%s import ( - confirmation_functions as c, - locking_functions as l, - retraction_functions as r, - scheduling_functions as s, - unlocking_functions as u) - -confirmation_functions.update(c) -locking_functions.update(l) -retraction_functions.update(r) -scheduling_functions.update(s) -unlocking_functions.update(u) -""" % module - - finally: - f.close() - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r 2b62bfd72d3f -r d2c6bd93269a tools/update_storage_modules.py --- a/tools/update_storage_modules.py Tue Jan 31 16:18:55 2017 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -#!/usr/bin/env python - -""" -Update the storage modules import manifest. - -Copyright (C) 2016, 2017 Paul Boddie - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; either version 3 of the License, or (at your option) any later -version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see . -""" - -from glob import glob -from os import listdir -from os.path import commonprefix, isdir, join, split, splitext -import imp - -reserved = ["__init__.py", "common.py", "manifest.py"] - -def get_extensions(dirname): - filenames = [] - found = glob(join(dirname, "*.py")) - found.sort() - - for filename in found: - leafname = split(filename)[-1] - if leafname not in reserved: - filenames.append(filename) - - return filenames - -# The main program generating a new version of the manifest module. - -if __name__ == "__main__": - _f, dirname, _d = imp.find_module("imiptools/stores") - dirname = join(dirname, "") - manifest = join(dirname, "manifest.py") - - # Get all Python files in the stores directory, filtering out the - # reserved files that do not provide storage functions. - - filenames = get_extensions(dirname) - - # Get all extensions from directories in the stores directory. - - found = listdir(dirname) - found.sort() - - for filename in found: - filename = join(dirname, filename) - if isdir(filename): - filenames += get_extensions(filename) - - # Open the manifest module and write code to import and combine the - # functions from each module. - - f = open(manifest, "w") - try: - print >>f, """\ -stores = {} -""" - - for filename in filenames: - relative = filename[len(commonprefix([filename, dirname])):] - - # NOTE: Converting POSIX paths to module paths. - - module = splitext(relative)[0].replace("/", ".") - module_parts = module.rsplit(".", 1) - - # Get subpackage location and module. - - module_parents = len(module_parts) > 1 and module_parts[0] - module_name = module_parts[-1] - - print >>f, """\ -from imiptools.stores%s import %s -stores[%r] = %s -""" % (module_parents and ".%s" % module_parents or "", - module_name, module_name, module_name) - - finally: - f.close() - -# vim: tabstop=4 expandtab shiftwidth=4