PageRenderTime 29ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/python/helper/__init__.py

http://scim-python.googlecode.com/
Python | 70 lines | 39 code | 6 blank | 25 comment | 10 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. #
  26. import os.path as path
  27. import traceback
  28. import sys
  29. from glob import glob
  30. helpers = None
  31. def _init_helpers ():
  32. global helpers
  33. if helpers == None:
  34. helpers = []
  35. wildcast = path.join (path.dirname (__file__), "*")
  36. for name in [name for name in glob (wildcast) if path.isdir (name)]:
  37. name = path.basename (name)
  38. try:
  39. mod = __import__ (name, globals (), locals (), [])
  40. helpers.append ((mod, mod.get_info ()))
  41. except:
  42. traceback.print_exc ()
  43. def number_of_helpers ():
  44. return len (helpers)
  45. def get_helper_info (index):
  46. info = None
  47. try:
  48. info = helpers[index][1]
  49. except:
  50. traceback.print_exc ()
  51. return info
  52. def run_helper (uuid, config, display):
  53. try:
  54. for helper in helpers:
  55. if helper[1][0] == uuid:
  56. try:
  57. helper[0].run_helper (uuid, config, display)
  58. except:
  59. traceback.print_exc ()
  60. return
  61. print >> sys.stderr, "Can not find a helper with uuid=%s" % uuid
  62. except:
  63. traceback.print_exc ()
  64. _init_helpers ()