Example #1
0
	def __init__(self, path=None, prefix=None):
		'''
		'''
		if path == None:
			# by default get path relative to the module this was
			# called from.... (????)
			#   (e.g. import all that is on callres level...)
			i = 0
			while True:
				f_locals = sys._getframe(frame_depth+i).f_locals
				if '__file__' in f_locals:
					break
				i += 1
			path = os.path.dirname(f_locals['__file__'])
			if prefix == None:
				# the prefix is same as caller...
				 n = f_locals['__name__']
				 if n != '__main__':
					 prefix = n
		elif type(path) == types.ModuleType:
			mod = path
			# get path...
			path = os.path.dirname(mod.__file__)
			if prefix == None and mod.__name__ != '__main__':
				# get prefix...
				prefix = mod.__name__
		elif exttypes.isstring(path):
			pass
##			self.path = path
			if prefix == None:
				# normalize the path...
				f = os.path.normpath(path)
				# guess the prefix 
				# see if it is in sys.modules...
				for n, v in sys.modules.iteritems():
					if hasattr(v, '__file__') and v.__file__.startswith(f) and v.__name__ != None:
						prefix = v.__name__
						break
				# Q: is there anythong else we could do here???
				##!!!
		else:
			raise TypeError, 'the path may either be a string (or unicode), a package or None (got: %s).' % path

		self.path = path
		self.prefix = prefix
		self.plugins = {}
		##!!!
		self.sorted_plugins = None
Example #2
0
	def load(self, path=None, prefix=None, ignore=None, frame_depth=1):
		'''

		NOTE: path can either be a string path to the dir or a root module object...
		'''
		loaded = self.loaded
		errors = self.errors
		unimportable = self.unimportable
		disabled = self.disabled

		if path == None:
			# by default get path relative to the module this was
			# called from.... (????)
			#   (e.g. import all that is on callres level...)
			i = 0
			while True:
				f_locals = sys._getframe(frame_depth+i).f_locals
				if '__file__' in f_locals:
					break
				i += 1
##			f_locals = sys._getframe(frame_depth).f_locals
			path = os.path.dirname(f_locals['__file__'])
			if prefix == None:
				# the prefix is same as caller...
				 n = f_locals['__name__']
				 if n != '__main__':
					 prefix = n
		elif type(path) == types.ModuleType:
			mod = path
			# get path...
			path = os.path.dirname(mod.__file__)
			if prefix == None and mod.__name__ != '__main__':
				# get prefix...
				prefix = mod.__name__
		elif exttypes.isstring(path):
			self.path = path
			if prefix == None:
				# normalize the path...
				f = os.path.normpath(path)
				# guess the prefix 
				# see if it is in sys.modules...
				for n, v in sys.modules.iteritems():
					if hasattr(v, '__file__') and v.__file__.startswith(f) and v.__name__ != None:
						prefix = v.__name__
						break
				# Q: is there anythong else we could do here???
				##!!!
		else:
			raise TypeError, 'the path may either be a string (or unicode), a package or None (got: %s).' % path

##		# debug data...
##		self._path = path
##		self._prefix = prefix
##		self._ignore = ignore

		if hasattr(self, '__plugin_load_event__'):
			load_event = self.__plugin_load_event__
		else:
			load_event = None
		# the import loop....
		for name, module in importutils.importdependspackagesiter(path, \
																  self.__disable_file_name__, \
																  self.__depends_file_name__, \
																  errors, \
																  disabled, \
																  ignore_modules=(ignore == None and self.__ignored_modules__),\
																  name_prefix=prefix
																 ):
			if load_event != None:
				load_event.fire(name, module)
			loaded[name] = module