summaryrefslogtreecommitdiffstats
path: root/pym/portage/dispatch_conf.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-07-24 13:52:44 -0700
committerZac Medico <zmedico@gentoo.org>2010-07-24 13:52:44 -0700
commit45709611085ba5f8c9670ce9877fed5031416fc5 (patch)
treeb9ca7057ca6faf67a6f8afc67eb2664c6e696887 /pym/portage/dispatch_conf.py
parentf20465a6a8a1ce9a715d861013038238149fe533 (diff)
downloadportage-45709611085ba5f8c9670ce9877fed5031416fc5.tar.gz
portage-45709611085ba5f8c9670ce9877fed5031416fc5.tar.bz2
portage-45709611085ba5f8c9670ce9877fed5031416fc5.zip
Handle UnicodeDecodeError from subprocess.getstatusoutput() calls, reported
with python3.1.
Diffstat (limited to 'pym/portage/dispatch_conf.py')
-rw-r--r--pym/portage/dispatch_conf.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/pym/portage/dispatch_conf.py b/pym/portage/dispatch_conf.py
index 956f52373..b4cded266 100644
--- a/pym/portage/dispatch_conf.py
+++ b/pym/portage/dispatch_conf.py
@@ -10,9 +10,9 @@ from __future__ import print_function
import os, sys, shutil
try:
- from subprocess import getoutput as subprocess_getoutput
+ from subprocess import getstatusoutput as subprocess_getstatusoutput
except ImportError:
- from commands import getoutput as subprocess_getoutput
+ from commands import getstatusoutput as subprocess_getstatusoutput
import portage
from portage.localization import _
@@ -25,6 +25,21 @@ RCS_MERGE = "rcsmerge -p -r" + RCS_BRANCH + " '%s' > '%s'"
DIFF3_MERGE = "diff3 -mE '%s' '%s' '%s' > '%s'"
+def diffstatusoutput_len(cmd):
+ """
+ Execute the string cmd in a shell with getstatusoutput() and return a
+ 2-tuple (status, output_length). If getstatusoutput() raises
+ UnicodeDecodeError (known to happen with python3.1), return a
+ 2-tuple (1, 1). This provides a simple way to check for non-zero
+ output length of diff commands, while providing simple handling of
+ UnicodeDecodeError when necessary.
+ """
+ try:
+ status, output = subprocess_getstatusoutput(cmd)
+ return (status, len(output))
+ except UnicodeDecodeError:
+ return (1, 1)
+
def read_config(mandatory_opts):
loader = portage.env.loaders.KeyValuePairFileLoader(
'/etc/dispatch-conf.conf', None)
@@ -115,7 +130,7 @@ def file_archive(archive, curconf, newconf, mrgconf):
# Archive the current config file if it isn't already saved
if os.path.exists(archive) \
- and len(subprocess_getoutput("diff -aq '%s' '%s'" % (curconf,archive))) != 0:
+ and diffstatusoutput_len("diff -aq '%s' '%s'" % (curconf,archive))[1] != 0:
suf = 1
while suf < 9 and os.path.exists(archive + '.' + str(suf)):
suf += 1