[Pymoul-svn] SF.net SVN: pymoul: [81] pymoul/trunk/src/moul
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-01-26 14:55:56
|
Revision: 81
http://pymoul.svn.sourceforge.net/pymoul/?rev=81&view=rev
Author: tiran
Date: 2007-01-26 06:55:52 -0800 (Fri, 26 Jan 2007)
Log Message:
-----------
Added isMoulRunning stuff
Enhanced startMoul
Added some (disabled) tests for start and is running
Modified Paths:
--------------
pymoul/trunk/src/moul/config/__init__.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
Modified: pymoul/trunk/src/moul/config/__init__.py
===================================================================
--- pymoul/trunk/src/moul/config/__init__.py 2007-01-26 14:17:50 UTC (rev 80)
+++ pymoul/trunk/src/moul/config/__init__.py 2007-01-26 14:55:52 UTC (rev 81)
@@ -16,6 +16,30 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""Configuration package
+
+>>> from moul.osdependent import startMoul
+>>> from moul.osdependent import isMoulRunning
+>>> installDir = lookupDir('install')
+>>> from time import sleep
+
+Start MOUL
+#>>> popen = startMoul(installDir)
+
+Wait a bit before testing the rest
+#>>> sleep(0.2)
+#>>> bool(popen.pid)
+True
+#>>> popen.poll()
+#>>> popen.returncode is None
+True
+
+Check the running tester
+#>>> isMoulRunning()
+u'urulauncher.exe'
+
+#>>> popen.wait()
+#>>> popen.returncode
+#0
"""
import os
Modified: pymoul/trunk/src/moul/osdependent/__init__.py
===================================================================
--- pymoul/trunk/src/moul/osdependent/__init__.py 2007-01-26 14:17:50 UTC (rev 80)
+++ pymoul/trunk/src/moul/osdependent/__init__.py 2007-01-26 14:55:52 UTC (rev 81)
@@ -53,7 +53,7 @@
# names to import: from moul.osdependent.ID import NAME (as NAME)
NAMES = ('getMoulUserDataDir',
('getPyMoulDataDir', '_getPyMoulDataDir'), # as
- '_startMOUL', 'EXEC_NAME',
+ 'startMoul', 'isMoulRunning',
'getCurrentPids', 'getCurrentPidNames',
)
Modified: pymoul/trunk/src/moul/osdependent/darwin/__init__.py
===================================================================
--- pymoul/trunk/src/moul/osdependent/darwin/__init__.py 2007-01-26 14:17:50 UTC (rev 80)
+++ pymoul/trunk/src/moul/osdependent/darwin/__init__.py 2007-01-26 14:55:52 UTC (rev 81)
@@ -22,9 +22,12 @@
__revision__ = "$Revision$"
import os
-from moul.log import LOG
-LOG.warning('Darwin/Mac support is not tested')
+from subprocess import Popen
+from moul.log import getLogger
+LOG = getLogger('moul.darwin')
+LOG.critical('Darwin/Mac support is not tested')
+
MOUL_DIR = "Uru Live"
EXEC_NAME = "UruLauncher"
HOME = os.environ['HOME']
@@ -43,12 +46,12 @@
inidir= os.path.join(HOME, '.pymoul')
return inidir
-def _startMOUL(installdir, *args):
- """Start MOUL
+def startMoul(installdir, *args, **kwargs):
+ """Start MOUL - returns a Popen instance
+
+ args are applied to the program while kwargs are applied to
+ subprocess.Popen()
"""
- # 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)
+ args = ' '.join(args)
+ return Popen("%s %s" % (path, args), cwd=installdir, **kwargs)
Modified: pymoul/trunk/src/moul/osdependent/linux/__init__.py
===================================================================
--- pymoul/trunk/src/moul/osdependent/linux/__init__.py 2007-01-26 14:17:50 UTC (rev 80)
+++ pymoul/trunk/src/moul/osdependent/linux/__init__.py 2007-01-26 14:55:52 UTC (rev 81)
@@ -22,13 +22,17 @@
__revision__ = "$Revision$"
import os
-from moul.log import LOG
-LOG.warning('Linux support is not tested')
+from subprocess import Popen
+from moul.log import getLogger
+LOG = getLogger('moul.linux')
+LOG.critical('Darwin/Mac support is not tested')
+
MOUL_DIR = "Uru Live"
INI_FILE = ('pyMoul', 'pymoul.ini')
EXEC_NAME = "UruLauncher"
HOME = os.environ['HOME']
+PROCESSES = ('urulauncher', 'uruexplorer')
def getMoulUserDataDir():
"""Get path of MOUL data directory
@@ -44,19 +48,26 @@
inidir= os.path.join(HOME, '.pymoul')
return inidir
-def _startMOUL(installdir, *args):
- """Start MOUL
+def startMoul(installdir, *args, **kwargs):
+ """Start MOUL - returns a Popen instance
+
+ args are applied to the program while kwargs are applied to
+ subprocess.Popen()
"""
- # 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)
+ args = ' '.join(args)
+ return Popen("%s %s" % (path, args), cwd=installdir, **kwargs)
+def isMoulRunning():
+ """Test if MOUL or the launcher is running
+ """
+ for pid, name in getCurrentPidNames().items():
+ if name.lower() in PROCESSES:
+ return name.lower()
+ return False
+
# process info
# based on http://gelb.bcom.at/trac/misc/browser/processinfo
-
def getCurrentPids():
"""Returns current process ids
"""
Modified: pymoul/trunk/src/moul/osdependent/win32/__init__.py
===================================================================
--- pymoul/trunk/src/moul/osdependent/win32/__init__.py 2007-01-26 14:17:50 UTC (rev 80)
+++ pymoul/trunk/src/moul/osdependent/win32/__init__.py 2007-01-26 14:55:52 UTC (rev 81)
@@ -22,18 +22,25 @@
__revision__ = "$Revision$"
import os
+from subprocess import Popen
+
from moul.osdependent.win32.miniwinshell import my_documents as getMyDocuments
from moul.osdependent.win32.miniwinshell import application_data as getAppdata
#from moul.osdependent.win32.winpath import get_homedir as getMyDocuments
#from moul.osdependent.win32.winpath import get_appdata as getAppdata
from moul.osdependent.win32 import wmi
+from moul.log import getLogger
+LOG = getLogger('moul.win')
+
MOUL_DIR = "Uru Live"
-EXEC_NAME = "UruLauncher.exe"
+EXEC_NAME = "UruLauncher.exe"
+# lower case
+PROCESSES = ("urulauncher.exe", "uruexplorer.exe")
-mycomputer = None
-mydocs = getMyDocuments()
-myappdata = getAppdata()
+MYCOMPUTER = None # wmi instance
+MYDOCS = getMyDocuments()
+MYAPPDATA = getAppdata()
def getMoulUserDataDir():
"""Get path of MOUL data directory
@@ -41,41 +48,48 @@
The MOUL data directory contains log files, chatlogs, KI images and many
more things.
"""
- moul_data = os.path.join(mydocs, MOUL_DIR)
+ moul_data = os.path.join(MYDOCS, MOUL_DIR)
return moul_data
def getPyMoulDataDir():
"""Get path to the pyMoul ini file
"""
- inidir = os.path.join(myappdata , 'pyMoul')
+ inidir = os.path.join(MYAPPDATA , 'pyMoul')
return inidir
-def _startMOUL(installdir, *args):
- """Start MOUL
+def startMoul(installdir, *args, **kwargs):
+ """Start MOUL - returns a Popen instance
+
+ args are applied to the program while kwargs are applied to
+ subprocess.Popen()
"""
- # TODO: use subprocess module
- # 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)
+ args = ' '.join(args)
+ return Popen("%s %s" % (path, args), cwd=installdir, **kwargs)
+def isMoulRunning():
+ """Test if MOUL or the launcher is running
+ """
+ for pid, name in getCurrentPidNames().items():
+ if name.lower() in PROCESSES:
+ return name.lower()
+ return False
+
def getCurrentPids():
"""Returns mapping pid -> name
"""
- global mycomputer
- if mycomputer is None:
+ global MYCOMPUTER
+ if MYCOMPUTER is None:
# XXX: extremely slow, also see getCurrentPidNames
- mycomputer = wmi.WMI()
- return [process.ProcessId for process in mycomputer.Win32_Process()]
+ MYCOMPUTER = wmi.WMI()
+ return [process.ProcessId for process in MYCOMPUTER.Win32_Process()]
def getCurrentPidNames():
"""Returns mapping pid -> name
"""
- global mycomputer
- if mycomputer is None:
- mycomputer = wmi.WMI()
+ global MYCOMPUTER
+ if MYCOMPUTER is None:
+ MYCOMPUTER = wmi.WMI()
return dict([(process.ProcessId, process.Name)
- for process in mycomputer.Win32_Process()
+ for process in MYCOMPUTER.Win32_Process()
])
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|