paul@1216 | 1 | #!/usr/bin/env python |
paul@1216 | 2 | |
paul@1216 | 3 | """ |
paul@1216 | 4 | Import utilities. |
paul@1216 | 5 | |
paul@1216 | 6 | Copyright (C) 2017 Paul Boddie <paul@boddie.org.uk> |
paul@1216 | 7 | |
paul@1216 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@1216 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@1216 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@1216 | 11 | version. |
paul@1216 | 12 | |
paul@1216 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@1216 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@1216 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@1216 | 16 | details. |
paul@1216 | 17 | |
paul@1216 | 18 | You should have received a copy of the GNU General Public License along with |
paul@1216 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@1216 | 20 | """ |
paul@1216 | 21 | |
paul@1216 | 22 | from os.path import isdir, join, splitext |
paul@1216 | 23 | from os import listdir |
paul@1216 | 24 | from importlib import import_module |
paul@1216 | 25 | |
paul@1216 | 26 | def get_extensions(dirname, modname, stores, reserved): |
paul@1216 | 27 | |
paul@1216 | 28 | "Import extensions inside 'dirname'." |
paul@1216 | 29 | |
paul@1216 | 30 | for filename in listdir(dirname): |
paul@1216 | 31 | pathname = join(dirname, filename) |
paul@1216 | 32 | |
paul@1216 | 33 | # Descend into directories. |
paul@1216 | 34 | |
paul@1216 | 35 | if isdir(pathname): |
paul@1216 | 36 | get_extensions(pathname, "%s.%s" % (modname, filename), |
paul@1216 | 37 | stores, reserved) |
paul@1216 | 38 | continue |
paul@1216 | 39 | |
paul@1216 | 40 | # Identify modules and import them. |
paul@1216 | 41 | |
paul@1216 | 42 | leafname, ext = splitext(filename) |
paul@1216 | 43 | |
paul@1216 | 44 | if ext == ".py" and leafname not in reserved: |
paul@1216 | 45 | stores[leafname] = import_module("%s.%s" % (modname, leafname)) |
paul@1216 | 46 | |
paul@1216 | 47 | # vim: tabstop=4 expandtab shiftwidth=4 |