Re: database error
[notmuch-archives.git] / 1a / 6ba0a4f41039b18bc185b7046dacbdc0c40594
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 0F345431FAF\r
6         for <notmuch@notmuchmail.org>; Mon, 10 Feb 2014 10:42:17 -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 pt8eCdaLPHKn for <notmuch@notmuchmail.org>;\r
18         Mon, 10 Feb 2014 10:42:11 -0800 (PST)\r
19 Received: from qmta12.westchester.pa.mail.comcast.net\r
20         (qmta12.westchester.pa.mail.comcast.net [76.96.59.227])\r
21         by olra.theworths.org (Postfix) with ESMTP id 61E52431FDF\r
22         for <notmuch@notmuchmail.org>; Mon, 10 Feb 2014 10:41:56 -0800 (PST)\r
23 Received: from omta15.westchester.pa.mail.comcast.net ([76.96.62.87])\r
24         by qmta12.westchester.pa.mail.comcast.net with comcast\r
25         id QiCj1n0081swQuc5Cihw5l; Mon, 10 Feb 2014 18:41:56 +0000\r
26 Received: from odin.tremily.us ([24.18.63.50])\r
27         by omta15.westchester.pa.mail.comcast.net with comcast\r
28         id Qihu1n00b152l3L3bihvdS; Mon, 10 Feb 2014 18:41:56 +0000\r
29 Received: from mjolnir.tremily.us (unknown [192.168.0.140])\r
30         by odin.tremily.us (Postfix) with ESMTPS id 8D72010167AD;\r
31         Mon, 10 Feb 2014 10:41:54 -0800 (PST)\r
32 Received: (nullmailer pid 1255 invoked by uid 1000);\r
33         Mon, 10 Feb 2014 18:40:44 -0000\r
34 From: "W. Trevor King" <wking@tremily.us>\r
35 To: notmuch@notmuchmail.org\r
36 Subject: [PATCH v2 06/20] nmbug-status: Consolidate functions and main code\r
37 Date: Mon, 10 Feb 2014 10:40:27 -0800\r
38 Message-Id:\r
39  <43b389b156214bb07c09f36cd36fd9fa2ccebf5b.1392056624.git.wking@tremily.us>\r
40 X-Mailer: git-send-email 1.8.5.2.8.g0f6c0d1\r
41 In-Reply-To: <cover.1392056624.git.wking@tremily.us>\r
42 References: <cover.1392056624.git.wking@tremily.us>\r
43 In-Reply-To: <cover.1392056624.git.wking@tremily.us>\r
44 References: <cover.1392056624.git.wking@tremily.us>\r
45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net;\r
46         s=q20121106; t=1392057716;\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=bxmgbBkbZ6uZdNj/k5H6p17VIYv+XKt9hOgIWYOUeEpo2syEw8mpQkqyymDG22Lry\r
51         bC/dd9rBO35PCyQBZ6//54pLiy0urp2s3RFnzcWAClCGHumbnwYB3t/UgSGLlfpIXD\r
52         vZNIZblPl02Aj6jZdG/aXeoGQdR4yOJFbrN0I2SVeG28QG/8s9xSTHsWwHdwMhm+qQ\r
53         T9niWQH/Xi9D3+2lWx3vIjzoPOo7AY2Kj4i2rkd6K9SvdovmJ1u3pe3yeQ0l9DfLrY\r
54         Ts2gO/mzPBcZdqBOdzog0o063uH13jB++iqVzJzBvJyswKYUDU/0Q9K7FHGH49E3sR\r
55         Z2agrjmdMKVwA==\r
56 Cc: Tomi Ollila <tomi.ollila@iki.fi>\r
57 X-BeenThere: notmuch@notmuchmail.org\r
58 X-Mailman-Version: 2.1.13\r
59 Precedence: list\r
60 List-Id: "Use and development of the notmuch mail system."\r
61         <notmuch.notmuchmail.org>\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
65 List-Post: <mailto:notmuch@notmuchmail.org>\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
69 X-List-Received-Date: Mon, 10 Feb 2014 18:42:17 -0000\r
70 \r
71 The definitions of Thread, output_with_separator, and print_view were\r
72 between the main argparse and view-printing code.  Group them together\r
73 with our existing read_config at the top of the module, which makes\r
74 for easier reading in the main section.\r
75 \r
76 I also:\r
77 \r
78 * Made 'headers' a print_view argument instead of a module-level\r
79   global.  The list -> tuple conversion avoids having a mutable\r
80   default argument, which makes some people jumpy ;).\r
81 \r
82 * Made 'db' a print_view argument instead of relying on the global\r
83   namespace to access it from print_view.\r
84 ---\r
85  devel/nmbug/nmbug-status | 78 +++++++++++++++++++++++++-----------------------\r
86  1 file changed, 40 insertions(+), 38 deletions(-)\r
87 \r
88 diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status\r
89 index 22eeb5c..199892f 100755\r
90 --- a/devel/nmbug/nmbug-status\r
91 +++ b/devel/nmbug/nmbug-status\r
92 @@ -47,40 +47,6 @@ def read_config(path=None, encoding=None):\r
93      return json.load(fp)\r
94  \r
95  \r
96 -# parse command line arguments\r
97 -\r
98 -parser = argparse.ArgumentParser()\r
99 -parser.add_argument('--text', help='output plain text format',\r
100 -                    action='store_true')\r
101 -parser.add_argument('--config', help='load config from given file',\r
102 -                    metavar='PATH')\r
103 -parser.add_argument('--list-views', help='list views',\r
104 -                    action='store_true')\r
105 -parser.add_argument('--get-query', help='get query for view',\r
106 -                    metavar='VIEW')\r
107 -\r
108 -args = parser.parse_args()\r
109 -\r
110 -config = read_config(path=args.config)\r
111 -\r
112 -if args.list_views:\r
113 -    for view in config['views']:\r
114 -        print(view['title'])\r
115 -    sys.exit(0)\r
116 -elif args.get_query != None:\r
117 -    for view in config['views']:\r
118 -        if args.get_query == view['title']:\r
119 -            print(' and '.join(view['query']))\r
120 -    sys.exit(0)\r
121 -else:\r
122 -    # only import notmuch if needed\r
123 -    import notmuch\r
124 -\r
125 -if args.text:\r
126 -    output_format = 'text'\r
127 -else:\r
128 -    output_format = 'html'\r
129 -\r
130  class Thread:\r
131      def __init__(self, last, lines):\r
132          self.last = last\r
133 @@ -89,16 +55,17 @@ class Thread:\r
134      def join_utf8_with_newlines(self):\r
135          return '\n'.join( (line.encode('utf-8') for line in self.lines) )\r
136  \r
137 +\r
138  def output_with_separator(threadlist, sep):\r
139      outputs = (thread.join_utf8_with_newlines() for thread in threadlist)\r
140      print(sep.join(outputs))\r
141  \r
142 -headers = ['date', 'from', 'subject']\r
143  \r
144 -def print_view(title, query, comment):\r
145 +def print_view(database, title, query, comment,\r
146 +               headers=('date', 'from', 'subject')):\r
147  \r
148      query_string = ' and '.join(query)\r
149 -    q_new = notmuch.Query(db, query_string)\r
150 +    q_new = notmuch.Query(database, query_string)\r
151      q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST)\r
152  \r
153      last_thread_id = ''\r
154 @@ -176,6 +143,41 @@ def print_view(title, query, comment):\r
155      else:\r
156          output_with_separator(threadlist, '\n\n')\r
157  \r
158 +\r
159 +# parse command line arguments\r
160 +\r
161 +parser = argparse.ArgumentParser()\r
162 +parser.add_argument('--text', help='output plain text format',\r
163 +                    action='store_true')\r
164 +parser.add_argument('--config', help='load config from given file',\r
165 +                    metavar='PATH')\r
166 +parser.add_argument('--list-views', help='list views',\r
167 +                    action='store_true')\r
168 +parser.add_argument('--get-query', help='get query for view',\r
169 +                    metavar='VIEW')\r
170 +\r
171 +args = parser.parse_args()\r
172 +\r
173 +config = read_config(path=args.config)\r
174 +\r
175 +if args.list_views:\r
176 +    for view in config['views']:\r
177 +        print(view['title'])\r
178 +    sys.exit(0)\r
179 +elif args.get_query != None:\r
180 +    for view in config['views']:\r
181 +        if args.get_query == view['title']:\r
182 +            print(' and '.join(view['query']))\r
183 +    sys.exit(0)\r
184 +else:\r
185 +    # only import notmuch if needed\r
186 +    import notmuch\r
187 +\r
188 +if args.text:\r
189 +    output_format = 'text'\r
190 +else:\r
191 +    output_format = 'html'\r
192 +\r
193  # main program\r
194  \r
195  db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)\r
196 @@ -200,7 +202,7 @@ if output_format == 'html':\r
197      print('</ul>')\r
198  \r
199  for view in config['views']:\r
200 -    print_view(**view)\r
201 +    print_view(database=db, **view)\r
202  \r
203  if output_format == 'html':\r
204      print('</body>\n</html>')\r
205 -- \r
206 1.8.5.2.8.g0f6c0d1\r
207 \r