[Pymoul-svn] SF.net SVN: pymoul: [269] pymoul/trunk/src/moul/file
Status: Alpha
Brought to you by:
tiran
From: <ti...@us...> - 2007-03-20 17:28:39
|
Revision: 269 http://pymoul.svn.sourceforge.net/pymoul/?rev=269&view=rev Author: tiran Date: 2007-03-20 10:19:45 -0700 (Tue, 20 Mar 2007) Log Message: ----------- Changed mkdir/makedirs in moul.file and added more logging. The factories mustn't create the directories when its parent directories are missing. Modified Paths: -------------- pymoul/trunk/src/moul/file/chatlog.py pymoul/trunk/src/moul/file/directory.py pymoul/trunk/src/moul/file/kiimage.py Modified: pymoul/trunk/src/moul/file/chatlog.py =================================================================== --- pymoul/trunk/src/moul/file/chatlog.py 2007-03-19 21:08:20 UTC (rev 268) +++ pymoul/trunk/src/moul/file/chatlog.py 2007-03-20 17:19:45 UTC (rev 269) @@ -91,7 +91,7 @@ def clear(self): """Clear results and check the existence of directories - + @return: state of directories, True if everything is ok @rtype: bool """ @@ -99,10 +99,11 @@ if not os.path.isdir(self._srcdir): LOG.warning("%s is not a directory" % self._srcdir) return False - if not os.path.isdir(self._destdir): - LOG.info("Creating chatlog directory %s" % self._destdir) - os.mkdir(self._destdir) - return False + else: + if not os.path.isdir(self._destdir): + LOG.info("Creating chatlog directory %s" % self._destdir) + os.mkdir(self._destdir) + return False # XXX ??? return True def findLogs(self): Modified: pymoul/trunk/src/moul/file/directory.py =================================================================== --- pymoul/trunk/src/moul/file/directory.py 2007-03-19 21:08:20 UTC (rev 268) +++ pymoul/trunk/src/moul/file/directory.py 2007-03-20 17:19:45 UTC (rev 269) @@ -62,7 +62,7 @@ class AbstractUruDirectory(object): """Abstract class for an Uru directory - + @cvar _dirmapping: A mapping of name S{->} subpath @type _dirmapping: dict @cvar _factories: A list of factories name S{->} (callable, name tuples) C{_dirmapping} @@ -80,6 +80,12 @@ @type basepath: str """ self._basepath = basepath + if not self.exists(): + LOG.warning("Basepath %s does not exist for %s!" % + (self._basepath, self.__class__.__name__)) + else: + LOG.debug("Using basepath %s for %s" % + (self._basepath, self.__class__.__name__)) for key in self._factories: if key in self.__class__.__dict__: raise AttributeError("Name %s is reserved and can't be used " @@ -103,10 +109,9 @@ @rtype: str """ if name and name != '.': - path = self._dirmapping[name] + return os.path.join(self._basepath, self._dirmapping[name]) else: - path = '' - return os.path.join(self._basepath, path) + return self._basepath def factory(self, name): """Factory - creates instances to handle subdirectories and files @@ -135,7 +140,7 @@ class UruGameDataDirectory(AbstractUruDirectory): """Uru game directory handler - + An uru game directory contains the launcher, explorer, age files, sound files, localizations and other stuff. """ @@ -152,7 +157,7 @@ class UruPersonalDataDirectory(AbstractUruDirectory): """Uru personal data handler - + An uru personal data directory contains per user data like audio and graphics settings, KI shots, avatar images, logs and pyMoul specific data. @@ -193,7 +198,8 @@ if not name or name == '.': raise ValueError("Cannot create() basedir") path = self.get(name) - os.makedirs(path) + os.mkdir(path) + #os.makedirs(path) # XXX return path def createTree(self): @@ -203,7 +209,8 @@ @rtype: list of str """ created = [] - if not self.exists(''): + if not self.exists(): + raise OSError("Basepath doesn't exist") # XXX os.mkdir(self._basepath) created.append(self._basepath) for key in self._dirmapping: Modified: pymoul/trunk/src/moul/file/kiimage.py =================================================================== --- pymoul/trunk/src/moul/file/kiimage.py 2007-03-19 21:08:20 UTC (rev 268) +++ pymoul/trunk/src/moul/file/kiimage.py 2007-03-20 17:19:45 UTC (rev 269) @@ -226,14 +226,15 @@ if not os.path.isdir(srcdir): LOG.warning("%s is not a directory" % srcdir) - if not os.path.isdir(destdir): - LOG.info("Creating fixed images directory %s" % destdir) - os.mkdir(destdir) + else: + if not os.path.isdir(destdir): + LOG.info("Creating fixed images directory %s" % destdir) + os.mkdir(destdir) @staticmethod def mkFixedName(path, name, dest): """Make new new based on the name of the KI image - + @param path: directory where the file lives @type path: str @param name: name of the image w/o path This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |