1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tools/update_scheduling_modules.py Fri Jan 29 22:25:02 2016 +0100
1.3 @@ -0,0 +1,55 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Update the scheduling modules import manifest.
1.8 +
1.9 +Copyright (C) 2016 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.path import join, split, splitext
1.27 +import imiptools.handlers
1.28 +
1.29 +reserved = ["__init__.py", "manifest.py"]
1.30 +
1.31 +# The main program generating a new version of the manifest module.
1.32 +
1.33 +if __name__ == "__main__":
1.34 + dirname = join(split(imiptools.handlers.__file__)[0], "scheduling")
1.35 +
1.36 + # Get all Python files in the scheduling directory, filtering out the
1.37 + # reserved files that do not provide scheduling functions.
1.38 +
1.39 + filenames = []
1.40 + for filename in glob(join(dirname, "*.py")):
1.41 + filename = split(filename)[-1]
1.42 + if filename not in reserved:
1.43 + filenames.append(filename)
1.44 +
1.45 + # Open the manifest module and write code to import and combine the
1.46 + # functions from each module.
1.47 +
1.48 + f = open(join(dirname, "manifest.py"), "w")
1.49 + try:
1.50 + print >>f, "scheduling_functions = {}"
1.51 + for filename in filenames:
1.52 + module = splitext(filename)[0]
1.53 + print >>f, "from imiptools.handlers.scheduling.%s import scheduling_functions as l" % module
1.54 + print >>f, "scheduling_functions.update(l)"
1.55 + finally:
1.56 + f.close()
1.57 +
1.58 +# vim: tabstop=4 expandtab shiftwidth=4