Patchwork [V4] posix: update os.popen with subprocess (issue4746)

login
register
mail settings
Submitter Rishabh Madan
Date March 4, 2017, 7:19 a.m.
Message ID <99a468ebed64e08a157f.1488611983@bunty>
Download mbox | patch
Permalink /patch/18908/
State Changes Requested
Headers show

Comments

Rishabh Madan - March 4, 2017, 7:19 a.m.
# HG changeset patch
# User Rishabh Madan <rishabhmadan96@gmail.com>
# Date 1488611777 -19800
#      Sat Mar 04 12:46:17 2017 +0530
# Node ID 99a468ebed64e08a157fdad1333e44103886130d
# Parent  71f692f1f678d86ffb4f95a3621aacfdaeb96b05
posix: update os.popen with subprocess (issue4746)

While importing a patch, we use a patch tool, say 'patch --merge', and the
patch doesn't merge cleanly, 'patch --merge' will return with exit status 1,
but 'hg import' displays 'abort: patch command failed: exited with status 256'.
This patch replaces the deprecated os.popen with subprocess.Popen with
conditional statements for 'r', 'rb', 'w' and 'wb' mode and raise ValueError
otherwise.
Yuya Nishihara - March 5, 2017, 3:44 a.m.
On Sat, 04 Mar 2017 12:49:43 +0530, Rishabh Madan wrote:
> # HG changeset patch
> # User Rishabh Madan <rishabhmadan96@gmail.com>
> # Date 1488611777 -19800
> #      Sat Mar 04 12:46:17 2017 +0530
> # Node ID 99a468ebed64e08a157fdad1333e44103886130d
> # Parent  71f692f1f678d86ffb4f95a3621aacfdaeb96b05
> posix: update os.popen with subprocess (issue4746)

I've dropped this from patchwork per the review for V3.

Patch

diff -r 71f692f1f678 -r 99a468ebed64 mercurial/posix.py
--- a/mercurial/posix.py	Wed Mar 01 20:22:04 2017 +0100
+++ b/mercurial/posix.py	Sat Mar 04 12:46:17 2017 +0530
@@ -16,6 +16,7 @@ 
 import re
 import select
 import stat
+import subprocess
 import sys
 import tempfile
 import unicodedata
@@ -419,7 +420,14 @@ 
     return cmd
 
 def popen(command, mode='r'):
-    return os.popen(command, mode)
+    if 'r' in mode:
+        return subprocess.Popen(command, shell=True,
+            stdout=subprocess.PIPE).stdout
+    elif 'w' in mode:
+        return subprocess.Popen(command, shell=True,
+            stdin=subprocess.PIPE).stdin
+    else:
+        raise ValueError
 
 def testpid(pid):
     '''return False if pid dead, True if running or not sure'''