Re: [PATCH v4 13/16] add indexopts to notmuch python bindings.
[notmuch-archives.git] / 8b / 149676c20b9a4bb297958877a91f0561b6eba2
1 Return-Path: <bremner@tesseract.cs.unb.ca>\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 BBADB431FBC\r
6         for <notmuch@notmuchmail.org>; Sun,  8 Jul 2012 22:09:20 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id v7+e3PUe27Ra for <notmuch@notmuchmail.org>;\r
16         Sun,  8 Jul 2012 22:09:18 -0700 (PDT)\r
17 Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])\r
18         (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id EC803431FAE\r
21         for <notmuch@notmuchmail.org>; Sun,  8 Jul 2012 22:09:17 -0700 (PDT)\r
22 Received: from remotemail by tesseract.cs.unb.ca with local (Exim 4.72)\r
23         (envelope-from <bremner@tesseract.cs.unb.ca>)\r
24         id 1So6Di-0004dM-Ky; Mon, 09 Jul 2012 02:09:14 -0300\r
25 Received: (nullmailer pid 29417 invoked by uid 1000);\r
26         Mon, 09 Jul 2012 05:09:08 -0000\r
27 From: david@tethera.net\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [PATCH v2] contrib/nmbug: add nmbug-status script\r
30 Date: Sun,  8 Jul 2012 23:09:06 -0600\r
31 Message-Id: <1341810546-28857-1-git-send-email-david@tethera.net>\r
32 X-Mailer: git-send-email 1.7.10\r
33 In-Reply-To: <1341689754-15243-2-git-send-email-david@tethera.net>\r
34 References: <1341689754-15243-2-git-send-email-david@tethera.net>\r
35 Cc: David Bremner <bremner@debian.org>\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.13\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40         <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
42         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
44 List-Post: <mailto:notmuch@notmuchmail.org>\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Mon, 09 Jul 2012 05:09:20 -0000\r
49 \r
50 From: David Bremner <bremner@debian.org>\r
51 \r
52 This is (almost) the same script as has been used for\r
53 http://nmbug.tethera.net/status for a while now. The only change is\r
54 that the configuration is not hardcoded anymore. By default the config\r
55 is fetched from a special branch in the nmbug repo that contains only\r
56 config info. The idea is that push access to this branch can be\r
57 restricted a bit more than the tags, since it will change the\r
58 appearence of the web pages.\r
59 ---\r
60 \r
61 The change here is to extract the configuration from a branch in the\r
62 nmbug repo. This will allow multiple people to update the layout of the status page.\r
63 \r
64  contrib/nmbug/nmbug-status       |  141 ++++++++++++++++++++++++++++++++++++++\r
65  contrib/nmbug/status-config.json |   65 ++++++++++++++++++\r
66  2 files changed, 206 insertions(+)\r
67  create mode 100755 contrib/nmbug/nmbug-status\r
68  create mode 100644 contrib/nmbug/status-config.json\r
69 \r
70 diff --git a/contrib/nmbug/nmbug-status b/contrib/nmbug/nmbug-status\r
71 new file mode 100755\r
72 index 0000000..cee9d3d\r
73 --- /dev/null\r
74 +++ b/contrib/nmbug/nmbug-status\r
75 @@ -0,0 +1,141 @@\r
76 +#!/usr/bin/python\r
77 +#\r
78 +# Copyright (c) 2011-2012 David Bremner <david@tethera.net>\r
79 +# License: Same as notmuch\r
80 +# dependencies\r
81 +#       - python 2.6 for json\r
82 +#       - argparse; either python 2.7, or install seperately\r
83 +\r
84 +import datetime\r
85 +import notmuch\r
86 +import sys\r
87 +import rfc822\r
88 +import urllib\r
89 +import json\r
90 +import argparse\r
91 +import os\r
92 +import subprocess\r
93 +\r
94 +# parse command line arguments\r
95 +\r
96 +parser = argparse.ArgumentParser()\r
97 +parser.add_argument("--text", help="output plain text format",\r
98 +                   action="store_true")\r
99 +\r
100 +parser.add_argument("--config", help="load config from given file")\r
101 +\r
102 +\r
103 +args = parser.parse_args()\r
104 +\r
105 +# read config from json file\r
106 +\r
107 +if args.config != None:\r
108 +    fp = open(args.config)\r
109 +else:\r
110 +    nmbhome = os.getenv('NMBGIT',os.path.expanduser("~/.nmbug"))\r
111 +\r
112 +    fp =  subprocess.Popen(['git','--git-dir',nmbhome,\r
113 +                            'cat-file','blob','config:status-config.json'],\r
114 +                           stdout=subprocess.PIPE).stdout\r
115 +\r
116 +config=json.load(fp)\r
117 +\r
118 +if args.text:\r
119 +    format = 'text'\r
120 +else:\r
121 +    format = 'html'\r
122 +\r
123 +headers = ['date', 'from', 'subject']\r
124 +last = {}\r
125 +\r
126 +def clear_last():\r
127 +    for header in headers:\r
128 +       last[header] = ''\r
129 +\r
130 +def print_view(title, query, comment):\r
131 +\r
132 +    query_string = " and ".join(query)\r
133 +    q_new = notmuch.Query(db, query_string)\r
134 +    q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST)\r
135 +\r
136 +\r
137 +    last['thread_id'] = ''\r
138 +\r
139 +    if format == 'html':\r
140 +       print '<h3>%s</h3>' % title\r
141 +       print comment\r
142 +       print 'The view is generated from the following query:'\r
143 +       print '<blockquote>'\r
144 +       print query_string\r
145 +       print '</blockquote>'\r
146 +       print '<table>\n'\r
147 +\r
148 +    for m in q_new.search_messages():\r
149 +\r
150 +       out = {};\r
151 +\r
152 +       thread_id = m.get_thread_id()\r
153 +       if thread_id != last['thread_id']:\r
154 +           clear_last()\r
155 +\r
156 +       for header in headers:\r
157 +           val = m.get_header(header)\r
158 +\r
159 +           if header == 'date':\r
160 +               val = str.join(' ', val.split(None)[1:4])\r
161 +               val = str(datetime.datetime.strptime(val, '%d %b %Y').date())\r
162 +           elif header == 'from':\r
163 +               val = rfc822.parseaddr(val)[0]\r
164 +\r
165 +           if last[header] == val:\r
166 +               out[header] = ""\r
167 +           else:\r
168 +               out[header] = val.encode('utf-8')\r
169 +               last[header] = val\r
170 +\r
171 +       mid = m.get_message_id()\r
172 +       out['id'] = 'id:"%s"' % mid\r
173 +\r
174 +       if format == 'html':\r
175 +           # XXX using <br /> is a hack, but ... // 20111216 too\r
176 +           if thread_id != last['thread_id']:\r
177 +               br = '<br />'\r
178 +           else:\r
179 +               br = ''\r
180 +           out['subject'] = '<a href="http://mid.gmane.org/%s">%s</a>' % (urllib.quote(mid), out['subject'])\r
181 +           print " <tr><td>%s %s" % (br, out['date'])\r
182 +           print "</td><td>%s %s" % (br, out['id'])\r
183 +           print "</td></tr>"\r
184 +           print " <tr><td>%s" % out['from']\r
185 +           print "</td><td>%s" % out['subject']\r
186 +           print "</td></tr>\n"\r
187 +       else:\r
188 +           print '%(date)-10.10s %(from)-20.20s %(subject)-40.40s\n%(id)72s\n' % out\r
189 +\r
190 +       last['thread_id'] = thread_id\r
191 +\r
192 +    if format == 'html':\r
193 +       print '</table>'\r
194 +\r
195 +# main program\r
196 +\r
197 +db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)\r
198 +\r
199 +if format == 'html':\r
200 +    print '''<?xml version="1.0" encoding="utf-8" ?>\r
201 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
202 +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\r
203 +<head>\r
204 +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r
205 +<title>Notmuch Patches</title>\r
206 +</head>\r
207 +<body>''';\r
208 +    print '<h2>Notmuch Patches</h2>'\r
209 +    print 'Generated: %s<br />' % datetime.datetime.utcnow().date()\r
210 +    print 'For more infomation see <a href="http://notmuchmail.org/nmbug">nmbug</a>'\r
211 +\r
212 +for view in config['views']:\r
213 +    print_view(**view)\r
214 +\r
215 +if format == 'html':\r
216 +    print '</body>\n</html>'\r
217 diff --git a/contrib/nmbug/status-config.json b/contrib/nmbug/status-config.json\r
218 new file mode 100644\r
219 index 0000000..6b4934f\r
220 --- /dev/null\r
221 +++ b/contrib/nmbug/status-config.json\r
222 @@ -0,0 +1,65 @@\r
223 +{\r
224 +    "views": [\r
225 +       {\r
226 +           "comment": "Unresolved bugs (or just need tag updating).",\r
227 +           "query": [\r
228 +               "tag:notmuch::bug",\r
229 +               "not tag:notmuch::fixed",\r
230 +               "not tag:notmuch::wontfix"\r
231 +           ],\r
232 +           "title": "Bugs"\r
233 +       },\r
234 +       {\r
235 +           "comment": "These patches are under consideration for pushing.",\r
236 +           "query": [\r
237 +               "tag:notmuch::patch and not tag:notmuch::pushed",\r
238 +               "not tag:notmuch::obsolete and not tag:notmuch::wip",\r
239 +               "not tag:notmuch::stale and not tag:notmuch::contrib",\r
240 +               "not tag:notmuch::moreinfo",\r
241 +               "not tag:notmuch::python",\r
242 +               "not tag:notmuch::vim",\r
243 +               "not tag:notmuch::wontfix",\r
244 +               "not tag:notmuch::needs-review"\r
245 +           ],\r
246 +           "title": "Maybe Ready (Core and Emacs)"\r
247 +       },\r
248 +       {\r
249 +           "comment": "These python related patches might be ready to push, or they might just need updated tags.",\r
250 +           "query": [\r
251 +               "tag:notmuch::patch and not tag:notmuch::pushed",\r
252 +               "not tag:notmuch::obsolete and not tag:notmuch::wip",\r
253 +               "not tag:notmuch::stale and not tag:notmuch::contrib",\r
254 +               "not tag:notmuch::moreinfo",\r
255 +               "not tag:notmuch::wontfix",\r
256 +               " tag:notmuch::python",\r
257 +               "not tag:notmuch::needs-review"\r
258 +           ],\r
259 +           "title": "Maybe Ready (Python)"\r
260 +       },\r
261 +       {\r
262 +           "comment": "These vim related patches might be ready to push, or they might just need updated tags.",\r
263 +           "query": [\r
264 +               "tag:notmuch::patch and not tag:notmuch::pushed",\r
265 +               "not tag:notmuch::obsolete and not tag:notmuch::wip",\r
266 +               "not tag:notmuch::stale and not tag:notmuch::contrib",\r
267 +               "not tag:notmuch::moreinfo",\r
268 +               "not tag:notmuch::wontfix",\r
269 +               "tag:notmuch::vim",\r
270 +               "not tag:notmuch::needs-review"\r
271 +           ],\r
272 +           "title": "Maybe Ready (vim)"\r
273 +       },\r
274 +       {\r
275 +           "comment": "These patches are under review, or waiting for feedback.",\r
276 +           "query": [\r
277 +               "tag:notmuch::patch",\r
278 +               "not tag:notmuch::pushed",\r
279 +               "not tag:notmuch::obsolete",\r
280 +               "not tag:notmuch::stale",\r
281 +               "not tag:notmuch::wontfix",\r
282 +               "(tag:notmuch::moreinfo or tag:notmuch::needs-review)"\r
283 +           ],\r
284 +           "title": "Review"\r
285 +       }\r
286 +    ]\r
287 +}\r
288 -- \r
289 1.7.10\r
290 \r