etisserant@203: #!/usr/bin/env python etisserant@203: # -*- coding: utf-8 -*- etisserant@203: # etisserant@203: #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD etisserant@203: # etisserant@203: #See COPYING file for copyrights details. etisserant@203: # etisserant@203: #This library is free software; you can redistribute it and/or etisserant@203: #modify it under the terms of the GNU General Public etisserant@203: #License as published by the Free Software Foundation; either etisserant@203: #version 2.1 of the License, or (at your option) any later version. etisserant@203: # etisserant@203: #This library is distributed in the hope that it will be useful, etisserant@203: #but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@203: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU etisserant@203: #General Public License for more details. etisserant@203: # etisserant@203: #You should have received a copy of the GNU General Public etisserant@203: #License along with this library; if not, write to the Free Software etisserant@203: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@203: etisserant@203: # Package initialisation etisserant@203: etisserant@203: from os import listdir, path etisserant@203: etisserant@203: _base_path = path.split(__file__)[0] etisserant@203: etisserant@203: connector_types = [name for name in listdir(_base_path) if path.isdir(path.join(_base_path, name)) and name.upper() != "CVS" and not name.startswith("__")] etisserant@203: etisserant@203: def ConnectorFactory(uri, pluginsroot): etisserant@203: """ etisserant@203: Return a connector corresponding to the URI etisserant@203: or None if cannot connect to URI etisserant@203: """ etisserant@203: servicetype = uri.split("://")[0] etisserant@203: if servicetype in connector_types: etisserant@203: # import module according to uri type etisserant@203: connectormodule = getattr(__import__("connectors."+servicetype), servicetype) etisserant@203: factoryname = servicetype + "_connector_factory" etisserant@203: return getattr(connectormodule, factoryname)(uri, pluginsroot) etisserant@227: elif servicetype == "LOCAL": etisserant@290: #handle incompatibility with tray icon and svgui... etisserant@298: poisoned_plugin = False etisserant@298: for PlugIn in pluginsroot.IterChilds(): etisserant@298: poisoned_plugin |= PlugIn.PlugType == "svgui" etisserant@298: runtime_port = pluginsroot.AppFrame.StartLocalRuntime(taskbaricon = not poisoned_plugin) etisserant@227: import PYRO etisserant@227: return PYRO.PYRO_connector_factory( etisserant@290: "PYRO://127.0.0.1:"+str(runtime_port), etisserant@227: pluginsroot) etisserant@203: else : etisserant@203: return None etisserant@203: