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

login
register
mail settings
Submitter Rishabh Madan
Date March 2, 2017, 11:01 p.m.
Message ID <dde3cd0607652020b3b2.1488495667@bunty>
Download mbox | patch
Permalink /patch/18876/
State Superseded
Headers show

Comments

Rishabh Madan - March 2, 2017, 11:01 p.m.
# HG changeset patch
# User Rishabh Madan <rishabhmadan96@gmail.com>
# Date 1488495530 -19800
#      Fri Mar 03 04:28:50 2017 +0530
# Node ID dde3cd0607652020b3b2e495e8a688383cf916ba
# 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 intends to replace the deprecated os.popen with subprocess.Popen
to return the correct output.
Jun Wu - March 2, 2017, 11:17 p.m.
Excerpts from Rishabh Madan's message of 2017-03-03 04:31:07 +0530:
> # HG changeset patch
> # User Rishabh Madan <rishabhmadan96@gmail.com>
> # Date 1488495530 -19800
> #      Fri Mar 03 04:28:50 2017 +0530
> # Node ID dde3cd0607652020b3b2e495e8a688383cf916ba
> # 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 intends to replace the deprecated os.popen with subprocess.Popen
> to return the correct output.
> 
> diff -r 71f692f1f678 -r dde3cd060765 mercurial/posix.py
> --- a/mercurial/posix.py    Wed Mar 01 20:22:04 2017 +0100
> +++ b/mercurial/posix.py    Fri Mar 03 04:28:50 2017 +0530
> @@ -16,6 +16,7 @@
>  import re
>  import select
>  import stat
> +import subprocess
>  import sys
>  import tempfile
>  import unicodedata
> @@ -419,7 +420,7 @@
>      return cmd
>  
>  def popen(command, mode='r'):
> -    return os.popen(command, mode)
> +    return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).stdout

I think this will break popen(mode='w')

>  
>  def testpid(pid):
>      '''return False if pid dead, True if running or not sure'''

Patch

diff -r 71f692f1f678 -r dde3cd060765 mercurial/posix.py
--- a/mercurial/posix.py	Wed Mar 01 20:22:04 2017 +0100
+++ b/mercurial/posix.py	Fri Mar 03 04:28:50 2017 +0530
@@ -16,6 +16,7 @@ 
 import re
 import select
 import stat
+import subprocess
 import sys
 import tempfile
 import unicodedata
@@ -419,7 +420,7 @@ 
     return cmd
 
 def popen(command, mode='r'):
-    return os.popen(command, mode)
+    return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).stdout
 
 def testpid(pid):
     '''return False if pid dead, True if running or not sure'''