From: <jb...@us...> - 2009-10-19 09:42:01
|
Revision: 368 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=368&view=rev Author: jblance Date: 2009-10-19 09:41:47 +0000 (Mon, 19 Oct 2009) Log Message: ----------- Added tmp dir clean up on start to plugins-v2 branch Modified Paths: -------------- pytrainer/branches/plugins-v2/pytrainer/lib/system.py pytrainer/branches/plugins-v2/pytrainer/main.py Modified: pytrainer/branches/plugins-v2/pytrainer/lib/system.py =================================================================== --- pytrainer/branches/plugins-v2/pytrainer/lib/system.py 2009-10-15 09:30:33 UTC (rev 367) +++ pytrainer/branches/plugins-v2/pytrainer/lib/system.py 2009-10-19 09:41:47 UTC (rev 368) @@ -25,7 +25,7 @@ self.tmpdir = None self.confdir = None self.conffile = None - self.gpxdir = None + self.gpxdir = None self.extensiondir = None self.plugindir = None @@ -36,48 +36,60 @@ self._setPluginDir() self._setGpxDir() - def _setHome(self): - if sys.platform == "linux2": - variable = 'HOME' - elif sys.platform == "win32": + def _setHome(self): + if sys.platform == "linux2": + variable = 'HOME' + elif sys.platform == "win32": variable = 'USERPROFILE' + else: + print "Unsupported sys.platform: %s." % sys.platform + sys.exit(1) + self.home = os.environ[variable] + + def _setTempDir(self): + self.tmpdir = self.confdir+"/tmp" + if not os.path.isdir(self.tmpdir): + os.mkdir(self.tmpdir) - self.home = os.environ[variable] - - def _setTempDir(self): - if sys.platform == "win32": - self.tmpdir = "C:/backup" - elif sys.platform == "linux2": - self.tmpdir = self.confdir+"/tmp" - - if not os.path.isdir(self.tmpdir): - os.mkdir(self.tmpdir) - - def _setConfFiles(self): - if sys.platform == "win32": - self.confdir = self.home+"/pytrainer" - self.conffile = self.confdir+"/conf.xml" - elif sys.platform == "linux2": - self.confdir = self.home+"/.pytrainer" - self.conffile = self.confdir+"/conf.xml" - + def clearTempDir(self): + """Function to clear out the tmp directory that pytrainer uses + will only remove files + """ + if not os.path.isdir(self.tmpdir): + return + else: + files = os.listdir(self.tmpdir) + for name in files: + fullname = (os.path.join(self.tmpdir, name)) + if os.path.isfile(fullname): + os.remove(os.path.join(self.tmpdir, name)) + + def _setConfFiles(self): + if sys.platform == "win32": + self.confdir = self.home+"/pytrainer" + elif sys.platform == "linux2": + self.confdir = self.home+"/.pytrainer" + else: + print "Unsupported sys.platform: %s." % sys.platform + sys.exit(1) + self.conffile = self.confdir+"/conf.xml" if not os.path.isdir(self.confdir): - os.mkdir(self.confdir) + os.mkdir(self.confdir) def _setGpxDir(self): - self.gpxdir = self.confdir+"/gpx" + self.gpxdir = self.confdir+"/gpx" if not os.path.isdir(self.gpxdir): - os.mkdir(self.gpxdir) + os.mkdir(self.gpxdir) def _setExtensionDir(self): - self.extensiondir = self.confdir+"/extensions" + self.extensiondir = self.confdir+"/extensions" if not os.path.isdir(self.extensiondir): - os.mkdir(self.extensiondir) + os.mkdir(self.extensiondir) def _setPluginDir(self): - self.plugindir = self.confdir+"/plugins" + self.plugindir = self.confdir+"/plugins" if not os.path.isdir(self.plugindir): - os.mkdir(self.plugindir) + os.mkdir(self.plugindir) def getConfFile(self): if not os.path.isfile(self.conffile): @@ -88,4 +100,3 @@ def getValue(self,variable): method = getattr(self, variable) return method - Modified: pytrainer/branches/plugins-v2/pytrainer/main.py =================================================================== --- pytrainer/branches/plugins-v2/pytrainer/main.py 2009-10-15 09:30:33 UTC (rev 367) +++ pytrainer/branches/plugins-v2/pytrainer/main.py 2009-10-19 09:41:47 UTC (rev 368) @@ -105,6 +105,8 @@ logging.debug('checking configuration...') self.conf = checkConf() + logging.debug("clearing tmp directory %s" % self.conf.getValue("tmpdir")) + self.conf.clearTempDir() self.filename = self.conf.getValue("conffile") logging.debug('retrieving data from '+ self.filename) self.configuration = XMLParser(self.filename) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |