PageRenderTime 22ms CodeModel.GetById 18ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/python/helper/__init__.py

http://scim-python.googlecode.com/
Python | 70 lines | 39 code | 6 blank | 25 comment | 9 complexity | bd3c52204d9c748dc9917c5934bdcb85 MD5 | raw file
 1# -*- coding: utf-8 -*-
 2# vim:set noet ts=4:
 3#
 4# scim-python
 5#
 6# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
 7#
 8#
 9# This library is free software; you can redistribute it and/or
10# modify it under the terms of the GNU Lesser General Public
11# License as published by the Free Software Foundation; either
12# version 2 of the License, or (at your option) any later version.
13#
14# This library is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU Lesser General Public License for more details.
18#
19# You should have received a copy of the GNU Lesser General Public
20# License along with this program; if not, write to the
21# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22# Boston, MA  02111-1307  USA
23#
24# $Id: $
25#
26import os.path as path
27import traceback
28import sys
29from glob import glob
30
31helpers = None
32
33def _init_helpers ():
34	global helpers
35	if helpers == None:
36		helpers = []
37		wildcast = path.join (path.dirname (__file__), "*")
38		for name in [name for name in glob (wildcast) if path.isdir (name)]:
39			name = path.basename (name)
40			try:
41				mod = __import__ (name, globals (), locals (), [])
42				helpers.append ((mod, mod.get_info ()))
43			except:
44				traceback.print_exc ()
45
46def number_of_helpers ():
47	return len (helpers)
48
49def get_helper_info (index):
50	info = None
51	try:
52		info =  helpers[index][1]
53	except:
54		traceback.print_exc ()
55	return info
56
57def run_helper (uuid, config, display):
58	try:
59		for helper in helpers:
60			if helper[1][0] == uuid:
61				try:
62					helper[0].run_helper (uuid, config, display)
63				except:
64					traceback.print_exc ()
65				return
66		print >> sys.stderr, "Can not find a helper with uuid=%s" % uuid
67	except:
68		traceback.print_exc ()
69
70_init_helpers ()