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@1208 | 6 | Copyright (C) 2016, 2017 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@1208 | 24 | import imp |
paul@1028 | 25 | |
paul@1199 | 26 | reserved = ["__init__.py", "common.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@1208 | 31 | _f, dirname, _d = imp.find_module("imiptools/handlers") |
paul@1208 | 32 | dirname = join(dirname, "scheduling") |
paul@1028 | 33 | |
paul@1028 | 34 | # Get all Python files in the scheduling directory, filtering out the |
paul@1028 | 35 | # reserved files that do not provide scheduling functions. |
paul@1028 | 36 | |
paul@1028 | 37 | filenames = [] |
paul@1208 | 38 | found = glob(join(dirname, "*.py")) |
paul@1208 | 39 | found.sort() |
paul@1208 | 40 | |
paul@1208 | 41 | for filename in found: |
paul@1028 | 42 | filename = split(filename)[-1] |
paul@1028 | 43 | if filename not in reserved: |
paul@1028 | 44 | filenames.append(filename) |
paul@1028 | 45 | |
paul@1028 | 46 | # Open the manifest module and write code to import and combine the |
paul@1028 | 47 | # functions from each module. |
paul@1028 | 48 | |
paul@1028 | 49 | f = open(join(dirname, "manifest.py"), "w") |
paul@1028 | 50 | try: |
paul@1039 | 51 | print >>f, """\ |
paul@1039 | 52 | confirmation_functions = {} |
paul@1040 | 53 | locking_functions = {} |
paul@1039 | 54 | retraction_functions = {} |
paul@1039 | 55 | scheduling_functions = {} |
paul@1040 | 56 | unlocking_functions = {} |
paul@1039 | 57 | """ |
paul@1039 | 58 | |
paul@1028 | 59 | for filename in filenames: |
paul@1028 | 60 | module = splitext(filename)[0] |
paul@1039 | 61 | |
paul@1039 | 62 | print >>f, """\ |
paul@1039 | 63 | from imiptools.handlers.scheduling.%s import ( |
paul@1039 | 64 | confirmation_functions as c, |
paul@1040 | 65 | locking_functions as l, |
paul@1039 | 66 | retraction_functions as r, |
paul@1040 | 67 | scheduling_functions as s, |
paul@1040 | 68 | unlocking_functions as u) |
paul@1039 | 69 | |
paul@1039 | 70 | confirmation_functions.update(c) |
paul@1040 | 71 | locking_functions.update(l) |
paul@1039 | 72 | retraction_functions.update(r) |
paul@1039 | 73 | scheduling_functions.update(s) |
paul@1040 | 74 | unlocking_functions.update(u) |
paul@1039 | 75 | """ % module |
paul@1039 | 76 | |
paul@1028 | 77 | finally: |
paul@1028 | 78 | f.close() |
paul@1028 | 79 | |
paul@1028 | 80 | # vim: tabstop=4 expandtab shiftwidth=4 |