Ready for mentors
[cgmail.git] / cGmail / lib / checkersutils.py
bloba8b60f3ffddeb81b8fe6cdd0f9bcd6242bbc2a1c
2 # Copyright (C) 2007 Marco Ferragina <marco.ferragina@gmail.com>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 import os
19 import sys
21 def load_checkers():
22 """
23 Load all checkers modules and return a list
24 """
25 path = os.path.abspath(os.path.dirname(__file__))
26 checkers_path = os.path.join("..", "checkers")
27 path = os.path.join(path, checkers_path)
28 sys.path.append(path)
29 modules = [x.split( '.' )[ 0 ] for x in os.listdir( path ) \
30 if x.endswith( '.py' ) and not x.startswith( '_' ) \
31 and x != 'base.py']
32 __import__("checkers", globals(), locals(), [])
33 checkers = []
34 for m in modules:
35 # print "Loading ", m
36 try:
37 mod = __import__( "checkers" + '.' + m, globals(), locals(), [] )
38 checkers.append(getattr(mod, m))
39 except ImportError, e:
40 print 'Exception importing ' + m + '\n' + str(e)
41 return checkers
43 def get_checker_by_name(name):
44 """
45 Return the checker named name
46 """
47 checkers = load_checkers()
48 for c in checkers:
49 tmp = c.Info()
50 if tmp.get_name() == name:
51 return c
52 return None
54 def get_checker_info_by_name(name):
55 """
56 Return the Info object for the checker named name
57 """
58 checker = get_checker_by_name(name)
59 if checker is not None:
60 return checker.Info()
61 return None