You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2018/05/27 00:28:44 UTC
[incubator-ponymail] 02/03: Unnecessary check - always true
This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail.git
commit 2de2c6d9ac9e01830a22c5950e6b8b2109fad49b
Author: Sebb <se...@apache.org>
AuthorDate: Sun May 27 01:21:02 2018 +0100
Unnecessary check - always true
---
tools/missing.py | 128 +++++++++++++++++++++++++++----------------------------
1 file changed, 63 insertions(+), 65 deletions(-)
diff --git a/tools/missing.py b/tools/missing.py
index 8c55f5c..6e74b44 100755
--- a/tools/missing.py
+++ b/tools/missing.py
@@ -65,79 +65,77 @@ def update(elastic, js_arr):
if not args.test:
elastic.bulk(js_arr)
-if args.missing:
- setField = len(args.missing) > 1
- field = args.missing[0]
- value = None
- if setField:
- value = args.missing[1]
- if setField:
- print("Set missing/null field %s to '%s'" %(field, value))
- else:
- print("List missing/null field %s" % field)
- count = 0
- scroll = '30m'
- then = time.time()
- elastic = Elastic()
- sourceLID = ("%s" if args.notag else "<%s>") % args.source.replace("@", ".").strip("<>")
- page = elastic.scan(# defaults to mbox
- scroll = scroll,
- body = {
- "_source" : ['subject','message-id'],
- "query" : {
- "bool" : {
- "must" : {
- 'wildcard' if args.wildcard else 'term': {
- 'list_raw': sourceLID
- }
- },
- # missing is not supported in ES 5.x
- "must_not": {
- "exists" : {
- "field" : field
+setField = len(args.missing) > 1
+field = args.missing[0]
+value = None
+if setField:
+ value = args.missing[1]
+ print("Set missing/null field %s to '%s'" %(field, value))
+else:
+ print("List missing/null field %s" % field)
+count = 0
+scroll = '30m'
+then = time.time()
+elastic = Elastic()
+sourceLID = ("%s" if args.notag else "<%s>") % args.source.replace("@", ".").strip("<>")
+page = elastic.scan(# defaults to mbox
+ scroll = scroll,
+ body = {
+ "_source" : ['subject','message-id'],
+ "query" : {
+ "bool" : {
+ "must" : {
+ 'wildcard' if args.wildcard else 'term': {
+ 'list_raw': sourceLID
}
+ },
+ # missing is not supported in ES 5.x
+ "must_not": {
+ "exists" : {
+ "field" : field
}
}
}
}
- )
+ }
+ )
+print(page)
+sid = page['_scroll_id']
+scroll_size = page['hits']['total']
+print("Found %d matches" % scroll_size)
+if args.debug:
print(page)
- sid = page['_scroll_id']
- scroll_size = page['hits']['total']
- print("Found %d matches" % scroll_size)
+js_arr = []
+while (scroll_size > 0):
+ page = elastic.scroll(scroll_id = sid, scroll = scroll)
if args.debug:
print(page)
- js_arr = []
- while (scroll_size > 0):
- page = elastic.scroll(scroll_id = sid, scroll = scroll)
- if args.debug:
- print(page)
- sid = page['_scroll_id']
- scroll_size = len(page['hits']['hits'])
- for hit in page['hits']['hits']:
- doc = hit['_id']
- body = {}
+ sid = page['_scroll_id']
+ scroll_size = len(page['hits']['hits'])
+ for hit in page['hits']['hits']:
+ doc = hit['_id']
+ body = {}
+ if setField:
+ body[field] = value
+ js_arr.append({
+ '_op_type': 'update',
+ '_index': elastic.dbname,
+ '_type': 'mbox',
+ '_id': doc,
+ 'doc': body
+ })
+ count += 1
+ source = hit['_source']
+ print("Id: %s Msg-id: %s Subject: %s" %(doc, getField(source, 'message-id'), getField(source,'subject')))
+ if (count % 500 == 0):
+ print("Processed %u emails..." % count)
if setField:
- body[field] = value
- js_arr.append({
- '_op_type': 'update',
- '_index': elastic.dbname,
- '_type': 'mbox',
- '_id': doc,
- 'doc': body
- })
- count += 1
- source = hit['_source']
- print("Id: %s Msg-id: %s Subject: %s" %(doc, getField(source, 'message-id'), getField(source,'subject')))
- if (count % 500 == 0):
- print("Processed %u emails..." % count)
- if setField:
- update(elastic, js_arr)
- js_arr = []
+ update(elastic, js_arr)
+ js_arr = []
- print("Processed %u emails." % count)
- if len(js_arr) > 0:
- if setField:
- update(elastic, js_arr)
+print("Processed %u emails." % count)
+if len(js_arr) > 0:
+ if setField:
+ update(elastic, js_arr)
- print("All done, processed %u docs in %u seconds" % (count, time.time() - then))
+print("All done, processed %u docs in %u seconds" % (count, time.time() - then))
--
To stop receiving notification emails like this one, please contact
sebb@apache.org.