--- /dev/null
+Return-Path: <wking@tremily.us>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 0F345431FAF\r
+ for <notmuch@notmuchmail.org>; Mon, 10 Feb 2014 10:42:17 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id pt8eCdaLPHKn for <notmuch@notmuchmail.org>;\r
+ Mon, 10 Feb 2014 10:42:11 -0800 (PST)\r
+Received: from qmta12.westchester.pa.mail.comcast.net\r
+ (qmta12.westchester.pa.mail.comcast.net [76.96.59.227])\r
+ by olra.theworths.org (Postfix) with ESMTP id 61E52431FDF\r
+ for <notmuch@notmuchmail.org>; Mon, 10 Feb 2014 10:41:56 -0800 (PST)\r
+Received: from omta15.westchester.pa.mail.comcast.net ([76.96.62.87])\r
+ by qmta12.westchester.pa.mail.comcast.net with comcast\r
+ id QiCj1n0081swQuc5Cihw5l; Mon, 10 Feb 2014 18:41:56 +0000\r
+Received: from odin.tremily.us ([24.18.63.50])\r
+ by omta15.westchester.pa.mail.comcast.net with comcast\r
+ id Qihu1n00b152l3L3bihvdS; Mon, 10 Feb 2014 18:41:56 +0000\r
+Received: from mjolnir.tremily.us (unknown [192.168.0.140])\r
+ by odin.tremily.us (Postfix) with ESMTPS id 8D72010167AD;\r
+ Mon, 10 Feb 2014 10:41:54 -0800 (PST)\r
+Received: (nullmailer pid 1255 invoked by uid 1000);\r
+ Mon, 10 Feb 2014 18:40:44 -0000\r
+From: "W. Trevor King" <wking@tremily.us>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 06/20] nmbug-status: Consolidate functions and main code\r
+Date: Mon, 10 Feb 2014 10:40:27 -0800\r
+Message-Id:\r
+ <43b389b156214bb07c09f36cd36fd9fa2ccebf5b.1392056624.git.wking@tremily.us>\r
+X-Mailer: git-send-email 1.8.5.2.8.g0f6c0d1\r
+In-Reply-To: <cover.1392056624.git.wking@tremily.us>\r
+References: <cover.1392056624.git.wking@tremily.us>\r
+In-Reply-To: <cover.1392056624.git.wking@tremily.us>\r
+References: <cover.1392056624.git.wking@tremily.us>\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net;\r
+ s=q20121106; t=1392057716;\r
+ bh=yMvCAOnnJi1PiHQdjnon2+E+kEYl22joo5zXYe+ylVs=;\r
+ h=Received:Received:Received:Received:From:To:Subject:Date:\r
+ Message-Id;\r
+ b=bxmgbBkbZ6uZdNj/k5H6p17VIYv+XKt9hOgIWYOUeEpo2syEw8mpQkqyymDG22Lry\r
+ bC/dd9rBO35PCyQBZ6//54pLiy0urp2s3RFnzcWAClCGHumbnwYB3t/UgSGLlfpIXD\r
+ vZNIZblPl02Aj6jZdG/aXeoGQdR4yOJFbrN0I2SVeG28QG/8s9xSTHsWwHdwMhm+qQ\r
+ T9niWQH/Xi9D3+2lWx3vIjzoPOo7AY2Kj4i2rkd6K9SvdovmJ1u3pe3yeQ0l9DfLrY\r
+ Ts2gO/mzPBcZdqBOdzog0o063uH13jB++iqVzJzBvJyswKYUDU/0Q9K7FHGH49E3sR\r
+ Z2agrjmdMKVwA==\r
+Cc: Tomi Ollila <tomi.ollila@iki.fi>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 10 Feb 2014 18:42:17 -0000\r
+\r
+The definitions of Thread, output_with_separator, and print_view were\r
+between the main argparse and view-printing code. Group them together\r
+with our existing read_config at the top of the module, which makes\r
+for easier reading in the main section.\r
+\r
+I also:\r
+\r
+* Made 'headers' a print_view argument instead of a module-level\r
+ global. The list -> tuple conversion avoids having a mutable\r
+ default argument, which makes some people jumpy ;).\r
+\r
+* Made 'db' a print_view argument instead of relying on the global\r
+ namespace to access it from print_view.\r
+---\r
+ devel/nmbug/nmbug-status | 78 +++++++++++++++++++++++++-----------------------\r
+ 1 file changed, 40 insertions(+), 38 deletions(-)\r
+\r
+diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status\r
+index 22eeb5c..199892f 100755\r
+--- a/devel/nmbug/nmbug-status\r
++++ b/devel/nmbug/nmbug-status\r
+@@ -47,40 +47,6 @@ def read_config(path=None, encoding=None):\r
+ return json.load(fp)\r
+ \r
+ \r
+-# parse command line arguments\r
+-\r
+-parser = argparse.ArgumentParser()\r
+-parser.add_argument('--text', help='output plain text format',\r
+- action='store_true')\r
+-parser.add_argument('--config', help='load config from given file',\r
+- metavar='PATH')\r
+-parser.add_argument('--list-views', help='list views',\r
+- action='store_true')\r
+-parser.add_argument('--get-query', help='get query for view',\r
+- metavar='VIEW')\r
+-\r
+-args = parser.parse_args()\r
+-\r
+-config = read_config(path=args.config)\r
+-\r
+-if args.list_views:\r
+- for view in config['views']:\r
+- print(view['title'])\r
+- sys.exit(0)\r
+-elif args.get_query != None:\r
+- for view in config['views']:\r
+- if args.get_query == view['title']:\r
+- print(' and '.join(view['query']))\r
+- sys.exit(0)\r
+-else:\r
+- # only import notmuch if needed\r
+- import notmuch\r
+-\r
+-if args.text:\r
+- output_format = 'text'\r
+-else:\r
+- output_format = 'html'\r
+-\r
+ class Thread:\r
+ def __init__(self, last, lines):\r
+ self.last = last\r
+@@ -89,16 +55,17 @@ class Thread:\r
+ def join_utf8_with_newlines(self):\r
+ return '\n'.join( (line.encode('utf-8') for line in self.lines) )\r
+ \r
++\r
+ def output_with_separator(threadlist, sep):\r
+ outputs = (thread.join_utf8_with_newlines() for thread in threadlist)\r
+ print(sep.join(outputs))\r
+ \r
+-headers = ['date', 'from', 'subject']\r
+ \r
+-def print_view(title, query, comment):\r
++def print_view(database, title, query, comment,\r
++ headers=('date', 'from', 'subject')):\r
+ \r
+ query_string = ' and '.join(query)\r
+- q_new = notmuch.Query(db, query_string)\r
++ q_new = notmuch.Query(database, query_string)\r
+ q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST)\r
+ \r
+ last_thread_id = ''\r
+@@ -176,6 +143,41 @@ def print_view(title, query, comment):\r
+ else:\r
+ output_with_separator(threadlist, '\n\n')\r
+ \r
++\r
++# parse command line arguments\r
++\r
++parser = argparse.ArgumentParser()\r
++parser.add_argument('--text', help='output plain text format',\r
++ action='store_true')\r
++parser.add_argument('--config', help='load config from given file',\r
++ metavar='PATH')\r
++parser.add_argument('--list-views', help='list views',\r
++ action='store_true')\r
++parser.add_argument('--get-query', help='get query for view',\r
++ metavar='VIEW')\r
++\r
++args = parser.parse_args()\r
++\r
++config = read_config(path=args.config)\r
++\r
++if args.list_views:\r
++ for view in config['views']:\r
++ print(view['title'])\r
++ sys.exit(0)\r
++elif args.get_query != None:\r
++ for view in config['views']:\r
++ if args.get_query == view['title']:\r
++ print(' and '.join(view['query']))\r
++ sys.exit(0)\r
++else:\r
++ # only import notmuch if needed\r
++ import notmuch\r
++\r
++if args.text:\r
++ output_format = 'text'\r
++else:\r
++ output_format = 'html'\r
++\r
+ # main program\r
+ \r
+ db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)\r
+@@ -200,7 +202,7 @@ if output_format == 'html':\r
+ print('</ul>')\r
+ \r
+ for view in config['views']:\r
+- print_view(**view)\r
++ print_view(database=db, **view)\r
+ \r
+ if output_format == 'html':\r
+ print('</body>\n</html>')\r
+-- \r
+1.8.5.2.8.g0f6c0d1\r
+\r