[Pymoul-svn] SF.net SVN: pymoul: [59] pymoul/trunk/src/moul
Status: Alpha
Brought to you by:
tiran
From: <ti...@us...> - 2007-01-23 13:02:29
|
Revision: 59 http://pymoul.svn.sourceforge.net/pymoul/?rev=59&view=rev Author: tiran Date: 2007-01-23 05:02:21 -0800 (Tue, 23 Jan 2007) Log Message: ----------- Configuration cleanup Moved all os dependent stuff to the right directory Modified Paths: -------------- pymoul/trunk/src/moul/config/__init__.py pymoul/trunk/src/moul/file/localization.py pymoul/trunk/src/moul/file/plasmalog.py pymoul/trunk/src/moul/osdependent/__init__.py pymoul/trunk/src/moul/osdependent/darwin/__init__.py pymoul/trunk/src/moul/osdependent/linux/__init__.py pymoul/trunk/src/moul/osdependent/win32/__init__.py pymoul/trunk/src/moul/qt/ui/mainwindow.py Added Paths: ----------- pymoul/trunk/src/moul/config/tests/test_config.py pymoul/trunk/src/moul/osdependent/win32/registry.py pymoul/trunk/src/moul/osdependent/win32/winpath.py Removed Paths: ------------- pymoul/trunk/src/moul/config/darwin.py pymoul/trunk/src/moul/config/linux.py pymoul/trunk/src/moul/config/win32.py Modified: pymoul/trunk/src/moul/config/__init__.py =================================================================== --- pymoul/trunk/src/moul/config/__init__.py 2007-01-23 11:06:58 UTC (rev 58) +++ pymoul/trunk/src/moul/config/__init__.py 2007-01-23 13:02:21 UTC (rev 59) @@ -34,23 +34,23 @@ _marker=object() # XXX: what about cygwin, bsd and others? if __WIN32__: - from moul.config.win32 import ( + from moul.osdependent.win32 import ( getMoulUserDataDir, - getPyMoulIniLocation, + getPyMoulIniDir, _startMOUL, EXEC_NAME ) elif __LINUX__: - from moul.config.linux import ( + from moul.osdependent.linux import ( getMoulUserDataDir, - getPyMoulIniLocation, + getPyMoulIniDir, _startMOUL, EXEC_NAME ) elif __MACOSX__: - from moul.config.darwin import ( + from moul.osdependent.darwin import ( getMoulUserDataDir, - getPyMoulIniLocation, + getPyMoulIniDir, _startMOUL, EXEC_NAME ) @@ -58,95 +58,137 @@ raise RuntimeError('platform %s not supported' % sys.platform) ## configuration -_configuration = { - 'moul' : {} - } -def getConfigOption(section, name=None, default=_marker): - """Get configuration option - """ - global _configuration - if name is None: - section, name = section.split('.') - sec = _configuration.get(section, default) - if sec is not default: - value = sec.get(name, default) - if value is default and default is _marker: - raise KeyError("%s.%s" % (section, name)) - else: - return value - elif default is _marker: - raise KeyError(section) -def setConfigOption(section, name=None, value=_marker): - """Set configuratin option - """ - global _configuration - if value is _marker: - raise ValueError("No value applied") - if name is None: - section, name = section.split('.') - sec = _configuration[section] - if value is None: - del sec[name] - else: - sec[name] = value +class Configuration(dict): + def __new__(cls, *args, **kwargs): + self = dict.__new__(cls, *args, **kwargs) + self.addSection('moul') + return self -def addConfigSection(section): - """Add a new configuration section - """ - global _configuration - return _configuration.setdefault(section, {}) + def getOption(self, section, name=None, default=_marker): + """Get configuration option + """ + if name is None: + section, name = section.split('.') + sec = self.get(section, default) + if sec is not default: + value = sec.get(name, default) + if value is default and default is _marker: + raise KeyError("%s.%s" % (section, name)) + else: + return value + elif default is _marker: + raise KeyError(section) + + def setOption(self, section, name=None, value=_marker): + """Set configuratin option + """ + if value is _marker: + raise ValueError("No value applied") + if name is None: + section, name = section.split('.') + sec = self[section] + if value is None: + del sec[name] + else: + sec[name] = value + + def addSection(self, section): + """Add a new configuration section + """ + return self.setdefault(section, {}) + + def listConfig(self): + """List + + >>> cfg = listConfig() + >>> len(cfg) > 0 + True + >>> type(cfg) + <type 'dict'> + """ + out = {} + for sec, names in self.items(): + for name, value in names.items(): + fullname = "%s.%s" % (sec, name) + out[fullname] = value + return out -def listConfig(): - """List - """ - global _configuration - out = {} - for sec, names in _configuration.items(): - for name, value in names.items(): - fullname = "%s.%s" % (sec, name) - out[fullname] = value - return out +_configuration = Configuration() +getOption = _configuration.getOption +setOption = _configuration.setOption +addSection = _configuration.addSection +listConfig = _configuration.listConfig -#setConfigOption('moul', 'installdir', 'D:\\games\\MystOnline') +# hard coded for my system +setOption('moul', 'installdir', 'D:\\games\\MystOnline') ## directories -def getMoulInstallDir(): - return getConfigOption('moul.installdir') +class Directories(object): + + _dirmapping = { + 'install' : "%(installdir)s", + 'loc' : "%(installdir)s/dat", + 'dat' : "%(installdir)s/dat", + 'sound' : "%(installdir)s/sfx", + 'soundwav' : "%(installdir)s/sfx/streamingCache", + 'video' : "%(installdir)s/avi", + + 'userdata' : "%(datadir)s", + 'log' : "%(datadir)s/Log", + 'kiimages' : "%(datadir)s/KIimages", + 'avatars' : "%(datadir)s/Avatars", + 'chatlogs' : "%(datadir)s/chatlogs", + 'ini' : "%(datadir)s/init", + + 'pymoul.ini' : "%(pymouldir)s/pymoul.ini", + } + + def __init__(self, config): + self._cache = {} + self._config = config + + def clearCache(self): + self._cache.clear() -def startMOUL(*args): - """Start MOUL wrapper - """ - installdir = getMoulInstallDir() - _startMOUL(installdir, *args) + def getMoulInstallDir(self): + return self._config.getOption('moul.installdir') + + def getMoulUserDataDir(self): + return getMoulUserDataDir() -# name -> (callable, list) -_mapping = { - 'install' : (getMoulInstallDir, ()), - 'loc' : (getMoulInstallDir, ('dat', )), - 'dat' : (getMoulInstallDir, ('dat', )), - 'sound' : (getMoulInstallDir, ('sfx', )), - 'soundwav' : (getMoulInstallDir, ('sfx', 'streamingCache', )), - 'video' : (getMoulInstallDir, ('avi', )), + def getPyMoulIniDir(self): + return getPyMoulIniDir() - 'userdata' : (getMoulUserDataDir, ()), - 'log' : (getMoulUserDataDir, ('Log', )), - 'kiimages' : (getMoulUserDataDir, ('KIimages', )), - 'avatars' : (getMoulUserDataDir, ('Avatars', )), - 'chatlogs' : (getMoulUserDataDir, ('chatlogs', )), - 'ini' : (getMoulUserDataDir, ('init', )), + def lookupDir(self, name): + """Lookup MOUL directory + """ + cached = self._cache.get(name, None) + if cached: + return cached + path = self._dirmapping.get(name) + path = path.replace('/', os.sep) + map = {'installdir' : self.getMoulInstallDir(), + 'datadir' : self.getMoulUserDataDir(), + 'pymouldir' : self.getPyMoulIniDir(), + } + fullpath = path % map + #self._cache[name] = fullpath + return fullpath + + def listDirs(self): + """List all MOUL dirs + + >>> dirs = listDirs() + >>> len(dirs) + 13 + >>> type(dirs) + <type 'dict'> + """ + return dict([(name, self.lookupDir(name)) for name in self._dirmapping]) - 'pymoul.ini' : (getPyMoulIniLocation, ()), - } - -def getMoulDir(name): - """Lookup MOUL directory - """ - callable, args = _mapping.get(name) - return os.path.join(callable(), *args) - -def listMoulDirs(): - """List all MOUL dirs - """ - return dict([(name, getMoulDir(name)) for name in _mapping]) +_directories = Directories(_configuration) +clearCache = _directories.clearCache +lookupDir = _directories.lookupDir +listDirs = _directories.listDirs Deleted: pymoul/trunk/src/moul/config/darwin.py =================================================================== --- pymoul/trunk/src/moul/config/darwin.py 2007-01-23 11:06:58 UTC (rev 58) +++ pymoul/trunk/src/moul/config/darwin.py 2007-01-23 13:02:21 UTC (rev 59) @@ -1,57 +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 -# -"""Darwin (Mac OS X) configuration for pyMoul - -XXX: untested! -""" -__author__ = "Christian Heimes" -__version__ = "$Id$" -__revision__ = "$Revision$" - -import os -from moul.log import LOG -LOG.warning('Darwin/Mac support is not tested') - -MOUL_DIR = "Uru Live" -INI_FILE = ('pyMoul', 'pymoul.ini') -EXEC_NAME = "UruLauncher" -HOME = os.environ['HOME'] - -def getMoulUserDataDir(): - """Get path of MOUL data directory - - The MOUL data directory contains log files, chatlogs, KI images and many - more things. - """ - moul_data = os.path.join(HOME, MOUL_DIR) - -def getPyMoulIniLocation(): - """Get path to the pyMoul ini file - """ - ini_file = os.path.join(HOME, *INI_FILE) - return ini_file - -def _startMOUL(installdir, *args): - """Start MOUL - """ - # P_DETACH is similar to P_NOWAIT, but the new process is detached from - # the console of the calling process. - mode = os.P_DETACH - path = os.path.join(installdir, EXEC_NAME) - args = (EXEC_NAME,) + args - return os.spawnv(mode, path, args) Deleted: pymoul/trunk/src/moul/config/linux.py =================================================================== --- pymoul/trunk/src/moul/config/linux.py 2007-01-23 11:06:58 UTC (rev 58) +++ pymoul/trunk/src/moul/config/linux.py 2007-01-23 13:02:21 UTC (rev 59) @@ -1,57 +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 -# -"""Linux configuration for pyMoul - -XXX: untested! -""" -__author__ = "Christian Heimes" -__version__ = "$Id$" -__revision__ = "$Revision$" - -import os -from moul.log import LOG -LOG.warning('Linux support is not tested') - -MOUL_DIR = "Uru Live" -INI_FILE = ('pyMoul', 'pymoul.ini') -EXEC_NAME = "UruLauncher" -HOME = os.environ['HOME'] - -def getMoulUserDataDir(): - """Get path of MOUL data directory - - The MOUL data directory contains log files, chatlogs, KI images and many - more things. - """ - moul_data = os.path.join(HOME, MOUL_DIR) - -def getPyMoulIniLocation(): - """Get path to the pyMoul ini file - """ - ini_file = os.path.join(HOME, *INI_FILE) - return ini_file - -def _startMOUL(installdir, *args): - """Start MOUL - """ - # P_DETACH is similar to P_NOWAIT, but the new process is detached from - # the console of the calling process. - mode = os.P_DETACH - path = os.path.join(installdir, EXEC_NAME) - args = (EXEC_NAME,) + args - return os.spawnv(mode, path, args) Added: pymoul/trunk/src/moul/config/tests/test_config.py =================================================================== --- pymoul/trunk/src/moul/config/tests/test_config.py (rev 0) +++ pymoul/trunk/src/moul/config/tests/test_config.py 2007-01-23 13:02:21 UTC (rev 59) @@ -0,0 +1,35 @@ +# 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.config unit tests +""" +__author__ = "Christian Heimes" +__version__ = "$Id$" +__revision__ = "$Revision$" + +import unittest +from doctest import DocTestSuite + +import moul.config + +def test_suite(): + return unittest.TestSuite(( + DocTestSuite('moul.config') + )) + +if __name__ == '__main__': + unittest.main(defaultTest="test_suite") Property changes on: pymoul/trunk/src/moul/config/tests/test_config.py ___________________________________________________________________ Name: svn:eol-style + native Deleted: pymoul/trunk/src/moul/config/win32.py =================================================================== --- pymoul/trunk/src/moul/config/win32.py 2007-01-23 11:06:58 UTC (rev 58) +++ pymoul/trunk/src/moul/config/win32.py 2007-01-23 13:02:21 UTC (rev 59) @@ -1,67 +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 -# -"""Win32 configuration for pyMoul -""" -__author__ = "Christian Heimes" -__version__ = "$Id$" -__revision__ = "$Revision$" - -import os -from miniwinshell import my_documents -from miniwinshell import application_data -#from win32com.directsound import directsound - -MOUL_DIR = "Uru Live" -INI_FILE = ('pyMoul', 'pymoul.ini') -EXEC_NAME = "UruLauncher.exe" - -def getMoulUserDataDir(): - """Get path of MOUL data directory - - The MOUL data directory contains log files, chatlogs, KI images and many - more things. - """ - mydoc = my_documents() - moul_data = os.path.join(mydoc, MOUL_DIR) - return moul_data - -def getPyMoulIniLocation(): - """Get path to the pyMoul ini file - """ - app_data = application_data() - ini_file = os.path.join(app_data, *INI_FILE) - return ini_file - -def _startMOUL(installdir, *args): - """Start MOUL - """ - # P_DETACH is similar to P_NOWAIT, but the new process is detached from - # the console of the calling process. - mode = os.P_DETACH - path = os.path.join(installdir, EXEC_NAME) - args = (EXEC_NAME,) + args - return os.spawnv(mode, path, args) - -#def enumSoundDevices(): -# """ -# """ -# names = [] -# for iid, name, driver in directsound.DirectSoundEnumerate(): -# if iid is not None: -# names.append(name) -# return names Modified: pymoul/trunk/src/moul/file/localization.py =================================================================== --- pymoul/trunk/src/moul/file/localization.py 2007-01-23 11:06:58 UTC (rev 58) +++ pymoul/trunk/src/moul/file/localization.py 2007-01-23 13:02:21 UTC (rev 59) @@ -33,7 +33,6 @@ from xml.sax import make_parser from xml.sax.handler import feature_namespaces -from moul.config import getMoulDir from moul.log import LOG def _add(d, key, value): @@ -179,7 +178,7 @@ parser.setContentHandler(dh) parser.parse(fd) -def parseLocDirectory(path=None, clear=False): +def parseLocDirectory(path, clear=False): """Parse all loc files in a directory """ files = [] @@ -188,8 +187,6 @@ if clear: translationRegistry.clear() - if path is None: - path = getMoulDir('loc') if not os.path.isdir(path): raise IOError("invalid path %s" % path) @@ -210,10 +207,3 @@ files.append(fname) return {'files' : files, 'errors' : errors } - -def _test(): - path = getMoulDir('loc') - parseDirectory(path) - -if __name__ == '__main__': - _test() Modified: pymoul/trunk/src/moul/file/plasmalog.py =================================================================== --- pymoul/trunk/src/moul/file/plasmalog.py 2007-01-23 11:06:58 UTC (rev 58) +++ pymoul/trunk/src/moul/file/plasmalog.py 2007-01-23 13:02:21 UTC (rev 59) @@ -27,8 +27,6 @@ import zipfile import re -from moul.config import getMoulDir -from moul.config import getConfigOption from moul.crypt.elf import decryptElf PLASMA_LOG = "plasmalog.txt" @@ -54,18 +52,11 @@ return False return getTimeStamp(pl) -def zipLogDir(logdir=None, destdir=None, remove=_marker): +def zipLogDir(logdir, destdir, remove): """Zip all log files This function also zips subdirectories. """ - if logdir is None: - logdir = getMoulDir('log') - if destdir is None: - destdir = getMoulDir('userdata') - if remove is _marker: - remove = getConfigOption('moul', 'removelogs', default=False) - stored_dirs = [] for root, dirs, files in os.walk(logdir): @@ -92,14 +83,11 @@ return stored_dirs -def removeLogs(logdir=None): +def removeLogs(logdir): """Removes log directories The removeLogs function removes only files considered as safe """ - if logdir is None: - logdir = getMoulDir('log') - for root, dirs, files in os.walk(logdir, topdown=False): for name in files: if RE_SAFEXT.search(name): Modified: pymoul/trunk/src/moul/osdependent/__init__.py =================================================================== --- pymoul/trunk/src/moul/osdependent/__init__.py 2007-01-23 11:06:58 UTC (rev 58) +++ pymoul/trunk/src/moul/osdependent/__init__.py 2007-01-23 13:02:21 UTC (rev 59) @@ -1,22 +1,22 @@ -# 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 -# -""" -""" -__author__ = "Christian Heimes" -__version__ = "$Id$" -__revision__ = "$Revision$" +# 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 +# +""" +""" +__author__ = "Christian Heimes" +__version__ = "$Id$" +__revision__ = "$Revision$" Modified: pymoul/trunk/src/moul/osdependent/darwin/__init__.py =================================================================== --- pymoul/trunk/src/moul/osdependent/darwin/__init__.py 2007-01-23 11:06:58 UTC (rev 58) +++ pymoul/trunk/src/moul/osdependent/darwin/__init__.py 2007-01-23 13:02:21 UTC (rev 59) @@ -1,23 +1,54 @@ -# 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 -# -""" -""" -__author__ = "Christian Heimes" -__version__ = "$Id$" -__revision__ = "$Revision$" - +# 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.osdependent.darwin +""" +__author__ = "Christian Heimes" +__version__ = "$Id$" +__revision__ = "$Revision$" + +import os +from moul.log import LOG +LOG.warning('Darwin/Mac support is not tested') + +MOUL_DIR = "Uru Live" +EXEC_NAME = "UruLauncher" +HOME = os.environ['HOME'] + +def getMoulUserDataDir(): + """Get path of MOUL data directory + + The MOUL data directory contains log files, chatlogs, KI images and many + more things. + """ + moul_data = os.path.join(HOME, MOUL_DIR) + +def getPyMoulIniDir(): + """Get path to the pyMoul ini directory + """ + inidir= os.path.join(HOME, '.pymoul') + return inidir + +def _startMOUL(installdir, *args): + """Start MOUL + """ + # P_DETACH is similar to P_NOWAIT, but the new process is detached from + # the console of the calling process. + mode = os.P_DETACH + path = os.path.join(installdir, EXEC_NAME) + args = (EXEC_NAME,) + args + return os.spawnv(mode, path, args) Modified: pymoul/trunk/src/moul/osdependent/linux/__init__.py =================================================================== --- pymoul/trunk/src/moul/osdependent/linux/__init__.py 2007-01-23 11:06:58 UTC (rev 58) +++ pymoul/trunk/src/moul/osdependent/linux/__init__.py 2007-01-23 13:02:21 UTC (rev 59) @@ -1,23 +1,55 @@ -# 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 -# -""" -""" -__author__ = "Christian Heimes" -__version__ = "$Id$" -__revision__ = "$Revision$" - +# 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.osdependent.linux +""" +__author__ = "Christian Heimes" +__version__ = "$Id$" +__revision__ = "$Revision$" + +import os +from moul.log import LOG +LOG.warning('Linux support is not tested') + +MOUL_DIR = "Uru Live" +INI_FILE = ('pyMoul', 'pymoul.ini') +EXEC_NAME = "UruLauncher" +HOME = os.environ['HOME'] + +def getMoulUserDataDir(): + """Get path of MOUL data directory + + The MOUL data directory contains log files, chatlogs, KI images and many + more things. + """ + moul_data = os.path.join(HOME, MOUL_DIR) + +def getPyMoulIniDir(): + """Get path to the pyMoul ini directory + """ + inidir= os.path.join(HOME, '.pymoul') + return inidir + +def _startMOUL(installdir, *args): + """Start MOUL + """ + # P_DETACH is similar to P_NOWAIT, but the new process is detached from + # the console of the calling process. + mode = os.P_DETACH + path = os.path.join(installdir, EXEC_NAME) + args = (EXEC_NAME,) + args + return os.spawnv(mode, path, args) Modified: pymoul/trunk/src/moul/osdependent/win32/__init__.py =================================================================== --- pymoul/trunk/src/moul/osdependent/win32/__init__.py 2007-01-23 11:06:58 UTC (rev 58) +++ pymoul/trunk/src/moul/osdependent/win32/__init__.py 2007-01-23 13:02:21 UTC (rev 59) @@ -1,23 +1,69 @@ -# 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 -# -""" -""" -__author__ = "Christian Heimes" -__version__ = "$Id$" -__revision__ = "$Revision$" - +# 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.osdependent.win32 +""" +__author__ = "Christian Heimes" +__version__ = "$Id$" +__revision__ = "$Revision$" + +import os +#from moul.osdependent.win32.miniwinshell import my_documents +#from moul.osdependent.win32.miniwinshell import application_data +#from win32com.directsound import directsound +from moul.osdependent.win32.winpath import get_homedir +from moul.osdependent.win32.winpath import get_appdata + + +MOUL_DIR = "Uru Live" +EXEC_NAME = "UruLauncher.exe" + +def getMoulUserDataDir(): + """Get path of MOUL data directory + + The MOUL data directory contains log files, chatlogs, KI images and many + more things. + """ + mydoc = get_homedir() + moul_data = os.path.join(mydoc, MOUL_DIR) + return moul_data + +def getPyMoulIniDir(): + """Get path to the pyMoul ini file + """ + app_data = get_appdata() + inidir = os.path.join(app_data, 'pyMoul') + return inidir + +def _startMOUL(installdir, *args): + """Start MOUL + """ + # P_DETACH is similar to P_NOWAIT, but the new process is detached from + # the console of the calling process. + mode = os.P_DETACH + path = os.path.join(installdir, EXEC_NAME) + args = (EXEC_NAME,) + args + return os.spawnv(mode, path, args) + +#def enumSoundDevices(): +# """ +# """ +# names = [] +# for iid, name, driver in directsound.DirectSoundEnumerate(): +# if iid is not None: +# names.append(name) +# return names Added: pymoul/trunk/src/moul/osdependent/win32/registry.py =================================================================== --- pymoul/trunk/src/moul/osdependent/win32/registry.py (rev 0) +++ pymoul/trunk/src/moul/osdependent/win32/registry.py 2007-01-23 13:02:21 UTC (rev 59) @@ -0,0 +1,69 @@ +"""Based on http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146305 +""" +import _winreg as wreg +#import cPickle as pickle + +class WindowsRegistry: + + def __init__(self, company="spirito GmbH", project="TestProg", write=1): + """ + handle registry access + """ + self.write = write + self.company = company + self.project = project + self.keyname = "Software\\%s\\%s" % (self.company, self.project) + + try: + self.key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, self.keyname) + except: + if self.write: + self.key = wreg.CreateKey(wreg.HKEY_CURRENT_USER, self.keyname) + + def set(self, name, value): + " set value in registry " + if not self.write: + raise Exception, "registry is read only" + wreg.SetValue(self.key, name, wreg.REG_SZ,str(value)) + +# def pset(self, name, value): +# " set using pickle " +# self.set(name, pickle.dumps(value)) + + def get(self, name): + " get value out of registry " + return wreg.QueryValue(self.key, name) + + def delkey(self, name): + """Delete a key + """ + if not self.write: + raise Exception, "registry is read only" + return wreg.DeleteKey(self.key, name) + + def delvalue(self, name): + """Delete a value + """ + if not self.write: + raise Exception, "registry is read only" + return wreg.ValueKey(self.key, name) + +# def pget(self, name): +# " get using pickle " +# return pickle.loads(self.get(name)) + + def close(self): + " close the key finally " + self.key.Close() + + def __del__(self): + self.close() + + +if __name__=="__main__": + r = WindowsRegistry(project="MyTestProg", write=1) + r.set("test", "hello string data") + r.pset("testp", 123) + print r.get("test") + print r.pget("testp") + Property changes on: pymoul/trunk/src/moul/osdependent/win32/registry.py ___________________________________________________________________ Name: svn:eol-style + native Added: pymoul/trunk/src/moul/osdependent/win32/winpath.py =================================================================== --- pymoul/trunk/src/moul/osdependent/win32/winpath.py (rev 0) +++ pymoul/trunk/src/moul/osdependent/win32/winpath.py 2007-01-23 13:02:21 UTC (rev 59) @@ -0,0 +1,150 @@ +"""Functions for getting system/language/user dependent paths on windows. + +All path names returned by the functions of this module are unicode strings. + +From http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473846/ +""" + +__all__ = [ + 'HKCU', 'HKLM', + 'SHELL_FOLDERS', + 'USER_SHELL_FOLDERS', + 'expandvars', + 'get_appdata', + 'get_common_shellfolders', + 'get_homedir', + 'get_sharedconf', + 'get_shellfolders', + 'get_userconf', + 'get_windir' +] + +__module__ = "winpaths" +__author__ = "Christopher Arndt" +__version__ = "0.1" +__revision__ = "$Rev$" +__date__ = "$Date$" +__copyright__ = "Python license" + +# standard library modules +import _winreg, os + +SHELL_FOLDERS = \ + r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' +USER_SHELL_FOLDERS = \ + r'Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' +HKCU = _winreg.HKEY_CURRENT_USER +HKLM = _winreg.HKEY_LOCAL_MACHINE + +# helper functions +def _substenv(m): + return os.environ.get(m.group(1), m.group(0)) + +_env_rx = None +def expandvars(s): + """Expand environment variables of form %var%. + + Unknown variables are left unchanged. + """ + + global _env_rx + + if '%' not in s: + return s + if _env_rx is None: + import re + _env_rx = re.compile(r'%([^|<>=^%]+)%') + return _env_rx.sub(_substenv, s) + +def _get_reg_value(key, subkey, name): + """Return registry value specified by key, subkey, and name. + + Environment variables in values of type REG_EXPAND_SZ are expanded + if possible. + """ + + key = _winreg.OpenKey(key, subkey) + try: + ret = _winreg.QueryValueEx(key, name) + except WindowsError: + return None + else: + key.Close() + if ret[1] == _winreg.REG_EXPAND_SZ: + return expandvars(ret[0]) + else: + return ret[0] + +def _get_reg_user_value(key, name): + """Return a windows registry value from the CURRENT_USER branch.""" + + return _get_reg_value(HKCU, key, name) + +def _get_reg_machine_value(key, name): + """Return a windows registry value from the LOCAL_MACHINE branch.""" + + return _get_reg_value(HKLM, key, name) + +# public functions +def get_appdata(): + """Return path of directory where apps should store user specific data.""" + + return _get_reg_user_value(SHELL_FOLDERS, 'AppData') + +def get_common_shellfolders(): + """Return mapping of shell folder names (all users) to paths.""" + + return get_shellfolders(branch=HKLM) + +def get_homedir(): + """Return path to user home directory, i.e. 'My Files'.""" + + return _get_reg_user_value(SHELL_FOLDERS, 'Personal') + +def get_sharedconf(prog, *args): + """Return path to shared configuration data for 'prog' from 'vendor'. + + Additional arguments are appended via os.path.join(). + + See also: get_user_conf() + """ + + return os.path.join( + _get_reg_machine_value(SHELL_FOLDERS, 'Common AppData'), + vendor, prog, *args + ) + +def get_shellfolders(branch=HKCU, key=SHELL_FOLDERS): + """Return mapping of shell folder names (current user) to paths.""" + + key = _winreg.OpenKey(branch, key) + folders = {} + i = 0 + while True: + try: + ret = _winreg.EnumValue(key, i) + if ret[2] == _winreg.REG_EXPAND_SZ: + folders[ret[0]] = expandvars(ret[1]) + else: + folders[ret[0]] = ret[1] + except WindowsError: + break + i +=1 + key.Close() + return folders + +def get_userconf(vendor, prog, *args): + """Return path to user configuration data for 'prog' from 'vendor'. + + Additional arguments are appended via os.path.join(), e.g. + use like this: + + optionsfn = get_userconf("ACME Soft", "Exploder", "Options.xml") + """ + + return os.path.join(get_appdata(), vendor, prog, *args) + +def get_windir(): + """Convenience function to get path to windows installation directory.""" + + return unicode(os.environ["WINDIR"]) Property changes on: pymoul/trunk/src/moul/osdependent/win32/winpath.py ___________________________________________________________________ Name: svn:eol-style + native Modified: pymoul/trunk/src/moul/qt/ui/mainwindow.py =================================================================== --- pymoul/trunk/src/moul/qt/ui/mainwindow.py 2007-01-23 11:06:58 UTC (rev 58) +++ pymoul/trunk/src/moul/qt/ui/mainwindow.py 2007-01-23 13:02:21 UTC (rev 59) @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'src\moul\qt\ui\mainwindow.ui' # -# Created: Fri Jan 19 17:32:22 2007 +# Created: Fri Jan 19 17:47:21 2007 # by: PyQt4 UI code generator 4.1.1 # # WARNING! All changes made in this file will be lost! This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |