00001 ############################################################################## 00002 # 00003 # Copyright (c) 2008 Albert Cervera i Areny <albert@nan-tic.com> 00004 # 00005 # WARNING: This program as such is intended to be used by professional 00006 # programmers who take the whole responsability of assessing all potential 00007 # consequences resulting from its eventual inadequacies and bugs 00008 # End users who are looking for a ready-to-use solution with commercial 00009 # garantees and support are strongly adviced to contract a Free Software 00010 # Service Company 00011 # 00012 # This program is Free Software; you can redistribute it and/or 00013 # modify it under the terms of the GNU General Public License 00014 # as published by the Free Software Foundation; either version 2 00015 # of the License, or (at your option) any later version. 00016 # 00017 # This program is distributed in the hope that it will be useful, 00018 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 # GNU General Public License for more details. 00021 # 00022 # You should have received a copy of the GNU General Public License 00023 # along with this program; if not, write to the Free Software 00024 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00025 # 00026 ############################################################################## 00027 00028 import os 00029 import sys 00030 00031 ## @brief This helper function searches all available modules in a given directory. 00032 # It's used to scan the Plugins, Fields, View and Search directories. 00033 def scan( module, directory ): 00034 pluginImports = __import__(module, globals(), locals()) 00035 # Check if it's being run using py2exe or py2app environment 00036 frozen = getattr(sys, 'frozen', None) 00037 if frozen == 'macosx_app' or hasattr(pluginImports, '__loader__'): 00038 # If it's run using py2exe or py2app environment, all files will be in a single 00039 # zip file and we can't use listdir() to find all available plugins. 00040 zipFiles = pluginImports.__loader__._files 00041 moduleDir = os.sep.join( module.split('.') ) 00042 files = [zipFiles[file][0] for file in zipFiles.keys() if moduleDir in file] 00043 files = [file for file in files if '__init__.py' in file] 00044 for file in files: 00045 d = os.path.dirname(file) 00046 if d.endswith( moduleDir ): 00047 continue 00048 newModule = os.path.basename(os.path.dirname(file)) 00049 __import__( '%s.%s' % (module, newModule), globals(), locals(), [newModule] ) 00050 else: 00051 for i in os.listdir(directory): 00052 path = os.path.join( directory, i, '__init__.py' ) 00053 if os.path.isfile( path ): 00054 __import__( '%s.%s' % (module, i), globals(), locals(), [i] ) 00055