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 227A5429E3F
\r
6 for <notmuch@notmuchmail.org>; Mon, 3 Feb 2014 03:00:53 -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 5EShl-ySsXlD for <notmuch@notmuchmail.org>;
\r
18 Mon, 3 Feb 2014 03:00:47 -0800 (PST)
\r
19 Received: from qmta13.westchester.pa.mail.comcast.net
\r
20 (qmta13.westchester.pa.mail.comcast.net [76.96.59.243])
\r
21 by olra.theworths.org (Postfix) with ESMTP id A4AA2429E27
\r
22 for <notmuch@notmuchmail.org>; Mon, 3 Feb 2014 03:00:40 -0800 (PST)
\r
23 Received: from omta06.westchester.pa.mail.comcast.net ([76.96.62.51])
\r
24 by qmta13.westchester.pa.mail.comcast.net with comcast
\r
25 id Mmz51n00116LCl05Dn0gXf; Mon, 03 Feb 2014 11:00:40 +0000
\r
26 Received: from odin.tremily.us ([24.18.63.50])
\r
27 by omta06.westchester.pa.mail.comcast.net with comcast
\r
28 id Mn0f1n003152l3L3Sn0fiS; Mon, 03 Feb 2014 11:00:40 +0000
\r
29 Received: from mjolnir.tremily.us (unknown [192.168.0.140])
\r
30 by odin.tremily.us (Postfix) with ESMTPS id DEA59FB4D47;
\r
31 Mon, 3 Feb 2014 03:00:38 -0800 (PST)
\r
32 Received: (nullmailer pid 684 invoked by uid 1000);
\r
33 Mon, 03 Feb 2014 10:59:41 -0000
\r
34 From: "W. Trevor King" <wking@tremily.us>
\r
35 To: notmuch@notmuchmail.org
\r
36 Subject: [PATCH 04/17] nmbug-status: Factor config-loading out into
\r
38 Date: Mon, 3 Feb 2014 02:59:22 -0800
\r
40 <65fe8d8f253ba3dfa48f89193765ba16f44b4f81.1391424512.git.wking@tremily.us>
\r
41 X-Mailer: git-send-email 1.8.5.2.8.g0f6c0d1
\r
42 In-Reply-To: <cover.1391424512.git.wking@tremily.us>
\r
43 References: <cover.1391424512.git.wking@tremily.us>
\r
44 In-Reply-To: <cover.1391424512.git.wking@tremily.us>
\r
45 References: <cover.1391424512.git.wking@tremily.us>
\r
46 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net;
\r
47 s=q20121106; t=1391425240;
\r
48 bh=7QgiYpMpmn8WqWRsOxQXygu5qDb5C0F7IAUnsXEftMU=;
\r
49 h=Received:Received:Received:Received:From:To:Subject:Date:
\r
51 b=o9tQMCM6fAYLVEhz21s2QG+FtKD6vmuukq1JmZb0QvU9INxWB5vDxgJVF4eo9mFtx
\r
52 5e3z3UA1GWQf2AC9+L/0ddRiBs+Uo8L2WU5MHQH86SwzPSsK6OwFdjIr4H2GCJR4sf
\r
53 9M2rvg4J5g77yUxXsYDahzerr5vcLqvEr3T5fXfzGktEYgVmF/9pRIw4wd8vTTH2Te
\r
54 EftQr5F7DFc4+0H7n/nrkK258KXk3z5Fu5sPFrxYsMw1XglUHXq0vzOnaV300Qc8QU
\r
55 8ZAJMvxylciX7o3CgiaWGCBQK+D2BSppAZB6guZ/Qg/YxzvYReFS4sf8EROarZzad0
\r
57 X-BeenThere: notmuch@notmuchmail.org
\r
58 X-Mailman-Version: 2.1.13
\r
60 List-Id: "Use and development of the notmuch mail system."
\r
61 <notmuch.notmuchmail.org>
\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
63 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
65 List-Post: <mailto:notmuch@notmuchmail.org>
\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
68 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
69 X-List-Received-Date: Mon, 03 Feb 2014 11:00:53 -0000
\r
71 By isolating this peripheral handling, we make the core logic of
\r
72 nmbug-status easier to read.
\r
74 devel/nmbug/nmbug-status | 45 +++++++++++++++++++++++++--------------------
\r
75 1 file changed, 25 insertions(+), 20 deletions(-)
\r
77 diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status
\r
78 index a7a391d..6dfbe4d 100755
\r
79 --- a/devel/nmbug/nmbug-status
\r
80 +++ b/devel/nmbug/nmbug-status
\r
81 @@ -23,6 +23,30 @@ import subprocess
\r
82 _ENCODING = locale.getpreferredencoding() or sys.getdefaultencoding()
\r
85 +def read_config(path=None, encoding=None):
\r
86 + "Read config from json file"
\r
88 + encoding = _ENCODING
\r
92 + nmbhome = os.getenv('NMBGIT', os.path.expanduser('~/.nmbug'))
\r
94 + # read only the first line from the pipe
\r
95 + sha1_bytes = subprocess.Popen(
\r
96 + ['git', '--git-dir', nmbhome, 'show-ref', '-s', 'config'],
\r
97 + stdout=subprocess.PIPE).stdout.readline()
\r
98 + sha1 = sha1_bytes.decode(encoding).rstrip()
\r
100 + fp_byte_stream = subprocess.Popen(
\r
101 + ['git', '--git-dir', nmbhome, 'cat-file', 'blob',
\r
102 + sha1+':status-config.json'],
\r
103 + stdout=subprocess.PIPE).stdout
\r
104 + fp = codecs.getreader(encoding=encoding)(stream=fp_byte_stream)
\r
106 + return json.load(fp)
\r
109 # parse command line arguments
\r
111 parser = argparse.ArgumentParser()
\r
112 @@ -35,26 +59,7 @@ parser.add_argument('--get-query', help='get query for view')
\r
114 args = parser.parse_args()
\r
116 -# read config from json file
\r
118 -if args.config != None:
\r
119 - fp = open(args.config)
\r
121 - nmbhome = os.getenv('NMBGIT', os.path.expanduser('~/.nmbug'))
\r
123 - # read only the first line from the pipe
\r
124 - sha1_bytes = subprocess.Popen(
\r
125 - ['git', '--git-dir', nmbhome, 'show-ref', '-s', 'config'],
\r
126 - stdout=subprocess.PIPE).stdout.readline()
\r
127 - sha1 = sha1_bytes.decode(_ENCODING).rstrip()
\r
129 - fp_byte_stream = subprocess.Popen(
\r
130 - ['git', '--git-dir', nmbhome, 'cat-file', 'blob',
\r
131 - sha1+':status-config.json'],
\r
132 - stdout=subprocess.PIPE).stdout
\r
133 - fp = codecs.getreader(encoding=_ENCODING)(stream=fp_byte_stream)
\r
135 -config = json.load(fp)
\r
136 +config = read_config(path=args.config)
\r
138 if args.list_views:
\r
139 for view in config['views']:
\r