]> git.cworth.org Git - notmuch-wiki/blob - nmbug/report.py.mdwn
add description of "tag macros" for emacs.
[notmuch-wiki] / nmbug / report.py.mdwn
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2 <html>
3 <head>
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">
7 </head>
8 <body class="hl">
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 &lt;david&#64;tethera.net&gt;</span>
12 <span class="hl slc"># License: Same as notmuch</span>
13
14 <span class="hl kwa">import</span> datetime
15 <span class="hl kwa">import</span> notmuch
16 <span class="hl kwa">import</span> sys
17
18 QUERY <span class="hl opt">=</span> <span class="hl str">&quot;tag:notmuch::patch and not tag:notmuch::pushed&quot;</span>
19 QUERY <span class="hl opt">+=</span> <span class="hl str">&quot;  and not tag:notmuch::obsolete and not tag:notmuch::wip&quot;</span>
20 QUERY <span class="hl opt">+=</span> <span class="hl str">&quot; and not tag:notmuch::stale and not tag:notmuch::contrib&quot;</span>
21 QUERY <span class="hl opt">+=</span> <span class="hl str">&quot; and not tag:notmuch::python and not tag:notmuch::vim&quot;</span>
22 QUERY <span class="hl opt">+=</span> <span class="hl str">&quot; and not tag:notmuch::moreinfo&quot;</span>
23
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">'  &lt;tr&gt;&lt;td&gt;'</span>
26     <span class="hl kwa">print</span> <span class="hl str">'    &lt;/td&gt;&lt;td&gt;'</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">'  &lt;/td&gt;&lt;/tr&gt;'</span>
28
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>
32
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>
35
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>
38
39 <span class="hl kwa">print</span> <span class="hl str">'&lt;h2&gt;Notmuch Patches&lt;/h2&gt;'</span>
40
41 <span class="hl kwa">print</span> <span class="hl str">'Generated: %s&lt;br&gt;'</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>
42
43 <span class="hl kwa">print</span> <span class="hl str">'For more infomation see &lt;a href=&quot;http://notmuchmail.org/nmbug&quot;&gt;nmbug&lt;/a&gt;'</span>
44
45 <span class="hl kwa">print</span> <span class="hl str">'&lt;h3&gt;Query&lt;/h3&gt;'</span>
46 <span class="hl kwa">print</span> QUERY
47
48 <span class="hl kwa">print</span> <span class="hl str">'&lt;h3&gt;Result&lt;/h3&gt;'</span>
49
50
51 <span class="hl kwa">print</span> <span class="hl str">'&lt;table&gt;'</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>
53
54     out <span class="hl opt">= {};</span>
55
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>
61
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">&quot;&quot;</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
67
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>
69
70     out<span class="hl opt">[</span><span class="hl str">'id'</span><span class="hl opt">] =</span> <span class="hl str">'&lt;a href=http://mid.gmane.org/%s&gt;id:%s&lt;/a&gt;'</span> <span class="hl opt">% (</span>mid<span class="hl opt">,</span>mid<span class="hl opt">)</span>
71
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>
73
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">'&lt;/table&gt;'</span>
76 </pre>
77 </body>
78 </html>
79 <!--HTML generated by highlight 3.5, http://www.andre-simon.de/-->