__init__.py

Go to the documentation of this file.
00001 import os
00002 
00003 class Manager(object):
00004     clients = {}
00005 
00006     @classmethod
00007     def register(cls, *args):
00008         for client in args:
00009             if isinstance(client, str):
00010                 if client in cls.clients:
00011                     continue
00012                 module = __import__(client, globals(), locals(), [''], 1)
00013                 module.register(cls)
00014             else:
00015                 cls.clients[client.name] = client
00016 
00017     @classmethod
00018     def register_all(cls):
00019         dir = os.path.dirname(__file__)
00020         list = os.listdir(dir)
00021         modules = [f for f in list if os.path.isfile(os.path.join(dir, f))]
00022         for name in modules:
00023             name = name[:name.rfind('.')]
00024             try:
00025                 module = __import__(name, globals(), locals(), [''], 1)
00026                 module.register(cls)
00027             except:
00028                 pass
00029 
00030     @classmethod
00031     def get(cls, name=None, path=None):
00032         if name:
00033             ext = name.lower()
00034             if cls.clients.has_key(ext):
00035                 return cls.clients[ext]
00036             else:
00037                 try:
00038                     module = __import__(name, globals(), locals(), [''], 1)
00039                 except ImportError:
00040                     raise Exception('no matching ioclient')
00041                 module.register(cls)
00042                 return cls.clients[ext]
00043         elif path:
00044             for client in cls.clients.values():
00045                 if client.matches_path(path):
00046                     return client
00047             raise Exception('no matching ioclient')

Generated on Tue May 12 17:37:27 2009 for silme by  doxygen 1.5.8