1 Return-Path: <wking@tremily.us>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 1803F431FAF
\r
6 for <notmuch@notmuchmail.org>; Mon, 10 Feb 2014 10:42:11 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=0 tagged_above=-999 required=5
\r
13 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001]
\r
15 Received: from olra.theworths.org ([127.0.0.1])
\r
16 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
17 with ESMTP id xrG6UdFxYm2a for <notmuch@notmuchmail.org>;
\r
18 Mon, 10 Feb 2014 10:42:03 -0800 (PST)
\r
19 Received: from qmta08.westchester.pa.mail.comcast.net
\r
20 (qmta08.westchester.pa.mail.comcast.net [76.96.62.80])
\r
21 by olra.theworths.org (Postfix) with ESMTP id 9077B431FD7
\r
22 for <notmuch@notmuchmail.org>; Mon, 10 Feb 2014 10:41:55 -0800 (PST)
\r
23 Received: from omta05.westchester.pa.mail.comcast.net ([76.96.62.43])
\r
24 by qmta08.westchester.pa.mail.comcast.net with comcast
\r
25 id QgdL1n0050vyq2s58ihuq7; Mon, 10 Feb 2014 18:41:54 +0000
\r
26 Received: from odin.tremily.us ([24.18.63.50])
\r
27 by omta05.westchester.pa.mail.comcast.net with comcast
\r
28 id Qiht1n00T152l3L3RihuQu; Mon, 10 Feb 2014 18:41:54 +0000
\r
29 Received: from mjolnir.tremily.us (unknown [192.168.0.140])
\r
30 by odin.tremily.us (Postfix) with ESMTPS id 3EB3910167A7;
\r
31 Mon, 10 Feb 2014 10:41:53 -0800 (PST)
\r
32 Received: (nullmailer pid 1248 invoked by uid 1000);
\r
33 Mon, 10 Feb 2014 18:40:44 -0000
\r
34 From: "W. Trevor King" <wking@tremily.us>
\r
35 To: notmuch@notmuchmail.org
\r
36 Subject: [PATCH v2 03/20] nmbug-status: Decode Popen output using the user's
\r
38 Date: Mon, 10 Feb 2014 10:40:24 -0800
\r
40 <9a07face73274cbb977b8a8e4e983e64b0863531.1392056624.git.wking@tremily.us>
\r
41 X-Mailer: git-send-email 1.8.5.2.8.g0f6c0d1
\r
42 In-Reply-To: <cover.1392056624.git.wking@tremily.us>
\r
43 References: <cover.1392056624.git.wking@tremily.us>
\r
44 In-Reply-To: <cover.1392056624.git.wking@tremily.us>
\r
45 References: <cover.1392056624.git.wking@tremily.us>
\r
46 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net;
\r
47 s=q20121106; t=1392057714;
\r
48 bh=1aQ15C7VOfb5SpJX2PiuZjmexLCSbY7tx6l56EDHxmQ=;
\r
49 h=Received:Received:Received:Received:From:To:Subject:Date:
\r
51 b=bAKg/W+4GY85Y5zC2WGRsEjQaKEGAvSkoyllB/sJTORWTQBslG2odDp+1wPac03mk
\r
52 qHaC7yUl/+ovX2e1IYZOsBZlZZUfjbU084969rUFg50a+RlFh8nASFPAjxnAipE9fU
\r
53 GvKYwhLqDk86K4xSdavatN8jKke9q/dGJHE45WDaGakb4MQq84TqiPgf49ks1vvvaw
\r
54 OPmzAh6r1f0qE3HnGqJ7lxt6eCFzaMwYvWlL8nRBNdsE9N5ipzuVc0iMTg3oTfoUR+
\r
55 gb/4Z2ZnD1PTpX8HpL0coDYHHMhzdHSUvOZY61oYaWTnVjX5dgYP+QCPdI4fYw4+RF
\r
57 Cc: Tomi Ollila <tomi.ollila@iki.fi>
\r
58 X-BeenThere: notmuch@notmuchmail.org
\r
59 X-Mailman-Version: 2.1.13
\r
61 List-Id: "Use and development of the notmuch mail system."
\r
62 <notmuch.notmuchmail.org>
\r
63 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
64 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
65 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
66 List-Post: <mailto:notmuch@notmuchmail.org>
\r
67 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
68 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
69 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
70 X-List-Received-Date: Mon, 10 Feb 2014 18:42:11 -0000
\r
74 $ ./nmbug-status --list-views
\r
75 Traceback (most recent call last):
\r
76 File "./nmbug-status", line 47, in <module>
\r
77 'cat-file', 'blob', sha1+':status-config.json'],
\r
78 TypeError: can't concat bytes to str
\r
80 by explicitly converting the byte-stream read from Popen into a
\r
81 Unicode string. On Python 2, this conversion is str -> unicode; on
\r
82 Python 3 it is bytes -> str.
\r
84 _ENCODING is derived from the user's locale (or system default) in an
\r
85 attempt to match Git's output encoding. It may be more robust to skip
\r
86 the encoding/decoding by using a Python wrapper like pygit2 [1] for
\r
87 Git access. That's a fairly heavy dependency though, and using the
\r
88 locale will probably work.
\r
90 [1]: http://www.pygit2.org/
\r
92 devel/nmbug/nmbug-status | 25 ++++++++++++++++---------
\r
93 1 file changed, 16 insertions(+), 9 deletions(-)
\r
95 diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status
\r
96 index 6525176..a7a391d 100755
\r
97 --- a/devel/nmbug/nmbug-status
\r
98 +++ b/devel/nmbug/nmbug-status
\r
101 from __future__ import print_function
\r
110 @@ -17,6 +19,10 @@ import os
\r
115 +_ENCODING = locale.getpreferredencoding() or sys.getdefaultencoding()
\r
118 # parse command line arguments
\r
120 parser = argparse.ArgumentParser()
\r
121 @@ -37,15 +43,16 @@ else:
\r
122 nmbhome = os.getenv('NMBGIT', os.path.expanduser('~/.nmbug'))
\r
124 # read only the first line from the pipe
\r
125 - sha1 = subprocess.Popen(['git', '--git-dir', nmbhome,
\r
126 - 'show-ref', '-s', 'config'],
\r
127 - stdout=subprocess.PIPE).stdout.readline()
\r
129 - sha1 = sha1.rstrip()
\r
131 - fp = subprocess.Popen(['git', '--git-dir', nmbhome,
\r
132 - 'cat-file', 'blob', sha1+':status-config.json'],
\r
133 - stdout=subprocess.PIPE).stdout
\r
134 + sha1_bytes = subprocess.Popen(
\r
135 + ['git', '--git-dir', nmbhome, 'show-ref', '-s', 'config'],
\r
136 + stdout=subprocess.PIPE).stdout.readline()
\r
137 + sha1 = sha1_bytes.decode(_ENCODING).rstrip()
\r
139 + fp_byte_stream = subprocess.Popen(
\r
140 + ['git', '--git-dir', nmbhome, 'cat-file', 'blob',
\r
141 + sha1+':status-config.json'],
\r
142 + stdout=subprocess.PIPE).stdout
\r
143 + fp = codecs.getreader(encoding=_ENCODING)(stream=fp_byte_stream)
\r
145 config = json.load(fp)
\r