From 7fcd5e4878ff7d1991bb4705afa7868e629a5468 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Wed, 20 Jun 2018 17:02:32 +0200 Subject: [PATCH] Show progress in percent when reparsing large sets of emails --- loader/reparse_message.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/loader/reparse_message.py b/loader/reparse_message.py index 519ab0f..59862a3 100755 --- a/loader/reparse_message.py +++ b/loader/reparse_message.py @@ -70,12 +70,17 @@ if __name__ == "__main__": # Get messages curs = conn.cursor('msglist') if opt.all: + curs2 = conn.cursor() + curs2.execute("SELECT count(*) FROM messages WHERE hiddenstatus IS NULL") + totalcount, = curs2.fetchone() curs.execute("SELECT id, rawtxt FROM messages WHERE hiddenstatus IS NULL ORDER BY id") elif opt.sample: + totalcount = int(opt.sample) curs.execute("SELECT id, rawtxt FROM messages WHERE hiddenstatus IS NULL ORDER BY id DESC LIMIT %(num)s", { 'num': int(opt.sample), }) else: + totalcount = 1 curs.execute("SELECT id, rawtxt FROM messages WHERE messageid=%(msgid)s", { 'msgid': opt.msgid, }) @@ -104,7 +109,9 @@ if __name__ == "__main__": else: ap.diff(conn, f, fromonlyf, id) if datetime.now() - laststatus > timedelta(seconds=5): - sys.stdout.write("%s messages parsed (%s / second)\r" % (num, num / ((datetime.now()-firststatus).seconds))) + sys.stdout.write("%s messages parsed (%s%%, %s / second)\r" % (num, + num*100/totalcount, + num / ((datetime.now()-firststatus).seconds))) sys.stdout.flush() laststatus = datetime.now() -- 2.39.5