Re: Hi all
[notmuch-archives.git] / 1f / 90fe354070de5e66a820d84584dbdd65ab8082
1 Return-Path: <james@hackervisions.org>\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 A7333431FBF\r
6         for <notmuch@notmuchmail.org>; Fri, 26 Feb 2010 04:53:43 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.05\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.05 tagged_above=-999 required=5 tests=[AWL=-0.151,\r
12         BAYES_50=0.001, RDNS_DYNAMIC=0.1] autolearn=no\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 tOtQZsqAukzj for <notmuch@notmuchmail.org>;\r
16         Fri, 26 Feb 2010 04:53:42 -0800 (PST)\r
17 Received: from hackervisions.org (67-207-143-141.slicehost.net\r
18         [67.207.143.141])\r
19         by olra.theworths.org (Postfix) with ESMTP id C7D73431FAE\r
20         for <notmuch@notmuchmail.org>; Fri, 26 Feb 2010 04:53:42 -0800 (PST)\r
21 Received: from ool-18bd392a.dyn.optonline.net ([24.189.57.42] helo=localhost)\r
22         by hv with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.69)\r
23         (envelope-from <james@hackervisions.org>) id 1NkzhK-0003o1-6b\r
24         for notmuch@notmuchmail.org; Fri, 26 Feb 2010 07:53:38 -0500\r
25 From: James Vasile <james@hackervisions.org>\r
26 To: notmuch@notmuchmail.org\r
27 Date: Fri, 26 Feb 2010 07:53:29 -0500\r
28 Message-ID: <87pr3sw43a.fsf@hackervisions.org>\r
29 MIME-Version: 1.0\r
30 Content-Type: text/plain; charset=us-ascii\r
31 Subject: [notmuch] [PATCH] Add shell script notmuch-retry\r
32 X-BeenThere: notmuch@notmuchmail.org\r
33 X-Mailman-Version: 2.1.13\r
34 Precedence: list\r
35 List-Id: "Use and development of the notmuch mail system."\r
36         <notmuch.notmuchmail.org>\r
37 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
38         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
39 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
40 List-Post: <mailto:notmuch@notmuchmail.org>\r
41 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
42 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
43         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
44 X-List-Received-Date: Fri, 26 Feb 2010 12:53:43 -0000\r
45 \r
46 It occurs to me that having generic ability to tell notmuch to retry\r
47 until the DB isn't locked might useful.  So I put the functionality in a\r
48 script that can sit between notmuch and various clients.  It will\r
49 simplify my emacs setup, and improve it since emacs's handling of\r
50 asynchronous processes isn't great.\r
51 \r
52 This script calls notmuch and passes on all commandline arguments.  If\r
53 DB is locked, keep trying notmuch until the DB isn't locked.  Notmuch's\r
54 stdout and stderr go to stdout and stderr.  Returns notmuch's return\r
55 code.\r
56 \r
57 Maybe this retry loop should be put in notmuch itself?\r
58 \r
59 ---\r
60  notmuch-retry |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
61  1 files changed, 51 insertions(+), 0 deletions(-)\r
62  create mode 100755 notmuch-retry\r
63 \r
64 diff --git a/notmuch-retry b/notmuch-retry\r
65 new file mode 100755\r
66 index 0000000..2d7fcbc\r
67 --- /dev/null\r
68 +++ b/notmuch-retry\r
69 @@ -0,0 +1,51 @@\r
70 +#!/bin/bash\r
71 +#\r
72 +# notmuch-retry --- call notmuch and retry if DB is locked\r
73 +#\r
74 +# Calls notmuch and passes on all commandline arguments.  If DB is\r
75 +# locked, keep trying notmuch until the DB isn't locked.  Notmuch's\r
76 +# stdout and stderr go to stdout and stderr.  Returns notmuch's return\r
77 +# code.\r
78 +#\r
79 +# Copyright 2010 James Vasile\r
80 +#\r
81 +# This is free software: you can redistribute it and/or modify it\r
82 +# under the terms of the GNU General Public License as published by\r
83 +# the Free Software Foundation, either version 3 of the License, or\r
84 +# (at your option) any later version.\r
85 +#\r
86 +# This software is distributed in the hope that it will be useful, but\r
87 +# WITHOUT ANY WARRANTY; without even the implied warranty of\r
88 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
89 +# General Public License for more details.\r
90 +#\r
91 +# You should have received a copy of the GNU General Public License\r
92 +# along with this software.  If not, see\r
93 +# <http://www.gnu.org/licenses/>.\r
94 +#\r
95 +# Authors: James Vasile <james@hackervisions.org>\r
96 +\r
97 +bin=`which notmuch`\r
98 +\r
99 +notmuch_retry () {    \r
100 +    regex="already locked"\r
101 +    while [ 1 -gt 0 ]; do\r
102 +       $bin $@ 2>$err\r
103 +       retcode=$?\r
104 +       result=$(<$err)\r
105 +       if [[ $result =~ $regex ]]; then\r
106 +           sleep 2.5\r
107 +       else\r
108 +           if [ -n "$result" ]; then\r
109 +               echo $result >&2\r
110 +           fi\r
111 +           return $retcode\r
112 +       fi\r
113 +    done\r
114 +}\r
115 +\r
116 +err=$(mktemp)\r
117 +notmuch_retry $@\r
118 +retcode=$?\r
119 +rm $err\r
120 +exit $retcode\r
121 -- \r
122 1.6.3.3\r
123 \r