[Otfbot-svn] r103 - in trunk: . modules

cato- at BerliOS cato-
So Jun 10 20:38:38 CEST 2007


Author: cato-
Date: 2007-06-10 20:38:37 +0200 (Sun, 10 Jun 2007)
New Revision: 103

Modified:
   trunk/functions.py
   trunk/modules/answerMod.py
   trunk/modules/badwordsMod.py
   trunk/modules/commandsMod.py
   trunk/modules/kiMod.py
   trunk/modules/logMod.py
   trunk/modules/marvinMod.py
   trunk/otfbot.py
Log:
* modified modules to save their data into the right dirs

Modified: trunk/functions.py
===================================================================
--- trunk/functions.py	2007-06-10 18:33:12 UTC (rev 102)
+++ trunk/functions.py	2007-06-10 18:38:37 UTC (rev 103)
@@ -18,39 +18,44 @@
 # (c) 2006 by Robert Weidlich
 #
 
+import os
+
 def loadProperties(propertiesFile):
-	properties={}
-	if propertiesFile=="":
-		return {}
-	try:
-		propFile = open(propertiesFile, "r")
-		content = propFile.read()
-		propFile.close()
-		for line in content.split("\n"):
-			if len(line) >1 and line[0] != "#":
-				pair = line.split("=", 1)
-				if len(pair)==2:
-					properties[pair[0]] = pair[1]
-	except IOError:
-		print "loadProperties: Creating", propertiesFile
-		propFile = open(propertiesFile, "w")
-		propFile.close()
-	return properties
-	
+    properties={}
+    if propertiesFile=="":
+        return {}
+    try:
+        propFile = open(propertiesFile, "r")
+        content = propFile.read()
+        propFile.close()
+        for line in content.split("\n"):
+            if len(line) >1 and line[0] != "#":
+                pair = line.split("=", 1)
+                if len(pair)==2:
+                    properties[pair[0]] = pair[1]
+    except IOError:
+        print "loadProperties: Creating", propertiesFile
+        if (not os.path.isdir(os.path.dirname(propertiesFile))):
+            os.makedirs(os.path.dirname(propertiesFile))
+        propFile = open(propertiesFile, "w")
+        propFile.close()
+    return properties
+    
 def loadList(listFile):
-	if listFile=="":
-		return []
-	list=[]
-	try:
-		file = open(listFile, "r")
-		content = file.read()
-		file.close()
-		for word in content.split("\n"):
-			if word != "" and word[0] != '#':
-				list.append(word)
-	except IOError:
-		print "loadList: Creating", listFile
-		file = open(listFile, "w")
-		file.close()
-	return list
-
+    if listFile=="":
+        return []
+    list=[]
+    try:
+        file = open(listFile, "r")
+        content = file.read()
+        file.close()
+        for word in content.split("\n"):
+            if word != "" and word[0] != '#':
+                list.append(word)
+    except IOError:
+        print "loadList: Creating", listFile
+        if (not os.path.isdir(os.path.dirname(listFile))):
+            os.makedirs(os.path.dirname(listFile))
+        file = open(listFile, "w")
+        file.close()
+    return list

Modified: trunk/modules/answerMod.py
===================================================================
--- trunk/modules/answerMod.py	2007-06-10 18:33:12 UTC (rev 102)
+++ trunk/modules/answerMod.py	2007-06-10 18:38:37 UTC (rev 103)
@@ -23,14 +23,14 @@
 def default_settings():
 	settings={};
 	settings['answerMod.fileencoding']='iso-8859-15'
-	settings['answerMod.file']='answers.txt'
+	settings['answerMod.file']=datadir+'/answers.txt'
 	return settings
 		
 class chatMod(chatMod.chatMod):
 	def __init__(self, bot):
 		self.bot = bot
 
-		self.answersFile=bot.getConfig("file", "answers.txt", "answerMod")
+		self.answersFile=bot.getConfig("file", datadir+"/answers.txt", "answerMod")
 		self.answers = functions.loadProperties(self.answersFile)
 		self.channels={}
 		

Modified: trunk/modules/badwordsMod.py
===================================================================
--- trunk/modules/badwordsMod.py	2007-06-10 18:33:12 UTC (rev 102)
+++ trunk/modules/badwordsMod.py	2007-06-10 18:38:37 UTC (rev 103)
@@ -22,13 +22,13 @@
 
 def default_settings():
 	settings={};
-	settings['badwordsMod.file']='badwords.txt'
+	settings['badwordsMod.file']=datadir+'/badwords.txt'
 	return settings
 		
 class chatMod(chatMod.chatMod):
 	def __init__(self, bot):
 		self.bot=bot
-		self.badwordsFile=bot.getConfig("file", "badwords.txt","badwordsMod")
+		self.badwordsFile=bot.getConfig("file", datadir+"/badwords.txt","badwordsMod")
 		self.badwords=functions.loadList(self.badwordsFile)
 		self.channels = {}
 		

Modified: trunk/modules/commandsMod.py
===================================================================
--- trunk/modules/commandsMod.py	2007-06-10 18:33:12 UTC (rev 102)
+++ trunk/modules/commandsMod.py	2007-06-10 18:38:37 UTC (rev 103)
@@ -23,7 +23,7 @@
 def default_settings():
 	settings={};
 	settings['commandsMod.fileencoding']='iso-8859-15'
-	settings['commandsMod.file']='commands.txt'
+	settings['commandsMod.file']=datadir+'/commands.txt'
 	settings['commandsmod.commandChar']='!'
 	return settings
 		
@@ -37,7 +37,7 @@
 		self.reload()
 		
 	def joined(self, channel):
-		self.commands[channel]=functions.loadProperties(self.bot.getConfig("file", "commands.txt", "commandsMod", self.bot.network, channel))
+		self.commands[channel]=functions.loadProperties(self.bot.getConfig("file", datadir+"/commands.txt", "commandsMod", self.bot.network, channel))
 		self.commandChar[channel]=self.bot.getConfig("commandChar", "!", "commandsMod", self.bot.network, channel)
 	
 	def msg(self, user, channel, msg):
@@ -62,8 +62,8 @@
 	def start(self):
 		self.commands={}
 		self.commandChar={}
-		self.commands["general"]=functions.loadProperties(self.bot.getConfig("file","commands.txt","commandsMod"))
-		self.commands["network"]=functions.loadProperties(self.bot.getConfig("file","commands.txt","commandsMod", self.bot.network))
+		self.commands["general"]=functions.loadProperties(self.bot.getConfig("file",datadir+"/commands.txt","commandsMod"))
+		self.commands["network"]=functions.loadProperties(self.bot.getConfig("file",datadir+"/commands.txt","commandsMod", self.bot.network))
 
 	def reload(self):
 		self.start()

Modified: trunk/modules/kiMod.py
===================================================================
--- trunk/modules/kiMod.py	2007-06-10 18:33:12 UTC (rev 102)
+++ trunk/modules/kiMod.py	2007-06-10 18:38:37 UTC (rev 103)
@@ -42,7 +42,7 @@
 	settings['kiMod_keywordsTable']='keywords'
 	settings['kiMod_stringsTable']='strings'
 	
-	settings['kiMod_wordpairsFile']='wordpairs.txt'
+	settings['kiMod_wordpairsFile']=datadir+'/wordpairs.txt'
 	settings['kiMod_randomPercent']='0'
 	settings['kiMod_answerPercent']='50'
 	settings['kiMod_answerQueryPercent']='70'
@@ -183,7 +183,7 @@
 	def start(self):
 		self.logger = self.bot.logging.getLogger("core.kiMod")
 		self.channels=[]
-		self.wordpairsFile=self.bot.getConfig("kiMod_wordpairsFile", "wordpairs.txt")#XXX: this needs to be utf-8 encoded
+		self.wordpairsFile=self.bot.getConfig("kiMod_wordpairsFile", datadir+"/wordpairs.txt")#XXX: this needs to be utf-8 encoded
 		self.wordpairs=functions.loadProperties(self.wordpairsFile)
 
 		module=self.bot.getConfig("kiMod_module", "megahal")

