OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 import inspect | 4 import inspect |
5 import logging | 5 import logging |
6 import os | 6 import os |
7 import traceback | 7 import traceback |
8 | 8 |
9 def Discover(start_dir, suffix, clazz, import_error_should_raise=False): | 9 def Discover(start_dir, suffix, clazz, import_error_should_raise=False): |
10 """Discover all classes in |start_dir| which subclass |clazz|. | 10 """Discover all classes in |start_dir| which subclass |clazz|. |
(...skipping 24 matching lines...) Expand all Loading... |
35 raise | 35 raise |
36 logging.error('While importing [%s]\n' % fqn) | 36 logging.error('While importing [%s]\n' % fqn) |
37 traceback.print_exc() | 37 traceback.print_exc() |
38 continue | 38 continue |
39 for name, obj in inspect.getmembers(module): | 39 for name, obj in inspect.getmembers(module): |
40 if inspect.isclass(obj): | 40 if inspect.isclass(obj): |
41 if clazz in inspect.getmro(obj): | 41 if clazz in inspect.getmro(obj): |
42 name = module.__name__.split('.')[-1] | 42 name = module.__name__.split('.')[-1] |
43 classes[name] = obj | 43 classes[name] = obj |
44 return classes | 44 return classes |
OLD | NEW |