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