"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/popen.py" between
viewvc-1.1.28.tar.gz and viewvc-1.2.1.tar.gz

About: ViewVC is a browser interface for CVS and Subversion version control repositories.

popen.py  (viewvc-1.1.28):popen.py  (viewvc-1.2.1)
skipping to change at line 26 skipping to change at line 26
# rather than a system() type of convention. The shell facilities are not # rather than a system() type of convention. The shell facilities are not
# available, but that implies we can avoid worrying about shell hacks in # available, but that implies we can avoid worrying about shell hacks in
# the arguments. # the arguments.
# #
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
import os import os
import sys import sys
import sapi import sapi
import threading import threading
import string
if sys.platform == "win32": if sys.platform == "win32":
import win32popen import win32popen
import win32event import win32event
import win32process import win32process
import debug import debug
import StringIO import StringIO
def popen(cmd, args, mode, capture_err=1): def popen(cmd, args, mode, capture_err=1):
if sys.platform == "win32": if sys.platform == "win32":
command = win32popen.CommandLine(cmd, args) command = win32popen.CommandLine(cmd, args)
if string.find(mode, 'r') >= 0: if mode.find('r') >= 0:
hStdIn = None hStdIn = None
if debug.SHOW_CHILD_PROCESSES: if debug.SHOW_CHILD_PROCESSES:
dbgIn, dbgOut = None, StringIO.StringIO() dbgIn, dbgOut = None, StringIO.StringIO()
handle, hStdOut = win32popen.MakeSpyPipe(0, 1, (dbgOut,)) handle, hStdOut = win32popen.MakeSpyPipe(0, 1, (dbgOut,))
if capture_err: if capture_err:
hStdErr = hStdOut hStdErr = hStdOut
dbgErr = dbgOut dbgErr = dbgOut
skipping to change at line 88 skipping to change at line 87
# flush the stdio buffers since we are about to change the FD under them # flush the stdio buffers since we are about to change the FD under them
sys.stdout.flush() sys.stdout.flush()
sys.stderr.flush() sys.stderr.flush()
r, w = os.pipe() r, w = os.pipe()
pid = os.fork() pid = os.fork()
if pid: if pid:
# in the parent # in the parent
# close the descriptor that we don't need and return the other one. # close the descriptor that we don't need and return the other one.
if string.find(mode, 'r') >= 0: if mode.find('r') >= 0:
os.close(w) os.close(w)
return _pipe(os.fdopen(r, mode), pid) return _pipe(os.fdopen(r, mode), pid)
os.close(r) os.close(r)
return _pipe(os.fdopen(w, mode), pid) return _pipe(os.fdopen(w, mode), pid)
# in the child # in the child
# we'll need /dev/null for the discarded I/O # we'll need /dev/null for the discarded I/O
null = os.open('/dev/null', os.O_RDWR) null = os.open('/dev/null', os.O_RDWR)
if string.find(mode, 'r') >= 0: if mode.find('r') >= 0:
# hook stdout/stderr to the "write" channel # hook stdout/stderr to the "write" channel
os.dup2(w, 1) os.dup2(w, 1)
# "close" stdin; the child shouldn't use it # "close" stdin; the child shouldn't use it
### this isn't quite right... we may want the child to read from stdin ### this isn't quite right... we may want the child to read from stdin
os.dup2(null, 0) os.dup2(null, 0)
# what to do with errors? # what to do with errors?
if capture_err: if capture_err:
os.dup2(w, 2) os.dup2(w, 2)
else: else:
os.dup2(null, 2) os.dup2(null, 2)
skipping to change at line 128 skipping to change at line 127
# don't need these FDs any more # don't need these FDs any more
os.close(null) os.close(null)
os.close(r) os.close(r)
os.close(w) os.close(w)
# the stdin/stdout/stderr are all set up. exec the target # the stdin/stdout/stderr are all set up. exec the target
try: try:
os.execvp(cmd, (cmd,) + tuple(args)) os.execvp(cmd, (cmd,) + tuple(args))
except: except:
# aid debugging, if the os.execvp above fails for some reason: # aid debugging, if the os.execvp above fails for some reason:
print "<h2>exec failed:</h2><pre>", cmd, string.join(args), "</pre>" print "<h2>exec failed:</h2><pre>", cmd, ' '.join(args), "</pre>"
raise raise
# crap. shouldn't be here. # crap. shouldn't be here.
sys.exit(127) sys.exit(127)
class _pipe: class _pipe:
"Wrapper for a file which can wait() on a child process at close time." "Wrapper for a file which can wait() on a child process at close time."
def __init__(self, file, child_pid, done_event = None, thread = None): def __init__(self, file, child_pid, done_event = None, thread = None):
self.file = file self.file = file
 End of changes. 5 change blocks. 
5 lines changed or deleted 4 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)