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 retraction_functions = {} 50 scheduling_functions = {} 51 """ 52 53 for filename in filenames: 54 module = splitext(filename)[0] 55 56 print >>f, """\ 57 from imiptools.handlers.scheduling.%s import ( 58 confirmation_functions as c, 59 retraction_functions as r, 60 scheduling_functions as s) 61 62 confirmation_functions.update(c) 63 retraction_functions.update(r) 64 scheduling_functions.update(s) 65 """ % module 66 67 finally: 68 f.close() 69 70 # vim: tabstop=4 expandtab shiftwidth=4