Mercurial > hg
changeset 6548:962eb403165b
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).
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Mon, 14 Apr 2008 14:34:38 +0200 |
parents | 65f1b97484be |
children | 2af1b9de62b3 |
files | hgext/bugzilla.py hgext/pager.py hgext/patchbomb.py mercurial/mail.py mercurial/util.py mercurial/version.py |
diffstat | 6 files changed, 14 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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:
--- 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)
--- 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)
--- 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:
--- 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'''
--- 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)