1 #!/usr/bin/env python 2 3 """ 4 Update the scheduling modules import manifest. 5 6 Copyright (C) 2016 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 imiptools.handlers 25 26 reserved = ["__init__.py", "manifest.py"] 27 28 # The main program generating a new version of the manifest module. 29 30 if __name__ == "__main__": 31 dirname = join(split(imiptools.handlers.__file__)[0], "scheduling") 32 33 # Get all Python files in the scheduling directory, filtering out the 34 # reserved files that do not provide scheduling functions. 35 36 filenames = [] 37 for filename in glob(join(dirname, "*.py")): 38 filename = split(filename)[-1] 39 if filename not in reserved: 40 filenames.append(filename) 41 42 # Open the manifest module and write code to import and combine the 43 # functions from each module. 44 45 f = open(join(dirname, "manifest.py"), "w") 46 try: 47 print >>f, """\ 48 confirmation_functions = {} 49 locking_functions = {} 50 retraction_functions = {} 51 scheduling_functions = {} 52 unlocking_functions = {} 53 """ 54 55 for filename in filenames: 56 module = splitext(filename)[0] 57 58 print >>f, """\ 59 from imiptools.handlers.scheduling.%s import ( 60 confirmation_functions as c, 61 locking_functions as l, 62 retraction_functions as r, 63 scheduling_functions as s, 64 unlocking_functions as u) 65 66 confirmation_functions.update(c) 67 locking_functions.update(l) 68 retraction_functions.update(r) 69 scheduling_functions.update(s) 70 unlocking_functions.update(u) 71 """ % module 72 73 finally: 74 f.close() 75 76 # vim: tabstop=4 expandtab shiftwidth=4