[Pymoul-svn] SF.net SVN: pymoul: [112] pymoul/trunk/src/moul/file
Status: Alpha
Brought to you by:
tiran
From: <ti...@us...> - 2007-02-01 02:39:34
|
Revision: 112 http://pymoul.svn.sourceforge.net/pymoul/?rev=112&view=rev Author: tiran Date: 2007-01-31 18:39:34 -0800 (Wed, 31 Jan 2007) Log Message: ----------- Added directory handler Modified Paths: -------------- pymoul/trunk/src/moul/file/localization.py Added Paths: ----------- pymoul/trunk/src/moul/file/directory.py pymoul/trunk/src/moul/file/tests/test_directory.py Removed Paths: ------------- pymoul/trunk/src/moul/file/directories.py Deleted: pymoul/trunk/src/moul/file/directories.py =================================================================== --- pymoul/trunk/src/moul/file/directories.py 2007-02-01 00:05:40 UTC (rev 111) +++ pymoul/trunk/src/moul/file/directories.py 2007-02-01 02:39:34 UTC (rev 112) @@ -1,78 +0,0 @@ -# pyMoul - Python interface to Myst Online URU Live -# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> - -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation; either version 2 of the License, or (at your -# option) any later version. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., 59 -# Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -"""Directories: Uru game directory and Uru personal data directory -""" -__author__ = "Christian Heimes" -__version__ = "$Id$" -__revision__ = "$Revision$" - -import os - -from moul.log import getLogger -from moul.file.chatlog import ChatlogMover -from moul.file.chatlog import ChatlogDirectoryView -from moul.file.plasmalog import PlasmalogZipper -from moul.file.kiimage import KIImageFixer - -LOG = getLogger('moul.file.directory') - -class AbstractUruDirectory(object): - """Abstract class for an Uru directory - """ - _dirmapping = {} - - def __init__(self, basedir): - self._basedir = basedir - - def exists(self): - return os.path.isdir(self._basedir) - - def get(self, name): - path = self._dirmapping(name) - return os.path.join(self._basedir, path) - -class UruGameDataDirectory(AbstractUruDirectory): - """Uru game directory handler - - An uru game directory contains the launcher, explorer, age files, sound - files, localizations and other stuff. - """ - _dirmapping = { - 'loc' : 'dat', - 'dat' : 'dat', - 'sound' : 'sfx' - 'soundwav' : 'sfx' + os.sep + 'streamingCache', - 'video' : 'avi', - } - -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. - """ - _dirmapping = { - 'log' : 'Log', - 'kiimages' : 'KIimages', - 'avatars' : 'Avatars', - 'ini' : 'init', - 'chatlogs' : 'Chatlogs', - 'zipped' : 'ZippedLogs', - } - Copied: pymoul/trunk/src/moul/file/directory.py (from rev 111, pymoul/trunk/src/moul/file/directories.py) =================================================================== --- pymoul/trunk/src/moul/file/directory.py (rev 0) +++ pymoul/trunk/src/moul/file/directory.py 2007-02-01 02:39:34 UTC (rev 112) @@ -0,0 +1,130 @@ +# pyMoul - Python interface to Myst Online URU Live +# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> + +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., 59 +# Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +"""Directories: Uru game directory and Uru personal data directory +""" +__author__ = "Christian Heimes" +__version__ = "$Id$" +__revision__ = "$Revision$" + +import os + +from moul.log import getLogger +from moul.file.chatlog import ChatlogMover +from moul.file.chatlog import ChatlogDirectoryView +from moul.file.plasmalog import PlasmalogZipper +from moul.file.kiimage import KIImageFixer +from moul.file.wdysini import GraphicsIni +from moul.file.wdysini import AudioIni +from moul.file.localization import parseLocDirectory + +LOG = getLogger('moul.file.directory') + +class AbstractUruDirectory(object): + """Abstract class for an Uru directory + """ + # name -> subpath + _dirmapping = {} + # name -> (callable, nametuple) + _factories = {} + + def __init__(self, basepath): + self._basepath = basepath + + def exists(self, name=None): + """Check if directory with name exists. + """ + os.path.isdir(self.get(name)) + + def get(self, name=None): + """Get complete path for name + + None or '.' means basedir. + """ + if name and name != '.': + path = self._dirmapping(name) + else: + path = '' + return os.path.join(self._basepath, path) + + def factory(self, name): + """Factory - creates instances to handle subdirectories and files + """ + args = [] + factory, argnames = self._factories[name] + for name in argnames: + args.append(self.get(name)) + return factory(*args) + +class UruGameDataDirectory(AbstractUruDirectory): + """Uru game directory handler + + An uru game directory contains the launcher, explorer, age files, sound + files, localizations and other stuff. + """ + _dirmapping = { + 'loc' : 'dat', + 'dat' : 'dat', + 'sound' : 'sfx', + 'soundwav' : 'sfx' + os.sep + 'streamingCache', + 'video' : 'avi', + } + _factory = { + 'loc' : (parseLocDirectory, ('loc',)), + } + +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. + """ + _dirmapping = { + 'log' : 'Log', + 'kiimages' : 'KIimages', + 'avatars' : 'Avatars', + 'ini' : 'init', + 'chatlogs' : 'Chatlogs', + 'zipped' : 'ZippedLogs', + 'fixed' : 'FixedImages', + } + + _factories = { + 'log-chat' : (ChatlogMover, ('log', 'chatlogs')), + 'log-zip' : (PlasmalogZipper, ('log', 'zipped')), + 'kiimages' : (KIImageFixer, ('kiimages', 'fixed')), + 'avatars' : (KIImageFixer, ('avatars', 'fixed')), + 'graphics.ini' : (GraphicsIni, ('ini',)), + 'audio.ini' : (AudioIni, ('ini',)), + 'chatlogs' : (ChatlogDirectoryView, ('chatlogs',)), + 'zipped' : None, + 'fixed' : None, + } + + def createTree(self): + """Create the directory tree + """ + created = [] + if self.exists(''): + os.mkdir(self._basepath) + created.append(self._basepath) + for key in self._dirmapping: + if not self.exists(key): + os.mkdir(path) + created.append(path) + return created Property changes on: pymoul/trunk/src/moul/file/directory.py ___________________________________________________________________ Name: svn:keywords + Id Revision Name: svn:eol-style + native Modified: pymoul/trunk/src/moul/file/localization.py =================================================================== --- pymoul/trunk/src/moul/file/localization.py 2007-02-01 00:05:40 UTC (rev 111) +++ pymoul/trunk/src/moul/file/localization.py 2007-02-01 02:39:34 UTC (rev 112) @@ -36,21 +36,14 @@ from moul.log import getLogger LOG = getLogger('moul loc') -def _addList(d, key, value): - lst = d.setdefault(key, []) - lst.append(value) +IGNORE_AGES = [u'OptionsMenu', u'ACA', u'Global', u'KI', u'Heek'] +IGNORE_SETS = [] +IGNORE_ELEMENTS = [] -def _addTree(d, lang, age, setname, element, key): - dlang = d.setdefault(lang, {}) - dage = dlang.setdefault(age, {}) - dset = dage.setdefault(setname, {}) - dset[element] = key - class TranslationRegistry(dict): """Registry for Translation objects""" - __slot__ = ('_bylanguage', '_byage', '_byset', '_byelement', '_tree', - '_ignore_age') + __slot__ = ('_bylanguage', '_byage', '_byset', '_byelement', '_tree') def __new__(cls, *args, **kwargs): self = dict.__new__(cls, *args, **kwargs) @@ -59,7 +52,6 @@ self._byset = {} self._byelement = {} self._tree = {} - self._ignore_age = [u'OptionsMenu', u'ACA', u'Global', u'KI'] return self def register(self, translation): @@ -69,8 +61,12 @@ (translation.fname, str(key))) LOG.error("TranslationRegistry: %s" % msg) raise KeyError(msg) - if translation.age in self._ignore_age: + if translation.age in IGNORE_AGES: return + if translation.set in IGNORE_SETS: + return + if translation.element in IGNORE_ELEMENTS: + return _addList(self._bylanguage, translation.language, key) _addList(self._byage, translation.age, key) _addList(self._byset, translation.set, key) @@ -112,6 +108,21 @@ translationRegistry = TranslationRegistry() registerTranslation = translationRegistry.register +def _addList(d, key, value): + """Utility for dict.setdefault(key, [].append()) + """ + lst = d.setdefault(key, []) + lst.append(value) + +def _addTree(d, lang, age, setname, element, key): + """Utility to create the lang - age - set - element tree + """ + dlang = d.setdefault(lang, {}) + dage = dlang.setdefault(age, {}) + dset = dage.setdefault(setname, {}) + dset[element] = key + + class Translation(unicode): """Translation object Added: pymoul/trunk/src/moul/file/tests/test_directory.py =================================================================== --- pymoul/trunk/src/moul/file/tests/test_directory.py (rev 0) +++ pymoul/trunk/src/moul/file/tests/test_directory.py 2007-02-01 02:39:34 UTC (rev 112) @@ -0,0 +1,36 @@ +# pyMoul - Python interface to Myst Online URU Live +# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> + +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., 59 +# Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +"""moul.file.directory unit tests +""" +__author__ = "Christian Heimes" +__version__ = "$Id$" +__revision__ = "$Revision$" + +import unittest +from doctest import DocTestSuite + +import moul.file.directory + +def test_suite(): + return unittest.TestSuite(( + DocTestSuite('moul.file.directory') + )) + +if __name__ == '__main__': + unittest.main(defaultTest="test_suite") + Property changes on: pymoul/trunk/src/moul/file/tests/test_directory.py ___________________________________________________________________ Name: svn:keywords + Id Revision Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |