1.1 --- a/tools/update_storage_modules.py Tue Jan 31 16:18:55 2017 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,94 +0,0 @@
1.4 -#!/usr/bin/env python
1.5 -
1.6 -"""
1.7 -Update the storage modules import manifest.
1.8 -
1.9 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
1.10 -
1.11 -This program is free software; you can redistribute it and/or modify it under
1.12 -the terms of the GNU General Public License as published by the Free Software
1.13 -Foundation; either version 3 of the License, or (at your option) any later
1.14 -version.
1.15 -
1.16 -This program is distributed in the hope that it will be useful, but WITHOUT
1.17 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 -details.
1.20 -
1.21 -You should have received a copy of the GNU General Public License along with
1.22 -this program. If not, see <http://www.gnu.org/licenses/>.
1.23 -"""
1.24 -
1.25 -from glob import glob
1.26 -from os import listdir
1.27 -from os.path import commonprefix, isdir, join, split, splitext
1.28 -import imp
1.29 -
1.30 -reserved = ["__init__.py", "common.py", "manifest.py"]
1.31 -
1.32 -def get_extensions(dirname):
1.33 - filenames = []
1.34 - found = glob(join(dirname, "*.py"))
1.35 - found.sort()
1.36 -
1.37 - for filename in found:
1.38 - leafname = split(filename)[-1]
1.39 - if leafname not in reserved:
1.40 - filenames.append(filename)
1.41 -
1.42 - return filenames
1.43 -
1.44 -# The main program generating a new version of the manifest module.
1.45 -
1.46 -if __name__ == "__main__":
1.47 - _f, dirname, _d = imp.find_module("imiptools/stores")
1.48 - dirname = join(dirname, "")
1.49 - manifest = join(dirname, "manifest.py")
1.50 -
1.51 - # Get all Python files in the stores directory, filtering out the
1.52 - # reserved files that do not provide storage functions.
1.53 -
1.54 - filenames = get_extensions(dirname)
1.55 -
1.56 - # Get all extensions from directories in the stores directory.
1.57 -
1.58 - found = listdir(dirname)
1.59 - found.sort()
1.60 -
1.61 - for filename in found:
1.62 - filename = join(dirname, filename)
1.63 - if isdir(filename):
1.64 - filenames += get_extensions(filename)
1.65 -
1.66 - # Open the manifest module and write code to import and combine the
1.67 - # functions from each module.
1.68 -
1.69 - f = open(manifest, "w")
1.70 - try:
1.71 - print >>f, """\
1.72 -stores = {}
1.73 -"""
1.74 -
1.75 - for filename in filenames:
1.76 - relative = filename[len(commonprefix([filename, dirname])):]
1.77 -
1.78 - # NOTE: Converting POSIX paths to module paths.
1.79 -
1.80 - module = splitext(relative)[0].replace("/", ".")
1.81 - module_parts = module.rsplit(".", 1)
1.82 -
1.83 - # Get subpackage location and module.
1.84 -
1.85 - module_parents = len(module_parts) > 1 and module_parts[0]
1.86 - module_name = module_parts[-1]
1.87 -
1.88 - print >>f, """\
1.89 -from imiptools.stores%s import %s
1.90 -stores[%r] = %s
1.91 -""" % (module_parents and ".%s" % module_parents or "",
1.92 - module_name, module_name, module_name)
1.93 -
1.94 - finally:
1.95 - f.close()
1.96 -
1.97 -# vim: tabstop=4 expandtab shiftwidth=4