[Pymoul-svn] SF.net SVN: pymoul: [137] pymoul/trunk/src/moul
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-02-05 04:09:42
|
Revision: 137
http://pymoul.svn.sourceforge.net/pymoul/?rev=137&view=rev
Author: tiran
Date: 2007-02-04 20:09:41 -0800 (Sun, 04 Feb 2007)
Log Message:
-----------
Removed second implemenation of procesinfo stuff
Added getMoulInstallDir() function and a list of locations for Win32 and Linux
Modified Paths:
--------------
pymoul/trunk/src/moul/config/__init__.py
pymoul/trunk/src/moul/osdependent/__init__.py
pymoul/trunk/src/moul/osdependent/linux/__init__.py
pymoul/trunk/src/moul/osdependent/win32/__init__.py
pymoul/trunk/src/moul/osdependent/win32/winpath.py
Modified: pymoul/trunk/src/moul/config/__init__.py
===================================================================
--- pymoul/trunk/src/moul/config/__init__.py 2007-02-05 03:19:59 UTC (rev 136)
+++ pymoul/trunk/src/moul/config/__init__.py 2007-02-05 04:09:41 UTC (rev 137)
@@ -45,8 +45,8 @@
from moul.osdependent import getMoulUserDataDir
from moul.osdependent import getPyMoulDataDir
+from moul.osdependent import getMoulInstallDir
-
_marker=object()
# configuration
@@ -111,9 +111,7 @@
addSection = _configuration.addSection
listConfig = _configuration.listConfig
-# hard coded for my system
-#setOption('moul', 'installdir', 'D:\\games\\MystOnline')
-setOption('moul', 'installdir', '/home/heimes/dev/pymoul/MystOnline')
+#setOption('moul', 'installdir', '')
## directories
class Directories(object):
@@ -124,7 +122,7 @@
self._config = config
def getMoulInstallDir(self):
- return self._config.getOption('moul.installdir')
+ return getMoulInstallDir()
def getMoulUserDataDir(self):
return getMoulUserDataDir()
Modified: pymoul/trunk/src/moul/osdependent/__init__.py
===================================================================
--- pymoul/trunk/src/moul/osdependent/__init__.py 2007-02-05 03:19:59 UTC (rev 136)
+++ pymoul/trunk/src/moul/osdependent/__init__.py 2007-02-05 04:09:41 UTC (rev 137)
@@ -59,10 +59,13 @@
__POSIX__, __NT__)
# names to import: from moul.osdependent.ID import NAME (as NAME)
-NAMES = ('getMoulUserDataDir',
- ('getPyMoulDataDir', '_getPyMoulDataDir'), # as
- 'startMoul', 'isMoulRunning',
- )
+NAMES = (
+ 'getMoulUserDataDir',
+ 'getMoulInstallDir',
+ ('getPyMoulDataDir', '_getPyMoulDataDir'), # as
+ 'startMoul',
+ 'isMoulRunning',
+ )
_marker = object()
Modified: pymoul/trunk/src/moul/osdependent/linux/__init__.py
===================================================================
--- pymoul/trunk/src/moul/osdependent/linux/__init__.py 2007-02-05 03:19:59 UTC (rev 136)
+++ pymoul/trunk/src/moul/osdependent/linux/__init__.py 2007-02-05 04:09:41 UTC (rev 137)
@@ -23,6 +23,7 @@
import os
from subprocess import Popen
+from moul.osdependent.processinfo import getPidNames
from moul.log import getLogger
@@ -35,6 +36,11 @@
EXEC_NAME = "UruLauncher"
HOME = os.environ['HOME']
PROCESSES = ('urulauncher', 'uruexplorer')
+LOCATIONS = [
+ "%s/dev/pymoul/MystOnline" % HOME,
+ "/media/d/games/MystOnline",
+ "/usr/local/games/MystOnline"
+ ]
def getMoulUserDataDir():
"""Get path of MOUL data directory
@@ -50,6 +56,17 @@
inidir= os.path.join(HOME, '.pymoul')
return inidir
+def getMoulInstallDir():
+ """Get path to MOUL install dir
+ """
+ for path in LOCATIONS:
+ if os.path.isfile(os.path.join(path, EXEC_NAME)):
+ LOG.info("Uru directory found: %s" % path)
+ return path
+ LOG.warning("Uru directory NOT found! Search path was: \n %s" %
+ repr(LOCATIONS))
+ return 'INVALID'
+
def startMoul(installdir, *args, **kwargs):
"""Start MOUL - returns a Popen instance
@@ -63,55 +80,7 @@
def isMoulRunning():
"""Test if MOUL or the launcher is running
"""
- for pid, name in getCurrentPidNames().items():
+ for pid, name in getPidNames().items():
if name.lower() in PROCESSES:
- return name.lower()
+ return pid
return False
-
-# process info
-# based on http://gelb.bcom.at/trac/misc/browser/processinfo
-def getCurrentPids():
- """Returns current process ids
- """
- pids = []
- for fname in os.listdir("/proc"):
- if os.path.isdir(os.path.join("/proc", fname)):
- try:
- pids.append(int(fname))
- except ValueError:
- continue
- return pids
-
-def getCurrentPidDetails():
- """Returns mapping pid -> detailed informations
- """
- mapping = {}
- for pid in getCurrentPids():
- try:
- try:
- # read entiry file to avoid race condition bugs
- fd = open('/proc/%i/status' % pid, 'rb')
- status = fd.read().split('\n')
- finally:
- if fd:
- fd.close()
- except IOError:
- continue
- details = {}
- for line in status:
- try:
- key, value = line.split(':\t')
- except ValueError:
- continue
- details[key.lower()] = value.strip()
- mapping[pid] = details
-
- return mapping
-
-def getCurrentPidNames():
- """Returns mapping pid -> name
- """
- mapping = {}
- for pid, details in getCurrentPidDetails().items():
- mapping[pid] = details.get('name', None)
- return mapping
Modified: pymoul/trunk/src/moul/osdependent/win32/__init__.py
===================================================================
--- pymoul/trunk/src/moul/osdependent/win32/__init__.py 2007-02-05 03:19:59 UTC (rev 136)
+++ pymoul/trunk/src/moul/osdependent/win32/__init__.py 2007-02-05 04:09:41 UTC (rev 137)
@@ -26,8 +26,7 @@
from moul.log import getLogger
from moul.osdependent.processinfo import getPidNames
-from moul.osdependent.win32.winpath import get_appdata as getAppdata
-from moul.osdependent.win32.winpath import get_homedir as getMyDocuments
+from moul.osdependent.win32 import winpath
LOG = getLogger('moul.win')
@@ -37,9 +36,21 @@
# lower case
PROCESSES = ("urulauncher.exe", "uruexplorer.exe")
-MYDOCS = getMyDocuments()
-MYAPPDATA = getAppdata()
+MYDOCS = winpath.getMyDocuments()
+MYAPPDATA = winpath.getAppdata()
+PROGRAMFILES = winpath.getProgramFiles()
+HOME = winpath.getHome()
+DESKTOP = winpath.getHome()
+LOCATIONS = [
+ # my location
+ r"D:\games\MystOnline",
+ r"%s\moul\MystOnline" % DESKTOP,
+ # generic locations
+ r"%s\Myst Online" % PROGRAMFILES,
+ r"%s\GameTap\volumes\games\140000150\data" % PROGRAMFILES,
+ ]
+
def getMoulUserDataDir():
"""Get path of MOUL data directory
@@ -55,6 +66,17 @@
inidir = os.path.join(MYAPPDATA , 'pyMoul')
return inidir
+def getMoulInstallDir():
+ """Get path to MOUL install dir
+ """
+ for path in LOCATIONS:
+ if os.path.isfile(os.path.join(path, EXEC_NAME)):
+ LOG.info("Uru directory found: %s" % path)
+ return path
+ LOG.warning("Uru directory NOT found! Search path was: \n %s" %
+ repr(LOCATIONS))
+ return 'INVALID'
+
def startMoul(installdir, *args, **kwargs):
"""Start MOUL - returns a Popen instance
@@ -70,6 +92,5 @@
"""
for pid, name in getPidNames().items():
if name.lower() in PROCESSES:
- return pid, name.lower()
+ return pid
return False
-
Modified: pymoul/trunk/src/moul/osdependent/win32/winpath.py
===================================================================
--- pymoul/trunk/src/moul/osdependent/win32/winpath.py 2007-02-05 03:19:59 UTC (rev 136)
+++ pymoul/trunk/src/moul/osdependent/win32/winpath.py 2007-02-05 04:09:41 UTC (rev 137)
@@ -27,9 +27,10 @@
__copyright__ = "Python license"
# standard library modules
-import _winreg, os
+import _winreg
+import os
+import re
-
SHELL_FOLDERS = \
r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
USER_SHELL_FOLDERS = \
@@ -41,20 +42,14 @@
def _substenv(m):
return os.environ.get(m.group(1), m.group(0))
-_env_rx = None
+_env_rx = re.compile(r'%([^|<>=^%]+)%')
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):
@@ -63,7 +58,6 @@
Environment variables in values of type REG_EXPAND_SZ are expanded
if possible.
"""
-
key = _winreg.OpenKey(key, subkey)
try:
ret = _winreg.QueryValueEx(key, name)
@@ -78,46 +72,47 @@
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."""
-
+def getAppdata():
+ """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."""
+def getCommonShellfolders():
+ """Return mapping of shell folder names (all users) to paths.
+ """
+ return getShellfolders(branch=HKLM)
- return get_shellfolders(branch=HKLM)
+def getMyDocuments():
+ """Return path to user home directory, i.e. 'My Files'.
+ """
+ return _get_reg_user_value(SHELL_FOLDERS, 'Personal')
-def get_homedir():
- """Return path to user home directory, i.e. 'My Files'."""
+def getDesktop():
+ """Return path to desktop.
+ """
+ return _get_reg_user_value(SHELL_FOLDERS, 'Desktop')
- return _get_reg_user_value(SHELL_FOLDERS, 'Personal')
-
-def get_sharedconf(prog, *args):
+def getSharedconf(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):
+def getShellfolders(branch=HKCU, key=SHELL_FOLDERS):
"""Return mapping of shell folder names (current user) to paths."""
-
key = _winreg.OpenKey(branch, key)
folders = {}
i = 0
@@ -134,7 +129,7 @@
key.Close()
return folders
-def get_userconf(vendor, prog, *args):
+def getUserconf(vendor, prog, *args):
"""Return path to user configuration data for 'prog' from 'vendor'.
Additional arguments are appended via os.path.join(), e.g.
@@ -142,10 +137,19 @@
optionsfn = get_userconf("ACME Soft", "Exploder", "Options.xml")
"""
+ return os.path.join(getAppdata(), vendor, prog, *args)
- return os.path.join(get_appdata(), vendor, prog, *args)
+def getWindir():
+ """Convenience function to get path to windows installation directory.
+ """
+ return unicode(os.environ["WINDIR"])
-def get_windir():
- """Convenience function to get path to windows installation directory."""
+def getProgramFiles():
+ """Convenience function to get path to program files directory.
+ """
+ return unicode(os.environ["PROGRAMFILES"])
- return unicode(os.environ["WINDIR"])
+def getHome():
+ """Convenience function to get path to home directory.
+ """
+ return unicode(os.path.expanduser("~"))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|