From: <ror...@us...> - 2007-06-29 08:29:04
|
Revision: 63 http://roreditor.svn.sourceforge.net/roreditor/?rev=63&view=rev Author: rorthomas Date: 2007-06-29 01:29:01 -0700 (Fri, 29 Jun 2007) Log Message: ----------- * deleted old settings class * added new settingsManager and logger * added update bat script * added config files for logging and editor.ini * modified existing classes to use new settingsManager and logger - not completed Modified Paths: -------------- trunk/lib/ror/starter.py trunk/lib/rorterraineditor/MainFrame.py trunk/lib/rorterraineditor/RoRTerrainOgreWindow.py trunk/lib/rortruckeditor/MainFrame.py trunk/lib/rortruckeditor/RoRTruckOgreWindow.py Added Paths: ----------- trunk/lib/ror/editor.ini trunk/lib/ror/logger.py trunk/lib/ror/logging.ini trunk/lib/ror/settingsManager.py trunk/update.bat trunk/update.py Removed Paths: ------------- trunk/lib/ror/rorsettings.py Added: trunk/lib/ror/editor.ini =================================================================== --- trunk/lib/ror/editor.ini (rev 0) +++ trunk/lib/ror/editor.ini 2007-06-29 08:29:01 UTC (rev 63) @@ -0,0 +1,6 @@ +[RigsOfRods] +basepath = C:\games\RoR-0.31a + +[gui] +usegui = yes + Added: trunk/lib/ror/logger.py =================================================================== --- trunk/lib/ror/logger.py (rev 0) +++ trunk/lib/ror/logger.py 2007-06-29 08:29:01 UTC (rev 63) @@ -0,0 +1,22 @@ +import os, os.path, sys, logging,logging.config + +LOGCONFIGFILE = "logging.ini" + +# "extended" singleton +_rorlogger = None +def log(): + global _rorlogger + if _rorlogger is None: + _rorlogger = RoRLogger() + return _rorlogger.getLog() + +class RoRLogger(): + logconfigfilename = os.path.join(os.path.dirname(os.path.abspath(__file__)), LOGCONFIGFILE) + + def __init__(self): + logging.config.fileConfig(self.logconfigfilename) + self.myLog = logging.getLogger("root") + self.myLog.info("logging initialised") + + def getLog(self): + return self.myLog Added: trunk/lib/ror/logging.ini =================================================================== --- trunk/lib/ror/logging.ini (rev 0) +++ trunk/lib/ror/logging.ini 2007-06-29 08:29:01 UTC (rev 63) @@ -0,0 +1,41 @@ +#lines with # are comments! +#please refer to http://docs.python.org/lib/logging-config-fileformat.html + +#list of loggin-targets +[loggers] +keys=root + +#list of handlers +[handlers] +keys=consolelog,filelog + +#list of formatters +[formatters] +keys=full,short + +#main logging-target +[logger_root] +level=NOTSET +handlers=consolelog,filelog + +[handler_filelog] +class=FileHandler +level=DEBUG +formatter=full +args=('editorlog.txt', 'w') + +#console-output-handler +[handler_consolelog] +class=StreamHandler +level=DEBUG +formatter=short +args=(sys.stdout,) + +#logging formats +[formatter_full] +format=%(asctime)s | %(levelname)s | %(filename)s:%(lineno)s | %(message)s +datefmt= + +[formatter_short] +format=%(asctime)s | %(levelname)s | %(message)s +datefmt= Deleted: trunk/lib/ror/rorsettings.py =================================================================== --- trunk/lib/ror/rorsettings.py 2007-06-28 22:29:21 UTC (rev 62) +++ trunk/lib/ror/rorsettings.py 2007-06-29 08:29:01 UTC (rev 63) @@ -1,40 +0,0 @@ -import os, os.path - - -_set = None -def getSettings(): - global _set - if _set is None: - _set = RoRSettings() - return _set - -class RoRSettings: - rordir = None - configfilename = os.path.join(os.path.dirname(os.path.abspath(__file__)), "editor.cfg") - def __init__(self): - self.LoadRoRDir() - - def getRoRDir(self): - return self.rordir - - def setRoRDir(self, dir): - self.rordir = dir - self.SaveRoRDir() - - def LoadRoRDir(self): - try: - f = open(self.configfilename,'r') - self.rordir = os.path.abspath(f.read()) - f.close() - print "Loaded RoR Directory: %s" % self.rordir - print "Loading..." - except: - print "error while loading rordir: %s" % self.configfilename - - def SaveRoRDir(self): - try: - f = open(self.configfilename,'w') - f.write(self.rordir) - f.close() - except: - print "error while saving rordir: %s" % os.path.abspath("editor.cfg") Added: trunk/lib/ror/settingsManager.py =================================================================== --- trunk/lib/ror/settingsManager.py (rev 0) +++ trunk/lib/ror/settingsManager.py 2007-06-29 08:29:01 UTC (rev 63) @@ -0,0 +1,54 @@ +import os, os.path, sys, ConfigParser +import logger + +CONFIGFILE = "editor.ini" + +# singleton pattern +_rorsettings = None +def getSettingsManager(): + global _rorsettings + if _rorsettings is None: + _rorsettings = RoRSettings() + return _rorsettings + +class RoRSettings: + myConfig = None + configfilename = os.path.join(os.path.dirname(os.path.abspath(__file__)), CONFIGFILE) + + def __init__(self): + self.loadSettings() + + def loadSettings(self): + try: + self.myConfig = ConfigParser.ConfigParser() + self.myConfig.read(self.configfilename) + logger.log().info("Settings loaded") + except Exception, e: + logger.log().exception(str(e)) + + def getSetting(self, group, key): + try: + return self.myConfig.get(group, key) + except Exception, e: + logger.log().exception(str(e)) + return "" + + def saveSettings(self): + try: + fp = open(self.configfilename, 'w') + self.myConfig.write(fp) + fp.close() + logger.log().info("Settings saved") + except Exception, e: + logger.log().exception(str(e)) + + def setSetting(self, section, option, value): + try: + if not self.myConfig.has_section(section): + self.myConfig.add_section(section) + self.myConfig.set(section, option, value) + self.saveSettings() + return True + except Exception, e: + logger.log().exception(str(e)) + return False Modified: trunk/lib/ror/starter.py =================================================================== --- trunk/lib/ror/starter.py 2007-06-28 22:29:21 UTC (rev 62) +++ trunk/lib/ror/starter.py 2007-06-29 08:29:01 UTC (rev 63) @@ -1,11 +1,14 @@ #Thomas Fischer 31/05/2007, th...@th... from wxogre.OgreManager import * from ror.RoROgreWindow import * -from ror.rorsettings import * from ror.rorcommon import * from subprocess import Popen -import wx +from ror.logger import log +from ror.settingsManager import getSettingsManager + +import wx, os, os.path + class SettingsDialog(wx.Frame): rordir = None def __init__(self, *args, **kwds): @@ -36,7 +39,7 @@ self.btnExit = wx.Button(self.panel, wx.ID_ANY, "Exit") self.Bind(wx.EVT_BUTTON, self.OnExit, self.btnExit) - self.rordir = getSettings().getRoRDir() + self.rordir = getSettingsManager().getSetting("RigsOfRods", "BasePath") #print self.rordir if not self.rordir is None: if self.checkRoRDir(self.rordir): @@ -63,36 +66,41 @@ svn.run() def OnStartRoR(self, event=None): - #escape spaces! - path = os.path.join(self.rordir, "RoR.exe") - print path - p = Popen(path, shell=False, cwd=self.rordir) - #sts = os.waitpid(p.pid, 0) + try: + path = os.path.join(self.rordir, "RoR.exe") + log().info("starting RoR: %s" % path) + p = Popen(path, shell = False, cwd = self.rordir) + #sts = os.waitpid(p.pid, 0) + except Exception, e: + log().exception(str(e)) def OnTruckEditor(self, event=None): - import rortruckeditor.MainFrame try: + import rortruckeditor.MainFrame self.Close() + log().info("starting Truckeditor") app = rortruckeditor.MainFrame.startApp() del app - except: - pass + except Exception, e: + log().exception(str(e)) def OnBugReport(self, event=None): - import ror.bugreport - #try: - ror.bugreport.showBugReportFrame() - #except: - # pass + try: + log().info("starting bugreporter") + import ror.bugreport + ror.bugreport.showBugReportFrame() + except Exception, e: + log().exception(str(e)) def OnTerrainEditor(self, event=None): - import rorterraineditor.MainFrame try: + import rorterraineditor.MainFrame + log().info("starting Terraineditor") self.Close() app = rorterraineditor.MainFrame.startApp() del app - except: - pass + except Exception, e: + log().exception(str(e)) def checkRoRDir(self, fn): # withoutspaces = (fn.find(" ") == -1) @@ -123,7 +131,7 @@ #newpath = newpath.replace(" ", "\ ") self.rordir = newpath self.lblRoRDir.SetLabel(newpath) - getSettings().setRoRDir(newpath) + getSettingsManager().setSetting("RigsOfRods", "BasePath", newpath) #self.btnStartRoR.Enable(True) self.btnStartTruckEditor.Enable(True) self.btnStartTerrainEditor.Enable(True) Modified: trunk/lib/rorterraineditor/MainFrame.py =================================================================== --- trunk/lib/rorterraineditor/MainFrame.py 2007-06-28 22:29:21 UTC (rev 62) +++ trunk/lib/rorterraineditor/MainFrame.py 2007-06-29 08:29:01 UTC (rev 63) @@ -1,7 +1,10 @@ #Thomas Fischer 31/05/2007, th...@th... from wxogre.OgreManager import * from ror.RoROgreWindow import * -from ror.rorsettings import * + +from ror.logger import log +from ror.settingsManager import getSettingsManager + from ror.rorcommon import * from RoRTerrainOgreWindow import * from RoRTerrainSelectedObjectOgreWindow import * @@ -48,7 +51,7 @@ self.splitter.SetSashPosition(100) self.splitter.SetMinimumPaneSize(200) - self.rordir = getSettings().getRoRDir() + self.rordir = getSettingsManager().getSetting("RigsOfRods", "BasePath") #ogre windows self.terrainOgreWin = RoRTerrainOgreWindow(self.splitterleft, wx.ID_ANY, rordir=self.rordir) Modified: trunk/lib/rorterraineditor/RoRTerrainOgreWindow.py =================================================================== --- trunk/lib/rorterraineditor/RoRTerrainOgreWindow.py 2007-06-28 22:29:21 UTC (rev 62) +++ trunk/lib/rorterraineditor/RoRTerrainOgreWindow.py 2007-06-29 08:29:01 UTC (rev 63) @@ -844,7 +844,7 @@ myManualObject.position(float(node[1]),float(node[2]),float(node[3])) print len(p.tree['submeshgroups']) - if not 'submeshgroups' in p.tree.keys() or len(p.tree['submeshgroups']) == 0: + if len(p.tree['submeshgroups']) > 0: faces = [] for smobj in p.tree['submeshgroups']: for cabobj in smobj['cab']: Modified: trunk/lib/rortruckeditor/MainFrame.py =================================================================== --- trunk/lib/rortruckeditor/MainFrame.py 2007-06-28 22:29:21 UTC (rev 62) +++ trunk/lib/rortruckeditor/MainFrame.py 2007-06-29 08:29:01 UTC (rev 63) @@ -1,7 +1,10 @@ #Thomas Fischer 31/05/2007, th...@th... from wxogre.OgreManager import * from ror.RoROgreWindow import * -from ror.rorsettings import * + +from ror.logger import log +from ror.settingsManager import getSettingsManager + from ror.rorcommon import * from RoRTruckOgreWindow import * @@ -44,7 +47,7 @@ self.splitter.SetSashPosition(100) self.splitter.SetMinimumPaneSize(200) - self.rordir = getSettings().getRoRDir() + self.rordir = getSettingsManager().getSetting("RigsOfRods", "BasePath") #ogre windows self.truckOgreWin = RoRTruckOgreWindow(self.splitterleft, wx.ID_ANY) Modified: trunk/lib/rortruckeditor/RoRTruckOgreWindow.py =================================================================== --- trunk/lib/rortruckeditor/RoRTruckOgreWindow.py 2007-06-28 22:29:21 UTC (rev 62) +++ trunk/lib/rortruckeditor/RoRTruckOgreWindow.py 2007-06-29 08:29:01 UTC (rev 63) @@ -2,7 +2,10 @@ import wx, os, os.path import ogre.renderer.OGRE as ogre from ror.truckparser import * -from ror.rorsettings import * + +from ror.logger import log +from ror.settingsManager import getSettingsManager + from ror.rorcommon import * from wxogre.OgreManager import * from wxogre.wxOgreWindow import * @@ -17,7 +20,7 @@ class RoRTruckOgreWindow(wxOgreWindow): def __init__(self, parent, ID, size = wx.Size(200,200), **kwargs): self.parent = parent - self.rordir = getSettings().getRoRDir() + self.rordir = getSettingsManager().getSetting("RigsOfRods", "BasePath") self.World = OgreNewt.World() self.sceneManager = None self.uvFrame = None Added: trunk/update.bat =================================================================== --- trunk/update.bat (rev 0) +++ trunk/update.bat 2007-06-29 08:29:01 UTC (rev 63) @@ -0,0 +1 @@ +%systemdrive%\python25\python.exe update.py %1 %2 %3 %4 %5 %6 %7 %8 %9 Added: trunk/update.py =================================================================== --- trunk/update.py (rev 0) +++ trunk/update.py 2007-06-29 08:29:01 UTC (rev 63) @@ -0,0 +1,9 @@ +import sys, os, os.path + +def main(): + sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "lib")) + import ror.svn + ror.svn.run() + +if __name__=="__main__": + main() \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |