Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / 12 / 10ef838d56aaf88413300a59b1074ab27dd167
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 3AEA6429E2E\r
6         for <notmuch@notmuchmail.org>; Mon,  3 Feb 2014 03:08:16 -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
9 X-Spam-Flag: NO\r
10 X-Spam-Score: 0\r
11 X-Spam-Level: \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
14         autolearn=disabled\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 Om6W-npM-SaK for <notmuch@notmuchmail.org>;\r
18         Mon,  3 Feb 2014 03:08:10 -0800 (PST)\r
19 Received: from qmta03.westchester.pa.mail.comcast.net\r
20         (qmta03.westchester.pa.mail.comcast.net [76.96.62.32])\r
21         by olra.theworths.org (Postfix) with ESMTP id 1B9CE431E64\r
22         for <notmuch@notmuchmail.org>; Mon,  3 Feb 2014 03:08:10 -0800 (PST)\r
23 Received: from omta24.westchester.pa.mail.comcast.net ([76.96.62.76])\r
24         by qmta03.westchester.pa.mail.comcast.net with comcast\r
25         id Mn1p1n0051ei1Bg53n891j; Mon, 03 Feb 2014 11:08:09 +0000\r
26 Received: from odin.tremily.us ([24.18.63.50])\r
27         by omta24.westchester.pa.mail.comcast.net with comcast\r
28         id Mn881n00F152l3L3kn89Mz; Mon, 03 Feb 2014 11:08:09 +0000\r
29 Received: from mjolnir.tremily.us (unknown [192.168.0.140])\r
30         by odin.tremily.us (Postfix) with ESMTPS id EE746FB4D4B;\r
31         Mon,  3 Feb 2014 03:00:39 -0800 (PST)\r
32 Received: (nullmailer pid 689 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 06/17] nmbug-status: Consolidate functions and main code\r
37 Date: Mon,  3 Feb 2014 02:59:24 -0800\r
38 Message-Id:\r
39  <43b389b156214bb07c09f36cd36fd9fa2ccebf5b.1391424512.git.wking@tremily.us>\r
40 X-Mailer: git-send-email 1.8.5.2.8.g0f6c0d1\r
41 In-Reply-To: <cover.1391424512.git.wking@tremily.us>\r
42 References: <cover.1391424512.git.wking@tremily.us>\r
43 In-Reply-To: <cover.1391424512.git.wking@tremily.us>\r
44 References: <cover.1391424512.git.wking@tremily.us>\r
45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net;\r
46         s=q20121106; t=1391425689;\r
47         bh=yMvCAOnnJi1PiHQdjnon2+E+kEYl22joo5zXYe+ylVs=;\r
48         h=Received:Received:Received:Received:From:To:Subject:Date:\r
49         Message-Id;\r
50         b=ljtft7MtzF2ZXrN21J4UBrJ2x7X5BE5yyzKWfG/STBGoGOchjOt/FP7FpizUx6E1J\r
51         wDCzK/k2sApv04tsPsfSJP6FqHIZ5GC7OEyIMpFi+E/CR5UGzBr6h55MYO0bR67Hg4\r
52         jK/OPt2MIqCekk0e++M+v+8B6jPR8w1cSk7SlWMXkX7/RcS4kaOEUusfJTxW/f+ycm\r
53         NrocLO6G5H+qZazvQd40AD7kdJVexug5o/e9Qr89/HixAGl972FyAWBPu9d6Sn+Sq1\r
54         chVhAVuvLHlxqVy6TcjFncjGiIVsx1eKYudIyKCRqHsHjNH7XSCWFeQtugXZ3A87WO\r
55         1O0LfAZEchlTA==\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Mon, 03 Feb 2014 11:08:16 -0000\r
69 \r
70 The definitions of Thread, output_with_separator, and print_view were\r
71 between the main argparse and view-printing code.  Group them together\r
72 with our existing read_config at the top of the module, which makes\r
73 for easier reading in the main section.\r
74 \r
75 I also:\r
76 \r
77 * Made 'headers' a print_view argument instead of a module-level\r
78   global.  The list -> tuple conversion avoids having a mutable\r
79   default argument, which makes some people jumpy ;).\r
80 \r
81 * Made 'db' a print_view argument instead of relying on the global\r
82   namespace to access it from print_view.\r
83 ---\r
84  devel/nmbug/nmbug-status | 78 +++++++++++++++++++++++++-----------------------\r
85  1 file changed, 40 insertions(+), 38 deletions(-)\r
86 \r
87 diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status\r
88 index 22eeb5c..199892f 100755\r
89 --- a/devel/nmbug/nmbug-status\r
90 +++ b/devel/nmbug/nmbug-status\r
91 @@ -47,40 +47,6 @@ def read_config(path=None, encoding=None):\r
92      return json.load(fp)\r
93  \r
94  \r
95 -# parse command line arguments\r
96 -\r
97 -parser = argparse.ArgumentParser()\r
98 -parser.add_argument('--text', help='output plain text format',\r
99 -                    action='store_true')\r
100 -parser.add_argument('--config', help='load config from given file',\r
101 -                    metavar='PATH')\r
102 -parser.add_argument('--list-views', help='list views',\r
103 -                    action='store_true')\r
104 -parser.add_argument('--get-query', help='get query for view',\r
105 -                    metavar='VIEW')\r
106 -\r
107 -args = parser.parse_args()\r
108 -\r
109 -config = read_config(path=args.config)\r
110 -\r
111 -if args.list_views:\r
112 -    for view in config['views']:\r
113 -        print(view['title'])\r
114 -    sys.exit(0)\r
115 -elif args.get_query != None:\r
116 -    for view in config['views']:\r
117 -        if args.get_query == view['title']:\r
118 -            print(' and '.join(view['query']))\r
119 -    sys.exit(0)\r
120 -else:\r
121 -    # only import notmuch if needed\r
122 -    import notmuch\r
123 -\r
124 -if args.text:\r
125 -    output_format = 'text'\r
126 -else:\r
127 -    output_format = 'html'\r
128 -\r
129  class Thread:\r
130      def __init__(self, last, lines):\r
131          self.last = last\r
132 @@ -89,16 +55,17 @@ class Thread:\r
133      def join_utf8_with_newlines(self):\r
134          return '\n'.join( (line.encode('utf-8') for line in self.lines) )\r
135  \r
136 +\r
137  def output_with_separator(threadlist, sep):\r
138      outputs = (thread.join_utf8_with_newlines() for thread in threadlist)\r
139      print(sep.join(outputs))\r
140  \r
141 -headers = ['date', 'from', 'subject']\r
142  \r
143 -def print_view(title, query, comment):\r
144 +def print_view(database, title, query, comment,\r
145 +               headers=('date', 'from', 'subject')):\r
146  \r
147      query_string = ' and '.join(query)\r
148 -    q_new = notmuch.Query(db, query_string)\r
149 +    q_new = notmuch.Query(database, query_string)\r
150      q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST)\r
151  \r
152      last_thread_id = ''\r
153 @@ -176,6 +143,41 @@ def print_view(title, query, comment):\r
154      else:\r
155          output_with_separator(threadlist, '\n\n')\r
156  \r
157 +\r
158 +# parse command line arguments\r
159 +\r
160 +parser = argparse.ArgumentParser()\r
161 +parser.add_argument('--text', help='output plain text format',\r
162 +                    action='store_true')\r
163 +parser.add_argument('--config', help='load config from given file',\r
164 +                    metavar='PATH')\r
165 +parser.add_argument('--list-views', help='list views',\r
166 +                    action='store_true')\r
167 +parser.add_argument('--get-query', help='get query for view',\r
168 +                    metavar='VIEW')\r
169 +\r
170 +args = parser.parse_args()\r
171 +\r
172 +config = read_config(path=args.config)\r
173 +\r
174 +if args.list_views:\r
175 +    for view in config['views']:\r
176 +        print(view['title'])\r
177 +    sys.exit(0)\r
178 +elif args.get_query != None:\r
179 +    for view in config['views']:\r
180 +        if args.get_query == view['title']:\r
181 +            print(' and '.join(view['query']))\r
182 +    sys.exit(0)\r
183 +else:\r
184 +    # only import notmuch if needed\r
185 +    import notmuch\r
186 +\r
187 +if args.text:\r
188 +    output_format = 'text'\r
189 +else:\r
190 +    output_format = 'html'\r
191 +\r
192  # main program\r
193  \r
194  db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)\r
195 @@ -200,7 +202,7 @@ if output_format == 'html':\r
196      print('</ul>')\r
197  \r
198  for view in config['views']:\r
199 -    print_view(**view)\r
200 +    print_view(database=db, **view)\r
201  \r
202  if output_format == 'html':\r
203      print('</body>\n</html>')\r
204 -- \r
205 1.8.5.2.8.g0f6c0d1\r
206 \r