1
# Copyright (C) 2008 Canonical Ltd
 
 
3
# This program is free software; you can redistribute it and/or modify
 
 
4
# it under the terms of the GNU General Public License as published by
 
 
5
# the Free Software Foundation; either version 2 of the License, or
 
 
6
# (at your option) any later version.
 
 
8
# This program is distributed in the hope that it will be useful,
 
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 
11
# GNU General Public License for more details.
 
 
13
# You should have received a copy of the GNU General Public License
 
 
14
# along with this program; if not, write to the Free Software
 
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
17
"""Custom module finder for entire package"""
 
 
24
class CustomModuleFinder(modulefinder.ModuleFinder):
 
 
25
    """Custom module finder for processing python packages,
 
 
26
    e.g. bzr plugins packages.
 
 
28
    :param  path:   list of directories to search for modules;
 
 
29
                    if not specified, python standard library only is used.
 
 
32
    def __init__(self, path=None, debug=0, excludes=[], replace_paths=[]):
 
 
34
            path = [os.path.dirname(os.__file__)]    # only python std lib
 
 
35
        modulefinder.ModuleFinder.__init__(self, path, debug, excludes,
 
 
38
    def run_package(self, package_path):
 
 
39
        """Recursively process each module in package with run_script method.
 
 
41
        :param  package_path:   path to package directory.
 
 
43
        stack = [package_path]
 
 
46
            py = os.listdir(curdir)
 
 
48
                full = os.path.join(curdir, i)
 
 
49
                if os.path.isdir(full):
 
 
50
                    init = os.path.join(full, '__init__.py')
 
 
51
                    if os.path.isfile(init):
 
 
54
                if not i.endswith('.py'):
 
 
56
                if i == 'setup.py':     # skip
 
 
61
        """Return 2-tuple: (list of packages, list of modules)"""
 
 
62
        keys = self.modules.keys()
 
 
68
            if not m.__file__:      # skip builtins
 
 
72
            elif key != '__main__':
 
 
77
if __name__ == '__main__':
 
 
80
    mf = CustomModuleFinder()
 
 
81
    mf.run_package(package)
 
 
83
    packs, mods = mf.get_result()