Beispiel #1
0
	def get_optionlist(self, section, key, seperator=',', default=[]):
		try:
			return Config.parselist(self._config.get(section, key), seperator)
		except Exception, e:
			Log.error('Error getting value list for key %s in section %s' %
							(key, section))
			Log.exception(e)
Beispiel #2
0
	def get_bool(self, section, key, default=False):
		try:
			val = self._config.getboolean(section, key)
			return val
		except ValueError:
			Log.error('Config option %s in section [%s] must be on of "1,yes,true,on" or "0,no,false,off"'%(section,key))
		except Exception, e:
			Log.exception(e)
Beispiel #3
0
	def forall(self, func_name, *args, **kwargs):
		""" execute a given function(name) on all plugins that expose it"""
		for name, plugin in filter(lambda (name, plugin):
				func_name in dir(plugin), self.plugins.iteritems()):
			try:
				func = getattr(plugin, func_name)
				func(*args, **kwargs)
			except SystemExit:
				raise SystemExit(0)
			except Exception, e:
				Log.error("PLUGIN %s ERROR calling  %s" %
					(func_name, name))
				Log.exception(e)
Beispiel #4
0
	def __init__(self, filename='Main.conf'):
		super(Config,self).__init__()
		self._filename = filename
		self._config = ConfigParser()
		#make keys case sensitive
		self._config.optionxform = str
		self.has_option = self._config.has_option
		self.set = self._config.set
		try:
			open(filename, 'r').close()
			self._config.read(filename)
		except Exception, e:
			#try:
			Log.error("Configfile %s invalid" % self._filename)
			Log.exception(e)
Beispiel #5
0
	def unloadplugin(self, name):
		""" unload plugin, stop all its threads
		via ondestroy and remove from interal list"""
		if not name in self.plugins:
			Log.error("Plugin %s not loaded" % name)
			return
		try:
			if "ondestroy" in dir(self.plugins[name]):
				self.plugins[name].ondestroy()
			self.plugins.pop(name)
			Log.notice("%s Unloaded" % name)
		except Exception, e:
			Log.error("Cannot unload plugin %s" % name)
			Log.error("Use forceunload to remove it anyway")
			Log.exception(e)
Beispiel #6
0
 def get(self, section, key, default=None):
     # find out reason why int keys fail to load
     key = str(key)
     # if isinstance(key,int):#uncomment this to locate int keys
     # Log.error('WUT')
     # traceback.print_stack()
     # raise SystemExit(1)
     try:
         return os.path.expandvars(self._config.get(section, key))
     except NoOptionError:
         if default == None:
             Log.error("no value or default found for config item %s -- %s" % (section, key))
     except Exception, e:
         Log.error("Error getting config item %s -- %s" % (section, key))
         Log.exception(e)
Beispiel #7
0
	def addplugin(self, name, tasc):
		"""try to import module name and init it"""
		if name in self.plugins:
			Log.bad("Plugin %s is already loaded" % name)
			return
		try:
			code = __import__(name)
		except ImportError:
			Log.debug('trying to load plugin %s from plugins subdir' % name )
			try:
				pname = 'tasbot.plugins.%s' % name
				__import__(pname)
				code = sys.modules[pname]
			except ImportError, imp:
				Log.error("Cannot load plugin %s" % name)
				Log.exception(imp)
				raise SystemExit(1)
Beispiel #8
0
 def __init__(self, filename="Main.conf"):
     super(Config, self).__init__()
     self._filename = filename
     self._config = ConfigParser()
     # make keys case sensitive
     self._config.optionxform = str
     self.has_option = self._config.has_option
     self.set = self._config.set
     try:
         open(filename, "r").close()
         self._config.read(filename)
     except Exception, e:
         try:
             Log.error("Configfile %s invalid" % self.filename)
             Log.exception(e)
         except AttributeError, e:
             print("Error reading configfile %s and Logging not initialized" % filename)
Beispiel #9
0
				raise SystemExit(1)
		try:
			self.plugins.update([(name, code.Main(name, tasc))])
		except TypeError, t:
			Log.exception(t)
			self.plugins.update([(name, code.Main())])
			Log.error('loaded old-style plugin %s. Please derive from IPlugin' % name)
		self.plugins[name].socket = tasc.socket

		try:
			if "onload" in dir(self.plugins[name]):
				self.plugins[name].onload(tasc)
			if "onloggedin" in dir(self.plugins[name]) and self.app.connected:
				self.plugins[name].onloggedin(tasc.socket)
		except Exception, e:
			Log.exception(e)
			return
		Log.loaded("Plugin " + name)

	def unloadplugin(self, name):
		""" unload plugin, stop all its threads
		via ondestroy and remove from interal list"""
		if not name in self.plugins:
			Log.error("Plugin %s not loaded" % name)
			return
		try:
			if "ondestroy" in dir(self.plugins[name]):
				self.plugins[name].ondestroy()
			self.plugins.pop(name)
			Log.notice("%s Unloaded" % name)
		except Exception, e: