notmuch: Make modifications to implement notmuch search

This commit is contained in:
Jesse Rosenthal 2010-03-25 15:17:31 +01:00
parent bdc3a95bb7
commit 46d06838ae

45
notmuch
View file

@ -1,10 +1,14 @@
#!/usr/bin/env python #!/usr/bin/env python
"""This is a notmuch implementation in python. It's goal is to allow running the test suite on the cnotmuch python bindings. """This is a notmuch implementation in python.
It's goal is to allow running the test suite on the cnotmuch python bindings.
This "binary" honors the NOTMUCH_CONFIG environmen variable for reading a user's This "binary" honors the NOTMUCH_CONFIG environmen variable for reading a user's
notmuch configuration (e.g. the database path) notmuch configuration (e.g. the database path).
This code is licensed under the GNU GPL v3+.""" (c) 2010 by Sebastian Spaeth <Sebastian@SSpaeth.de>
Jesse Rosenthal <jrosenthal@jhu.edu>
This code is licensed under the GNU GPL v3+.
"""
from __future__ import with_statement # This isn't required in Python 2.6 from __future__ import with_statement # This isn't required in Python 2.6
import sys, os, re, logging import sys, os, re, logging
from subprocess import call from subprocess import call
@ -299,16 +303,45 @@ if __name__ == '__main__':
#------------------------------------- #-------------------------------------
elif sys.argv[1] == 'show': elif sys.argv[1] == 'show':
db = Database() db = Database()
out_format="text"
if len(sys.argv) == 2: if len(sys.argv) == 2:
#no further search term #no further search term
querystr='' querystr=''
elif sys.argv[2].startswith("--format="):
out_format = sys.argv[2].split("=")[1].strip()
if not out_format in ("json", "text"):
raise Exception("unknown format")
if len(sys.argv) == 3:
querystr = ''
else:
querystr = quote_query_line(sys.argv[3:])
else: else:
#mangle arguments wrapping terms with spaces in quotes #mangle arguments wrapping terms with spaces in quotes
querystr = quote_query_line(sys.argv[2:]) querystr = quote_query_line(sys.argv[2:])
logging.debug("show "+querystr) logging.debug("show "+querystr)
m = Query(db,querystr).search_messages() t = Query(db,querystr).search_threads()
for msg in m:
print(msg.format_as_text()) first_toplevel=True
if out_format.lower()=="json":
sys.stdout.write("[")
for thrd in t:
msgs = thrd.get_toplevel_messages()
if not first_toplevel:
if format.lower()=="json":
sys.stdout.write(", ")
first_toplevel = False
msgs.show_messages(out_format, 0, True)
if out_format.lower() == "json":
sys.stdout.write("]")
sys.stdout.write("\n")
#------------------------------------- #-------------------------------------
elif sys.argv[1] == 'reply': elif sys.argv[1] == 'reply':