Modified: trunk/modules/logMod.py
===================================================================
--- trunk/modules/logMod.py	2007-06-10 18:33:12 UTC (rev 102)
+++ trunk/modules/logMod.py	2007-06-10 18:38:37 UTC (rev 103)
@@ -25,7 +25,7 @@
 
 def default_settings():
 	settings={'logMod.path':'$n-$c/$y-$m-$d.log',
-			  'logMod.storedir':'log'}
+			  'logMod.dir':datadir}
 	return settings
 		
 class chatMod(chatMod.chatMod):
@@ -34,9 +34,10 @@
 		self.channels={}
 		self.files={}
 		self.path={}
-		self.logpath=bot.getConfig("logMod.storedir", "log")+"/"+bot.getConfig("logMod.path", "$n-$c/$y-$m-$d.log")
-		if not os.path.isdir(bot.getConfig("logMod.storedir", "log")):
-			os.mkdir(bot.getConfig("logMod.storedir", "log"))
+		self.datadir=bot.getConfig("logMod.dir",datadir)
+		self.logpath=self.datadir+"/"+bot.getConfig("logMod.path", "$n-$c/$y-$m-$d.log")
+		if not os.path.isdir(self.datadir):
+			os.mkdir(self.datadir)
 		locale.setlocale(locale.LC_ALL, "de_DE.UTF-8")
 		self.day=self.ts("%d") #saves the hour, to detect daychanges
 		#self.timer=threading.Timer(self.secsUntilDayChange(), self.dayChange)

Modified: trunk/modules/marvinMod.py
===================================================================
--- trunk/modules/marvinMod.py	2007-06-10 18:33:12 UTC (rev 102)
+++ trunk/modules/marvinMod.py	2007-06-10 18:38:37 UTC (rev 103)
@@ -23,7 +23,7 @@
 
 def default_settings():
 	settings={};
-	settings['marvinMod.filename']='marvin.txt'
+	settings['marvinMod.filename']=datadir+'/marvin.txt'
 	settings['marvinMod.percent']='5'
 	settings['marvinMod.fileencoding']='iso-8859-15'
 	return settings
@@ -43,7 +43,7 @@
 				self.bot.sendmsg(channel, random.choice(self.marvin), self.bot.getConfig("fileencoding", "iso-8859-15", "marvinMod"))
 
 	def start(self):
-		self.marvin=functions.loadList(self.bot.getConfig("filename", "marvin.txt", "marvinMod"))
+		self.marvin=functions.loadList(self.bot.getConfig("filename", datadir+"/marvin.txt", "marvinMod"))
 
 	def reload(self):
 		self.start()

Modified: trunk/otfbot.py
===================================================================
--- trunk/otfbot.py	2007-06-10 18:33:12 UTC (rev 102)
+++ trunk/otfbot.py	2007-06-10 18:38:37 UTC (rev 103)
@@ -30,11 +30,12 @@
 import os, random, string, re, threading, time, sys, traceback, threading, atexit
 import functions, config
 
-sys.path.append("module")
+sys.path.append("modules")
 classes=[]
 for file in os.listdir("modules"):
 	if len(file)>=3 and file[-3:]==".py":
 		classes.append(__import__("modules/"+file[:-3]))
+		classes[-1].datadir = classes[-1].__name__+"-data"
 
 modchars={'a':'!','o':'@','h':'%','v':'+'}
 modcharvals={'!':4,'@':3,'%':2,'+':1,' ':0}
@@ -237,6 +238,7 @@
 	
 	# public API
 	def startMods(self):
+		workingdir=os.getcwd()
 		for chatModule in self.classes:
 			#if self.getConfig("enabled","true",chatModule.__name__,self.network)
 			self.mods.append( chatModule.chatMod(self) )




Mehr Informationen über die Mailingliste Otfbot-dev