Ejemplo n.º 1
0
	def onSelectImportPageLeft(self, page):
		if page.get_property('complete'):
			path = self.controller.selectImportPage.getSelectedBotConfFilePath()
			if path:
				config = BotPhpConfigFile(path)
				config.load()
				self.botConfig = config
Ejemplo n.º 2
0
	def start(self):
		"""Starts the bot."""
		# do nothing if bot process is still running.
		if self.process.isRunning():
			return

		configPath = self.settingModel.getValue(self.name, 'configfile')
		self.configFile = BotPhpConfigFile(configPath)
		self.configFile.load()
		port = self.configFile.getVar('API Port')

		# make sure that port is within defined range
		lowPort  = self.settingModel.getApiPortRangeLow()
		highPort = self.settingModel.getApiPortRangeHigh()
		if port < lowPort or port > highPort:
			port = lowPort
			self.configFile.setVar('API Port', port)
			self.configFile.save()

		# find a free port if currently set port is not free
		if self.isPortFree(port) == False:
			for port in range(lowPort, highPort + 1):
				if self.isPortFree(port):
					self.configFile.setVar('API Port', port)
					self.configFile.save()
					break

		self.noRestart = False
		self.process.setConfigFilePath(configPath)
		self.process.setWorkingDirectoryPath(self.settingModel.getValue(self.name, 'installdir'))
		self.process.start()
		self.notify('isRunning')
		self.pollApi()
Ejemplo n.º 3
0
	def load(self, path):
		"""Loads all config files from given path and adds them to the model."""
		self.clear()
		for fileName in os.listdir(path):
			# ignore the template file
			if fileName == 'config.template.php':
				continue
			try:
				# try to load the file as a config file
				filePath = os.path.join(path, fileName)
				configFile = BotPhpConfigFile(filePath)
				configFile.load()
				name = configFile.getVar('name')
				dimension = 'RK %s' % configFile.getVar('dimension')
			except (KeyError, IOError):
				# ignore files which are not valid config files
				continue
			# add to the config file to model
			self.append((fileName, name, dimension))
Ejemplo n.º 4
0
	def onSelectBotInstallDirectoryPageLeft(self, page):
		"""This signal handler is called when wizard leaves page where user can
		give path to the bot's directory.
		"""
		if page.get_property('complete'):
			# build a path to the new configuration file
			dirPath = os.path.join(self.getBotInstallPath(), 'conf')
			fileName = 'config.php'
			counter = 0
			while os.path.exists(os.path.join(dirPath, fileName)):
				fileName = 'config%s.php' % (counter + 2)
				counter += 1
			path = os.path.join(dirPath, fileName)
			# initialize the file
			self.botConfig = BotPhpConfigFile(path)
			self.botConfig.load()
Ejemplo n.º 5
0
class Bot(gobject.GObject):
	""""""

	# custom properties
	__gproperties__ = {
		'apiAccessible' : (gobject.TYPE_BOOLEAN, 'api accessible', 'is api accessible', False, gobject.PARAM_READWRITE),
		'isRunning' : (gobject.TYPE_BOOLEAN, 'is running', 'is running', False, gobject.PARAM_READWRITE)
	}

	CHANNEL_TELL = 0
	CHANNEL_ORG = 1
	CHANNEL_PRIVATE = 2
 
	def __init__(self, name, settingModel):
		"""Constructor method."""
		self.__gobject_init__()
		self.name = name
		self.settingModel = settingModel
		self.api = budapi.Budapi()
		self.process = Process()
		self.consoleModel = gtk.TextBuffer()
		self.configFile = None
		self.noRestart = False
		self.set_property('apiAccessible', False)
		self.process.connect('stdout_received', self.onBotStdoutReceived)
		self.process.connect('stderr_received', self.onBotStderrReceived)
		self.process.connect('stopped', self.onBotDied)

		tagTable = self.consoleModel.get_tag_table()

		def addTag(buffer, name, foreground, weight = None):
			"""Adds a text tag to buffer with given name and styles."""
			tag = gtk.TextTag(name)
			tag.set_property('foreground', foreground)
			if weight != None:
				tag.set_property('weight', weight)
			buffer.get_tag_table().add(tag)

		addTag(self.consoleModel, 'error', foreground = 'red', weight = pango.WEIGHT_BOLD)
		addTag(self.consoleModel, 'response', foreground = 'lightblue')


	def do_get_property(self, property):
		"""Returns value of given property.
		This is required to make GTK's properties to work.
		See: http://www.pygtk.org/articles/subclassing-gobject/sub-classing-gobject-in-python.htm#d0e127
		"""
		if property.name == 'apiAccessible':
			return self.apiAccessible
		elif property.name == 'isRunning':
			return self.process.isRunning()
		else:
			raise AttributeError, 'unknown property %s' % property.name

	def do_set_property(self, property, value):
		"""Sets value of given property.
		This is required to make GTK's properties to work.
		See: http://www.pygtk.org/articles/subclassing-gobject/sub-classing-gobject-in-python.htm#d0e127
		"""
		if property.name == 'apiAccessible':
			self.apiAccessible = value
		else:
			raise AttributeError, 'unknown property %s' % property.name

	def getName(self):
		"""Returns name of the bot."""
		return self.name

	def getConsoleModel(self):
		"""Returns console model"""
		return self.consoleModel

	def start(self):
		"""Starts the bot."""
		# do nothing if bot process is still running.
		if self.process.isRunning():
			return

		configPath = self.settingModel.getValue(self.name, 'configfile')
		self.configFile = BotPhpConfigFile(configPath)
		self.configFile.load()
		port = self.configFile.getVar('API Port')

		# make sure that port is within defined range
		lowPort  = self.settingModel.getApiPortRangeLow()
		highPort = self.settingModel.getApiPortRangeHigh()
		if port < lowPort or port > highPort:
			port = lowPort
			self.configFile.setVar('API Port', port)
			self.configFile.save()

		# find a free port if currently set port is not free
		if self.isPortFree(port) == False:
			for port in range(lowPort, highPort + 1):
				if self.isPortFree(port):
					self.configFile.setVar('API Port', port)
					self.configFile.save()
					break

		self.noRestart = False
		self.process.setConfigFilePath(configPath)
		self.process.setWorkingDirectoryPath(self.settingModel.getValue(self.name, 'installdir'))
		self.process.start()
		self.notify('isRunning')
		self.pollApi()

	def isPortFree(self, port):
		"""Returns True if given TCP/IP port is free."""
		s = None
		try:
			s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
			s.bind(('0.0.0.0', port))
			return True
		except socket.error, e:
			try:
				s.close()
			except:
				pass
		return False
