1 |
commit: 3f7a3b294dd38c6009d41ce7f40075e2e2645c6e |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Mar 31 17:22:13 2012 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Mar 31 17:22:13 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=3f7a3b29 |
7 |
|
8 |
dispatch_conf: emulate getstatusoutput with Popen |
9 |
|
10 |
This will fix bug #410315. |
11 |
|
12 |
--- |
13 |
pym/portage/dispatch_conf.py | 24 ++++++++++++------------ |
14 |
1 files changed, 12 insertions(+), 12 deletions(-) |
15 |
|
16 |
diff --git a/pym/portage/dispatch_conf.py b/pym/portage/dispatch_conf.py |
17 |
index 3d53f64..cc98fad 100644 |
18 |
--- a/pym/portage/dispatch_conf.py |
19 |
+++ b/pym/portage/dispatch_conf.py |
20 |
@@ -1,5 +1,5 @@ |
21 |
# archive_conf.py -- functionality common to archive-conf and dispatch-conf |
22 |
-# Copyright 2003-2011 Gentoo Foundation |
23 |
+# Copyright 2003-2012 Gentoo Foundation |
24 |
# Distributed under the terms of the GNU General Public License v2 |
25 |
|
26 |
|
27 |
@@ -8,7 +8,7 @@ |
28 |
|
29 |
from __future__ import print_function |
30 |
|
31 |
-import os, sys, shutil |
32 |
+import os, shutil, subprocess, sys |
33 |
|
34 |
import portage |
35 |
from portage.env.loaders import KeyValuePairFileLoader |
36 |
@@ -26,17 +26,17 @@ DIFF3_MERGE = "diff3 -mE '%s' '%s' '%s' > '%s'" |
37 |
def diffstatusoutput(cmd, file1, file2): |
38 |
""" |
39 |
Execute the string cmd in a shell with getstatusoutput() and return a |
40 |
- 2-tuple (status, output). If getstatusoutput() raises |
41 |
- UnicodeDecodeError (known to happen with python3.1), return a |
42 |
- 2-tuple (1, 1). This provides a simple way to check for non-zero |
43 |
- output length of diff commands, while providing simple handling of |
44 |
- UnicodeDecodeError when necessary. |
45 |
+ 2-tuple (status, output). |
46 |
""" |
47 |
- try: |
48 |
- status, output = portage.subprocess_getstatusoutput(cmd % (file1, file2)) |
49 |
- return (status, output) |
50 |
- except UnicodeDecodeError: |
51 |
- return (1, 1) |
52 |
+ # Use Popen to emulate getstatusoutput(), since getstatusoutput() may |
53 |
+ # raise a UnicodeDecodeError which makes the output inaccessible. |
54 |
+ proc = subprocess.Popen(portage._unicode_encode(cmd % (file1, file2)), |
55 |
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) |
56 |
+ output = portage._unicode_decode(proc.communicate()[0]) |
57 |
+ if output and output[-1] == "\n": |
58 |
+ # getstatusoutput strips one newline |
59 |
+ output = output[:-1] |
60 |
+ return (proc.wait(), output) |
61 |
|
62 |
def read_config(mandatory_opts): |
63 |
eprefix = portage.const.EPREFIX |