1.1 --- a/desktop.py Wed Oct 15 23:18:02 2008 +0200
1.2 +++ b/desktop.py Wed Jul 19 21:36:11 2006 +0000
1.3 @@ -5,7 +5,7 @@
1.4 detection and resource opening support for a selection of common and
1.5 standardised desktop environments.
1.6
1.7 -Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2005, 2006 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This library is free software; you can redistribute it and/or
1.11 modify it under the terms of the GNU Lesser General Public
1.12 @@ -68,11 +68,25 @@
1.13 http://lists.freedesktop.org/archives/xdg/2004-August/004489.html
1.14 """
1.15
1.16 -__version__ = "0.2.2"
1.17 +__version__ = "0.2.3"
1.18
1.19 import os
1.20 import sys
1.21 -import subprocess
1.22 +
1.23 +try:
1.24 + import subprocess
1.25 + def _run(cmd, shell, wait):
1.26 + opener = subprocess.Popen(cmd, shell=shell)
1.27 + if wait: opener.wait()
1.28 + return opener.pid
1.29 +
1.30 +except ImportError:
1.31 + import popen2
1.32 + def _run(cmd, shell, wait):
1.33 + opener = popen2.Popen3(cmd)
1.34 + if wait: opener.wait()
1.35 + return opener.pid
1.36 +
1.37 import commands
1.38
1.39 def get_desktop():
1.40 @@ -104,17 +118,6 @@
1.41
1.42 return os.environ.has_key("DESKTOP_LAUNCH")
1.43
1.44 -def _wait(pid, block):
1.45 -
1.46 - """
1.47 - Perform a blocking Wait for the given process identifier, 'pid', if the
1.48 - 'block' flag is set to a true value. Return the process identifier.
1.49 - """
1.50 -
1.51 - if block:
1.52 - os.waitpid(pid, os.P_WAIT)
1.53 - return pid
1.54 -
1.55 def open(url, desktop=None, wait=0):
1.56
1.57 """
1.58 @@ -146,7 +149,7 @@
1.59
1.60 if (desktop is None or desktop == "standard") and is_standard():
1.61 arg = "".join([os.environ["DESKTOP_LAUNCH"], commands.mkarg(url)])
1.62 - return _wait(subprocess.Popen(arg, shell=1).pid, wait)
1.63 + return _run(arg, 1, wait)
1.64
1.65 elif (desktop is None or desktop == "Windows") and detected == "Windows":
1.66 # NOTE: This returns None in current implementations.
1.67 @@ -168,6 +171,6 @@
1.68 else:
1.69 raise OSError, "Desktop not supported (neither DESKTOP_LAUNCH nor os.startfile could be used)"
1.70
1.71 - return _wait(subprocess.Popen(cmd).pid, wait)
1.72 + return _run(cmd, 0, wait)
1.73
1.74 # vim: tabstop=4 expandtab shiftwidth=4