Example #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)
Example #2
0
	def forceunloadplugin(self, name, tasc):
		"""simply removes name from internal list, only call if unload else fails"""
		if not name in self.plugins:
			Log.error("Plugin %s not loaded" % name)
			return
		self.plugins.pop(name)
		Log.bad("%s UnLog.loaded(Forced)" % name)
Example #3
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)
Example #4
0
def _async_raise(tid, exctype):
	"""Raises an exception in the threads with id tid (note: never seen working)"""
	if not inspect.isclass(exctype):
		raise TypeError("Only types can be raised (not instances)")
	res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid,
				ctypes.py_object(exctype))
	if res == 0:
		Log.error("Cannot kill thread %i" % tid)
	if res != 1:
		#if it returns a number greater than one, you're in trouble,
		#and you should call it again with exc=NULL to revert the effect
		ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0)
Example #5
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)
Example #6
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)
Example #7
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)
Example #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)
Example #9
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)
Example #10
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)
Example #11
0
	def __init__(self, name, tasclient):
		super(IPlugin, self).__init__()
		self.tasclient = tasclient
		self.name = name
		self.logger = Log.getPluginLogger(name)
		self.commands = defaultdict(list)
		#this registers all cmd_* where * matches an actualLobby command in our command dict
		foreign_cmd_count = 0
		cmd_count = 0
		for f in filter( lambda f: f.startswith('cmd_'), dir(self)):
			try:
				name_tokens = f.split('_')
				cmd = name_tokens[1].upper()
				if len(name_tokens) >= 3 and cmd in CHAT_COMMANDS:
					self.commands[cmd].append(('!%s'%name_tokens[2],f))
				elif cmd in ALL_COMMANDS:
					self.commands[cmd].append((None,f))
				else:
					self.logger.error('trying to register function for unknown command %s'%cmd)
				foreign_cmd_count += f != 'cmd_said_help' and f != 'cmd_saidprivate_help'
				cmd_count += 1
			except IndexError,e:
				self.logger.debug(f)
				self.logger.exception(e)
Example #12
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:
Example #13
0
	def onloggedin(self, socket):
		Log.info("[LOGIN] successful")
Example #14
0
	def onsaidprivate(self, user, message):
		Log.info("[PRIVATE] <%s> %s" % (user, message))
Example #15
0
	def onsaidex(self, channel, user, message):
		Log.info("[CHANNELEX] %s: <%s> %s" % (channel, user, message))
Example #16
0
	def onmotd(self, content):
		Log.info("[MOTD] %s" % content)
Example #17
0
	def ondisconnected(self):
		Log.bad("Disconnected")
Example #18
0
	def onconnectedplugin(self):
		Log.good("Connected to TASServer")
Example #19
0
	def onsaidprivate(self, user, message):
		"""react on a few given keywords and also pass the call to all plugins"""
		args = message.split(" ")
		if args[0].lower() == "!reloadconfig" and user in self.app.admins:
			self.app.ReloadConfig()
		if (args[0].lower() == "!unloadplugin" and
				user in self.app.admins and len(args) == 2):
			try:
				self.unloadplugin(args[1])
			except Exception:
				Log.bad("Unloadplugin failed")
				Log.error(traceback.print_exc())

		if (args[0].lower() == "!loadplugin" and
				user in self.app.admins and len(args) == 2):
			try:
				self.addplugin(args[1], self.app.tasclient)
			except Exception:
				Log.bad("addplugin failed")
				Log.error(traceback.print_exc())

		if (args[0].lower() == "!reloadplugin" and
				user in self.app.admins and len(args) == 2):
			try:
				self.reloadplugin(args[1])
			except Exception:
				Log.bad("Unloadplugin failed")
				Log.error(traceback.print_exc())

		self.forall("onsaidprivate", user, message)
Example #20
0
	def reloadplugin(self, name):
		"""broken"""
		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()
			Log.notice("%s Unloaded" % name)
		except Exception:
			Log.error("Cannot unload plugin %s" % name)
			Log.error("Use forceunload to remove it anyway")
			Log.error(traceback.print_exc())
		try:
			code = reload(sys.modules[name])
		except Exception:
			Log.error("Cannot reload plugin %s!" % name)
			return
		self.plugins.update([(name, code.Main())])
		self.plugins[name].socket = self.app.tasclient.socket
		try:
			if "onload" in dir(self.plugins[name]):
				self.plugins[name].onload(self.app.tasclient)
		except Exception:
			Log.error("Cannot load plugin   " + name)
			Log.error(traceback.print_exc())
			return
		Log.loaded("Plugin " + name)