|
|
|
@ -17,11 +17,10 @@
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
|
|
|
|
import os.path |
|
|
|
|
import glob |
|
|
|
|
import logging |
|
|
|
|
|
|
|
|
|
from mitterlib.network.networkbase import NetworkData |
|
|
|
|
from mitterlib import module_search |
|
|
|
|
|
|
|
|
|
_log = logging.getLogger('mitterlib.network.Networks') |
|
|
|
|
|
|
|
|
@ -34,23 +33,12 @@ SKIPPABLES = ('__init__.py', 'networkbase.py')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _import_name(module): |
|
|
|
|
"""Based on the name of the module, return the proper "import" |
|
|
|
|
statement.""" |
|
|
|
|
(name, _) = os.path.splitext(module) |
|
|
|
|
return 'mitterlib.network.%s' % (name) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _networks(): |
|
|
|
|
network_dir = os.path.dirname(__file__) |
|
|
|
|
|
|
|
|
|
networks = glob.glob(os.path.join(network_dir, '*.py')) |
|
|
|
|
for network in networks: |
|
|
|
|
network_name = os.path.basename(network) |
|
|
|
|
if network_name in SKIPPABLES: |
|
|
|
|
# not a real network |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
module_name = _import_name(network_name) |
|
|
|
|
yield module_name |
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------- |
|
|
|
|
# Exceptions |
|
|
|
|
#-------------------------------------------------------------------- |
|
|
|
@ -102,13 +90,10 @@ class Networks(object):
|
|
|
|
|
if self._networks: |
|
|
|
|
return self._networks |
|
|
|
|
|
|
|
|
|
for module_name in _networks(): |
|
|
|
|
try: |
|
|
|
|
module = __import__(module_name, fromlist=[module_name]) |
|
|
|
|
connection = module.Connection(self._options) |
|
|
|
|
self._networks[connection.SHORTCUT] = connection |
|
|
|
|
except ImportError, ex: |
|
|
|
|
raise NetworksErrorLoadingNetwork(module_name, ex) |
|
|
|
|
for module_name in module_search(__file__, SKIPPABLES): |
|
|
|
|
module = __import__(module_name, fromlist=[module_name]) |
|
|
|
|
connection = module.Connection(self._options) |
|
|
|
|
self._networks[connection.SHORTCUT] = connection |
|
|
|
|
|
|
|
|
|
return self._networks |
|
|
|
|
|
|
|
|
|