From 6142ba39d489983fe775771bfc0c5603c1c334df Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 4 Feb 2014 02:59:22 +1600 Subject: [PATCH] [PATCH 04/17] nmbug-status: Factor config-loading out into read_config --- 4a/b5192f5ec2fbc7d43e19e1dc8536a14d50ca2f | 142 ++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 4a/b5192f5ec2fbc7d43e19e1dc8536a14d50ca2f diff --git a/4a/b5192f5ec2fbc7d43e19e1dc8536a14d50ca2f b/4a/b5192f5ec2fbc7d43e19e1dc8536a14d50ca2f new file mode 100644 index 000000000..295362f48 --- /dev/null +++ b/4a/b5192f5ec2fbc7d43e19e1dc8536a14d50ca2f @@ -0,0 +1,142 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 227A5429E3F + for ; Mon, 3 Feb 2014 03:00:53 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 5EShl-ySsXlD for ; + Mon, 3 Feb 2014 03:00:47 -0800 (PST) +Received: from qmta13.westchester.pa.mail.comcast.net + (qmta13.westchester.pa.mail.comcast.net [76.96.59.243]) + by olra.theworths.org (Postfix) with ESMTP id A4AA2429E27 + for ; Mon, 3 Feb 2014 03:00:40 -0800 (PST) +Received: from omta06.westchester.pa.mail.comcast.net ([76.96.62.51]) + by qmta13.westchester.pa.mail.comcast.net with comcast + id Mmz51n00116LCl05Dn0gXf; Mon, 03 Feb 2014 11:00:40 +0000 +Received: from odin.tremily.us ([24.18.63.50]) + by omta06.westchester.pa.mail.comcast.net with comcast + id Mn0f1n003152l3L3Sn0fiS; Mon, 03 Feb 2014 11:00:40 +0000 +Received: from mjolnir.tremily.us (unknown [192.168.0.140]) + by odin.tremily.us (Postfix) with ESMTPS id DEA59FB4D47; + Mon, 3 Feb 2014 03:00:38 -0800 (PST) +Received: (nullmailer pid 684 invoked by uid 1000); + Mon, 03 Feb 2014 10:59:41 -0000 +From: "W. Trevor King" +To: notmuch@notmuchmail.org +Subject: [PATCH 04/17] nmbug-status: Factor config-loading out into + read_config +Date: Mon, 3 Feb 2014 02:59:22 -0800 +Message-Id: + <65fe8d8f253ba3dfa48f89193765ba16f44b4f81.1391424512.git.wking@tremily.us> +X-Mailer: git-send-email 1.8.5.2.8.g0f6c0d1 +In-Reply-To: +References: +In-Reply-To: +References: +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; + s=q20121106; t=1391425240; + bh=7QgiYpMpmn8WqWRsOxQXygu5qDb5C0F7IAUnsXEftMU=; + h=Received:Received:Received:Received:From:To:Subject:Date: + Message-Id; + b=o9tQMCM6fAYLVEhz21s2QG+FtKD6vmuukq1JmZb0QvU9INxWB5vDxgJVF4eo9mFtx + 5e3z3UA1GWQf2AC9+L/0ddRiBs+Uo8L2WU5MHQH86SwzPSsK6OwFdjIr4H2GCJR4sf + 9M2rvg4J5g77yUxXsYDahzerr5vcLqvEr3T5fXfzGktEYgVmF/9pRIw4wd8vTTH2Te + EftQr5F7DFc4+0H7n/nrkK258KXk3z5Fu5sPFrxYsMw1XglUHXq0vzOnaV300Qc8QU + 8ZAJMvxylciX7o3CgiaWGCBQK+D2BSppAZB6guZ/Qg/YxzvYReFS4sf8EROarZzad0 + 9XAi1ZpjTeswg== +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Mon, 03 Feb 2014 11:00:53 -0000 + +By isolating this peripheral handling, we make the core logic of +nmbug-status easier to read. +--- + devel/nmbug/nmbug-status | 45 +++++++++++++++++++++++++-------------------- + 1 file changed, 25 insertions(+), 20 deletions(-) + +diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status +index a7a391d..6dfbe4d 100755 +--- a/devel/nmbug/nmbug-status ++++ b/devel/nmbug/nmbug-status +@@ -23,6 +23,30 @@ import subprocess + _ENCODING = locale.getpreferredencoding() or sys.getdefaultencoding() + + ++def read_config(path=None, encoding=None): ++ "Read config from json file" ++ if not encoding: ++ encoding = _ENCODING ++ if path: ++ fp = open(path) ++ else: ++ nmbhome = os.getenv('NMBGIT', os.path.expanduser('~/.nmbug')) ++ ++ # read only the first line from the pipe ++ sha1_bytes = subprocess.Popen( ++ ['git', '--git-dir', nmbhome, 'show-ref', '-s', 'config'], ++ stdout=subprocess.PIPE).stdout.readline() ++ sha1 = sha1_bytes.decode(encoding).rstrip() ++ ++ fp_byte_stream = subprocess.Popen( ++ ['git', '--git-dir', nmbhome, 'cat-file', 'blob', ++ sha1+':status-config.json'], ++ stdout=subprocess.PIPE).stdout ++ fp = codecs.getreader(encoding=encoding)(stream=fp_byte_stream) ++ ++ return json.load(fp) ++ ++ + # parse command line arguments + + parser = argparse.ArgumentParser() +@@ -35,26 +59,7 @@ parser.add_argument('--get-query', help='get query for view') + + args = parser.parse_args() + +-# read config from json file +- +-if args.config != None: +- fp = open(args.config) +-else: +- nmbhome = os.getenv('NMBGIT', os.path.expanduser('~/.nmbug')) +- +- # read only the first line from the pipe +- sha1_bytes = subprocess.Popen( +- ['git', '--git-dir', nmbhome, 'show-ref', '-s', 'config'], +- stdout=subprocess.PIPE).stdout.readline() +- sha1 = sha1_bytes.decode(_ENCODING).rstrip() +- +- fp_byte_stream = subprocess.Popen( +- ['git', '--git-dir', nmbhome, 'cat-file', 'blob', +- sha1+':status-config.json'], +- stdout=subprocess.PIPE).stdout +- fp = codecs.getreader(encoding=_ENCODING)(stream=fp_byte_stream) +- +-config = json.load(fp) ++config = read_config(path=args.config) + + if args.list_views: + for view in config['views']: +-- +1.8.5.2.8.g0f6c0d1 + -- 2.26.2