paul@1028 | 1 | #!/usr/bin/env python |
paul@1028 | 2 | |
paul@1028 | 3 | """ |
paul@1028 | 4 | Update the scheduling modules import manifest. |
paul@1028 | 5 | |
paul@1028 | 6 | Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> |
paul@1028 | 7 | |
paul@1028 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@1028 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@1028 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@1028 | 11 | version. |
paul@1028 | 12 | |
paul@1028 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@1028 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@1028 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@1028 | 16 | details. |
paul@1028 | 17 | |
paul@1028 | 18 | You should have received a copy of the GNU General Public License along with |
paul@1028 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@1028 | 20 | """ |
paul@1028 | 21 | |
paul@1028 | 22 | from glob import glob |
paul@1028 | 23 | from os.path import join, split, splitext |
paul@1028 | 24 | import imiptools.handlers |
paul@1028 | 25 | |
paul@1028 | 26 | reserved = ["__init__.py", "manifest.py"] |
paul@1028 | 27 | |
paul@1028 | 28 | # The main program generating a new version of the manifest module. |
paul@1028 | 29 | |
paul@1028 | 30 | if __name__ == "__main__": |
paul@1028 | 31 | dirname = join(split(imiptools.handlers.__file__)[0], "scheduling") |
paul@1028 | 32 | |
paul@1028 | 33 | # Get all Python files in the scheduling directory, filtering out the |
paul@1028 | 34 | # reserved files that do not provide scheduling functions. |
paul@1028 | 35 | |
paul@1028 | 36 | filenames = [] |
paul@1028 | 37 | for filename in glob(join(dirname, "*.py")): |
paul@1028 | 38 | filename = split(filename)[-1] |
paul@1028 | 39 | if filename not in reserved: |
paul@1028 | 40 | filenames.append(filename) |
paul@1028 | 41 | |
paul@1028 | 42 | # Open the manifest module and write code to import and combine the |
paul@1028 | 43 | # functions from each module. |
paul@1028 | 44 | |
paul@1028 | 45 | f = open(join(dirname, "manifest.py"), "w") |
paul@1028 | 46 | try: |
paul@1039 | 47 | print >>f, """\ |
paul@1039 | 48 | confirmation_functions = {} |
paul@1040 | 49 | locking_functions = {} |
paul@1039 | 50 | retraction_functions = {} |
paul@1039 | 51 | scheduling_functions = {} |
paul@1040 | 52 | unlocking_functions = {} |
paul@1039 | 53 | """ |
paul@1039 | 54 | |
paul@1028 | 55 | for filename in filenames: |
paul@1028 | 56 | module = splitext(filename)[0] |
paul@1039 | 57 | |
paul@1039 | 58 | print >>f, """\ |
paul@1039 | 59 | from imiptools.handlers.scheduling.%s import ( |
paul@1039 | 60 | confirmation_functions as c, |
paul@1040 | 61 | locking_functions as l, |
paul@1039 | 62 | retraction_functions as r, |
paul@1040 | 63 | scheduling_functions as s, |
paul@1040 | 64 | unlocking_functions as u) |
paul@1039 | 65 | |
paul@1039 | 66 | confirmation_functions.update(c) |
paul@1040 | 67 | locking_functions.update(l) |
paul@1039 | 68 | retraction_functions.update(r) |
paul@1039 | 69 | scheduling_functions.update(s) |
paul@1040 | 70 | unlocking_functions.update(u) |
paul@1039 | 71 | """ % module |
paul@1039 | 72 | |
paul@1028 | 73 | finally: |
paul@1028 | 74 | f.close() |
paul@1028 | 75 | |
paul@1028 | 76 | # vim: tabstop=4 expandtab shiftwidth=4 |