mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-12-26 11:24:53 +01:00
rename show_messages to print_messages and fix up the arg parsing for notmuch show a bit
This commit is contained in:
parent
5c4af8ce39
commit
62a73f7eb0
2 changed files with 33 additions and 23 deletions
|
@ -172,14 +172,19 @@ class Messages(object):
|
|||
self._msgs = None
|
||||
return i
|
||||
|
||||
|
||||
|
||||
def __del__(self):
|
||||
"""Close and free the notmuch Messages"""
|
||||
if self._msgs is not None:
|
||||
nmlib.notmuch_messages_destroy (self._msgs)
|
||||
|
||||
def show_messages(self, format, indent=0, entire_thread=True):
|
||||
def print_messages(self, format, indent=0, entire_thread=False):
|
||||
"""Outputs messages as needed for 'notmuch show' to sys.stdout
|
||||
|
||||
:param format: A string of either 'text' or 'json'.
|
||||
:param indent: A number indicating the reply depth of these messages.
|
||||
:param entire_thread: A bool, indicating whether we want to output
|
||||
whole threads or only the matching messages.
|
||||
"""
|
||||
if format.lower() == "text":
|
||||
set_start = ""
|
||||
set_end = ""
|
||||
|
@ -195,6 +200,7 @@ class Messages(object):
|
|||
|
||||
sys.stdout.write(set_start)
|
||||
|
||||
# iterate through all toplevel messages in this thread
|
||||
for msg in self:
|
||||
# if not msg:
|
||||
# break
|
||||
|
@ -221,8 +227,7 @@ class Messages(object):
|
|||
# break
|
||||
if not replies is None:
|
||||
sys.stdout.write(set_sep)
|
||||
replies.show_messages(format, next_indent, entire_thread)
|
||||
|
||||
replies.print_messages(format, next_indent, entire_thread)
|
||||
|
||||
sys.stdout.write(set_end)
|
||||
sys.stdout.write(set_end)
|
||||
|
@ -720,13 +725,12 @@ class Message(object):
|
|||
% (format['id'], indent, format['match'], format['filename'])
|
||||
output += "\n\fheader{"
|
||||
|
||||
#Todo: this date is supposed to be cleaned up, as in the index.
|
||||
#Todo: this date is supposed to be prettified, as in the index.
|
||||
output += "\n%s (%s) (" % (format["headers"]["from"],
|
||||
format["headers"]["date"])
|
||||
output += ", ".join(format["tags"])
|
||||
output += ")\n"
|
||||
|
||||
|
||||
output += "\nSubject: %s" % format["headers"]["subject"]
|
||||
output += "\nFrom: %s" % format["headers"]["from"]
|
||||
output += "\nTo: %s" % format["headers"]["to"]
|
||||
|
@ -763,7 +767,6 @@ class Message(object):
|
|||
|
||||
return output
|
||||
|
||||
|
||||
def __del__(self):
|
||||
"""Close and free the notmuch Message"""
|
||||
if self._msg is not None:
|
||||
|
|
37
notmuch
37
notmuch
|
@ -302,24 +302,31 @@ if __name__ == '__main__':
|
|||
print(str(thread))
|
||||
#-------------------------------------
|
||||
elif sys.argv[1] == 'show':
|
||||
entire_thread = False
|
||||
db = Database()
|
||||
out_format="text"
|
||||
if len(sys.argv) == 2:
|
||||
#no further search term
|
||||
querystr=''
|
||||
elif sys.argv[2].startswith("--format="):
|
||||
out_format = sys.argv[2].split("=")[1].strip()
|
||||
querystr=''
|
||||
first_search_term = None
|
||||
|
||||
if not out_format in ("json", "text"):
|
||||
raise Exception("unknown format")
|
||||
#ugly homegrown option parsing
|
||||
#TODO: use OptionParser
|
||||
for (i, arg) in enumerate(sys.argv[1:]):
|
||||
if arg == '--entire-thread':
|
||||
entire_thread = True
|
||||
elif arg.startswith("--format="):
|
||||
out_format = arg.split("=")[1]
|
||||
if out_format == 'json':
|
||||
#for compatibility use --entire-thread for json
|
||||
entire_thread = True
|
||||
if not out_format in ("json", "text"):
|
||||
raise Exception("unknown format")
|
||||
elif not arg.startswith('--'):
|
||||
#save the position of the first sys.argv that is a search term
|
||||
first_search_term = i+1
|
||||
|
||||
if len(sys.argv) == 3:
|
||||
querystr = ''
|
||||
else:
|
||||
querystr = quote_query_line(sys.argv[3:])
|
||||
else:
|
||||
#mangle arguments wrapping terms with spaces in quotes
|
||||
querystr = quote_query_line(sys.argv[2:])
|
||||
if first_search_term:
|
||||
#mangle arguments wrapping terms with spaces in quotes
|
||||
querystr = quote_query_line(sys.argv[first_search_term:])
|
||||
|
||||
logging.debug("show "+querystr)
|
||||
t = Query(db,querystr).search_threads()
|
||||
|
@ -337,7 +344,7 @@ if __name__ == '__main__':
|
|||
|
||||
first_toplevel = False
|
||||
|
||||
msgs.show_messages(out_format, 0, True)
|
||||
msgs.print_messages(out_format, 0, True)
|
||||
|
||||
if out_format.lower() == "json":
|
||||
sys.stdout.write("]")
|
||||
|
|
Loading…
Reference in a new issue