Ejemplo n.º 6
0
class AddNewHandler(object):
	""""""
	def __init__(self, controller):
		"""Constructor method."""
		self.controller = controller
		controller.selectBotInstallDirPage.connect('left', self.onSelectBotInstallDirectoryPageLeft)
		self.botConfig = None

	def apply(self):
		self.botConfig.save()
		rootPath = self.getBotInstallPath()
		confPath = self.botConfig.getFilePath()
		name = self.controller.botNamePage.getBotName()
		self.controller.settingModel.addBot(name, confPath, rootPath)
		self.controller.settingModel.save()

	def getBotInstallPath(self):
		"""Returns currently selected bot install path."""
		return self.controller.selectBotInstallDirPage.getSelectedBotRootPath()

	def getCharacterName(self):
		return self.controller.enterCharacterInfoPage.getCharacterName()

	def getDimension(self):
		return self.controller.enterCharacterInfoPage.getDimension()

	def updateConfig(self):
		self.botConfig.setVar('login', self.controller.enterAccountInfoPage.getUsername())
		self.botConfig.setVar('password', self.controller.enterAccountInfoPage.getPassword())

		self.botConfig.setVar('name', self.controller.enterCharacterInfoPage.getCharacterName())
		self.botConfig.setVar('dimension', int(self.controller.enterCharacterInfoPage.getDimension()))

		if self.controller.selectBotTypePage.isOrganizationBot():
			self.botConfig.setVar('my_guild', self.controller.selectBotTypePage.getOrganizationName())

		self.botConfig.setVar('SuperAdmin', self.controller.enterSuperAdminPage.getSuperAdminName())

		if self.controller.selectDBSettingsPage.areManualSettingsUsed():
			if self.controller.selectDBTypePage.isSqliteSelected():
				self.botConfig.setVar('DB Type', 'sqlite')
				self.botConfig.setVar('DB Name', self.controller.enterSqliteSettingsPage.getDatabaseFilename())
				path = self.controller.enterSqliteSettingsPage.getDatabaseFolderPath()
				if sys.platform.startswith('win32'):
					path = path.replace('\\', '/')
				path = './' + path + '/'
				self.botConfig.setVar('DB Host', path)
			elif self.controller.selectDBTypePage.isMysqlSelected():
				self.botConfig.setVar('DB Type', 'mysql')
				self.botConfig.setVar('DB Name', self.controller.enterMysqlSettingsPage.getDatabaseName())
				self.botConfig.setVar('DB Host', self.controller.enterMysqlSettingsPage.getHost())
				self.botConfig.setVar('DB username', self.controller.enterMysqlSettingsPage.getUsername())
				self.botConfig.setVar('DB password', self.controller.enterMysqlSettingsPage.getPassword())

		self.botConfig.setVar('default_module_status', int(self.controller.selectModuleStatusPage.areModulesEnabledByDefault()))

	def getSummaryValues(self):
		values = {}
		values['name'] = self.controller.botNamePage.getBotName()
		values['root path'] = self.getBotInstallPath()
		values['conf path'] = self.botConfig.getFilePath()
		self.updateConfig()
		values['config'] = self.botConfig
		return values

	def onSelectBotInstallDirectoryPageLeft(self, page):
		"""This signal handler is called when wizard leaves page where user can
		give path to the bot's directory.
		"""
		if page.get_property('complete'):
			# build a path to the new configuration file
			dirPath = os.path.join(self.getBotInstallPath(), 'conf')
			fileName = 'config.php'
			counter = 0
			while os.path.exists(os.path.join(dirPath, fileName)):
				fileName = 'config%s.php' % (counter + 2)
				counter += 1
			path = os.path.join(dirPath, fileName)
			# initialize the file
			self.botConfig = BotPhpConfigFile(path)
			self.botConfig.load()