1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
4 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
5 <title>nmbug report generator</title>
6 <link rel="stylesheet" type="text/css" href="highlight.css">
9 <pre class="hl"><span class="hl slc">#!/usr/bin/python</span>
10 <span class="hl slc">#</span>
11 <span class="hl slc"># Copyright © 2011 David Bremner <david@tethera.net></span>
12 <span class="hl slc"># License: Same as notmuch</span>
14 <span class="hl kwa">import</span> datetime
15 <span class="hl kwa">import</span> notmuch
16 <span class="hl kwa">import</span> sys
18 QUERY <span class="hl opt">=</span> <span class="hl str">"tag:notmuch::patch and not tag:notmuch::pushed"</span>
19 QUERY <span class="hl opt">+=</span> <span class="hl str">" and not tag:notmuch::obsolete and not tag:notmuch::wip"</span>
20 QUERY <span class="hl opt">+=</span> <span class="hl str">" and not tag:notmuch::stale and not tag:notmuch::contrib"</span>
21 QUERY <span class="hl opt">+=</span> <span class="hl str">" and not tag:notmuch::python and not tag:notmuch::vim"</span>
22 QUERY <span class="hl opt">+=</span> <span class="hl str">" and not tag:notmuch::moreinfo"</span>
24 <span class="hl kwa">def</span> <span class="hl kwd">html_row</span><span class="hl opt">(*</span>args<span class="hl opt">):</span>
25 <span class="hl kwa">print</span> <span class="hl str">' <tr><td>'</span>
26 <span class="hl kwa">print</span> <span class="hl str">' </td><td>'</span><span class="hl opt">.</span><span class="hl kwd">join</span><span class="hl opt">(</span>args<span class="hl opt">).</span><span class="hl kwd">encode</span><span class="hl opt">(</span><span class="hl str">'utf-8'</span><span class="hl opt">)</span>
27 <span class="hl kwa">print</span> <span class="hl str">' </td></tr>'</span>
29 db <span class="hl opt">=</span> notmuch<span class="hl opt">.</span><span class="hl kwd">Database</span><span class="hl opt">(</span>mode<span class="hl opt">=</span>notmuch<span class="hl opt">.</span>Database<span class="hl opt">.</span>MODE<span class="hl opt">.</span>READ_WRITE<span class="hl opt">)</span>
30 q_new <span class="hl opt">=</span> notmuch<span class="hl opt">.</span><span class="hl kwd">Query</span><span class="hl opt">(</span>db<span class="hl opt">,</span> QUERY<span class="hl opt">)</span>
31 q_new<span class="hl opt">.</span><span class="hl kwd">set_sort</span><span class="hl opt">(</span>notmuch<span class="hl opt">.</span>Query<span class="hl opt">.</span>SORT<span class="hl opt">.</span>OLDEST_FIRST<span class="hl opt">)</span>
33 headers <span class="hl opt">= [</span><span class="hl str">'date'</span><span class="hl opt">,</span><span class="hl str">'from'</span><span class="hl opt">,</span><span class="hl str">'subject'</span><span class="hl opt">]</span>
34 last <span class="hl opt">= {}</span>
36 <span class="hl kwa">for</span> header <span class="hl kwa">in</span> headers<span class="hl opt">:</span>
37 last<span class="hl opt">[</span>header<span class="hl opt">] =</span> <span class="hl kwa">None</span>
39 <span class="hl kwa">print</span> <span class="hl str">'<h2>Notmuch Patches</h2>'</span>
41 <span class="hl kwa">print</span> <span class="hl str">'Generated: %s<br>'</span> <span class="hl opt">%</span> datetime<span class="hl opt">.</span>date<span class="hl opt">.</span><span class="hl kwd">today</span><span class="hl opt">()</span>
43 <span class="hl kwa">print</span> <span class="hl str">'For more infomation see <a href="http://notmuchmail.org/nmbug">nmbug</a>'</span>
45 <span class="hl kwa">print</span> <span class="hl str">'<h3>Query</h3>'</span>
46 <span class="hl kwa">print</span> QUERY
48 <span class="hl kwa">print</span> <span class="hl str">'<h3>Result</h3>'</span>
51 <span class="hl kwa">print</span> <span class="hl str">'<table>'</span>
52 <span class="hl kwa">for</span> m <span class="hl kwa">in</span> q_new<span class="hl opt">.</span><span class="hl kwd">search_messages</span><span class="hl opt">():</span>
54 out <span class="hl opt">= {};</span>
56 <span class="hl kwa">for</span> header <span class="hl kwa">in</span> headers<span class="hl opt">:</span>
57 <span class="hl kwa">if</span> header <span class="hl opt">!=</span> <span class="hl str">'date'</span><span class="hl opt">:</span>
58 val <span class="hl opt">=</span> m<span class="hl opt">.</span><span class="hl kwd">get_header</span><span class="hl opt">(</span>header<span class="hl opt">)</span>
59 <span class="hl kwa">else</span><span class="hl opt">:</span>
60 val <span class="hl opt">=</span> datetime<span class="hl opt">.</span>date<span class="hl opt">.</span><span class="hl kwd">fromtimestamp</span><span class="hl opt">(</span>m<span class="hl opt">.</span><span class="hl kwd">get_date</span><span class="hl opt">()).</span><span class="hl kwd">isoformat</span><span class="hl opt">()</span>
62 <span class="hl kwa">if</span> last<span class="hl opt">[</span>header<span class="hl opt">] ==</span> val<span class="hl opt">:</span>
63 out<span class="hl opt">[</span>header<span class="hl opt">] =</span> <span class="hl str">""</span>
64 <span class="hl kwa">else</span><span class="hl opt">:</span>
65 out<span class="hl opt">[</span>header<span class="hl opt">] =</span> val
66 last<span class="hl opt">[</span>header<span class="hl opt">] =</span> val
68 mid<span class="hl opt">=</span>m<span class="hl opt">.</span><span class="hl kwd">get_message_id</span><span class="hl opt">()</span>
70 out<span class="hl opt">[</span><span class="hl str">'id'</span><span class="hl opt">] =</span> <span class="hl str">'<a href=http://mid.gmane.org/%s>id:%s</a>'</span> <span class="hl opt">% (</span>mid<span class="hl opt">,</span>mid<span class="hl opt">)</span>
72 <span class="hl kwd">html_row</span><span class="hl opt">(</span>out<span class="hl opt">[</span><span class="hl str">'date'</span><span class="hl opt">],</span>out<span class="hl opt">[</span><span class="hl str">'from'</span><span class="hl opt">],</span>out<span class="hl opt">[</span><span class="hl str">'subject'</span><span class="hl opt">],</span>out<span class="hl opt">[</span><span class="hl str">'id'</span><span class="hl opt">])</span>
74 <span class="hl slc"># print '%(date)-10.10s %(from)-20.20s %(subject)-40.40s id:%(id)s' % out</span>
75 <span class="hl kwa">print</span> <span class="hl str">'</table>'</span>
79 <!--HTML generated by highlight 3.5, http://www.andre-simon.de/-->