# HG changeset patch # User Dirkjan Ochtman # Date 1208176478 -7200 # Node ID 962eb403165bbe7886aaf63fd90f4db8e93b08c2 # Parent 65f1b97484be50f3565a9ca59e9fbe01b3d143b8 replace usage of os.popen() with util.popen() To make this possible, I added a mode parameter to both implementations of util.popen(), defaulting to 'r' (as it does in the Python stdlib). diff -r 65f1b97484be -r 962eb403165b hgext/bugzilla.py --- a/hgext/bugzilla.py Sun Apr 13 11:31:45 2008 -0500 +++ b/hgext/bugzilla.py Mon Apr 14 14:34:38 2008 +0200 @@ -55,7 +55,7 @@ from mercurial.i18n import _ from mercurial.node import short from mercurial import cmdutil, templater, util -import os, re, time +import re, time MySQLdb = None @@ -127,7 +127,7 @@ cmd = self.ui.config('bugzilla', 'notify', 'cd /var/www/html/bugzilla && ' './processmail %s nobody@nowhere.com') % id - fp = os.popen('(%s) 2>&1' % cmd) + fp = util.popen('(%s) 2>&1' % cmd) out = fp.read() ret = fp.close() if ret: diff -r 65f1b97484be -r 962eb403165b hgext/pager.py --- a/hgext/pager.py Sun Apr 13 11:31:45 2008 -0500 +++ b/hgext/pager.py Mon Apr 14 14:34:38 2008 +0200 @@ -47,7 +47,7 @@ ''' import sys, os, signal -from mercurial import dispatch +from mercurial import dispatch, util def uisetup(ui): def pagecmd(ui, options, cmd, cmdfunc): @@ -56,7 +56,7 @@ attend = ui.configlist('pager', 'attend') if (cmd in attend or (cmd not in ui.configlist('pager', 'ignore') and not attend)): - sys.stderr = sys.stdout = os.popen(p, "wb") + sys.stderr = sys.stdout = util.popen(p, "wb") if ui.configbool('pager', 'quiet'): signal.signal(signal.SIGPIPE, signal.SIG_DFL) return oldrun(ui, options, cmd, cmdfunc) diff -r 65f1b97484be -r 962eb403165b hgext/patchbomb.py --- a/hgext/patchbomb.py Sun Apr 13 11:31:45 2008 -0500 +++ b/hgext/patchbomb.py Mon Apr 14 14:34:38 2008 +0200 @@ -404,7 +404,7 @@ ui.status('Displaying ', m['Subject'], ' ...\n') ui.flush() if 'PAGER' in os.environ: - fp = os.popen(os.environ['PAGER'], 'w') + fp = util.popen(os.environ['PAGER'], 'w') else: fp = ui generator = email.Generator.Generator(fp, mangle_from_=False) diff -r 65f1b97484be -r 962eb403165b mercurial/mail.py --- a/mercurial/mail.py Sun Apr 13 11:31:45 2008 -0500 +++ b/mercurial/mail.py Mon Apr 14 14:34:38 2008 +0200 @@ -6,7 +6,8 @@ # of the GNU General Public License, incorporated herein by reference. from i18n import _ -import os, smtplib, util, socket +import os, smtplib, socket +import util def _smtp(ui): '''build an smtp connection and return a function to send mail''' @@ -53,7 +54,7 @@ cmdline = '%s -f %s %s' % (program, util.email(sender), ' '.join(map(util.email, recipients))) ui.note(_('sending mail: %s\n') % cmdline) - fp = os.popen(cmdline, 'w') + fp = util.popen(cmdline, 'w') fp.write(msg) ret = fp.close() if ret: diff -r 65f1b97484be -r 962eb403165b mercurial/util.py --- a/mercurial/util.py Sun Apr 13 11:31:45 2008 -0500 +++ b/mercurial/util.py Mon Apr 14 14:34:38 2008 +0200 @@ -1086,12 +1086,12 @@ # through the current COMSPEC. cmd.exe suppress enclosing quotes. return '"' + cmd + '"' - def popen(command): + def popen(command, mode='r'): # Work around "popen spawned process may not write to stdout # under windows" # http://bugs.python.org/issue1366 command += " 2> %s" % nulldev - return os.popen(quotecommand(command)) + return os.popen(quotecommand(command), mode) def explain_exit(code): return _("exited with status %d") % code, code @@ -1252,8 +1252,8 @@ def quotecommand(cmd): return cmd - def popen(command): - return os.popen(command) + def popen(command, mode='r'): + return os.popen(command, mode) def testpid(pid): '''return False if pid dead, True if running or not sure''' diff -r 65f1b97484be -r 962eb403165b mercurial/version.py --- a/mercurial/version.py Sun Apr 13 11:31:45 2008 -0500 +++ b/mercurial/version.py Mon Apr 14 14:34:38 2008 +0200 @@ -12,6 +12,7 @@ import os import re import time +import util unknown_version = 'unknown' remembered_version = False @@ -48,7 +49,7 @@ """Store version information.""" global remembered_version if not version and os.path.isdir(".hg"): - f = os.popen("hg identify") # use real hg installation + f = util.popen("hg identify") # use real hg installation ident = f.read()[:-1] if not f.close() and ident: ids = ident.split(' ', 1)