Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(9)

Side by Side Diff: update-client.py

Issue 975: Add support for removes in updater.py and update-client.py SVN Base: http://malfind2.googlecode.com/svn/trunk/
Patch Set: Created 3 months, 3 weeks ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 import urllib 3 import urllib
4 import httplib 4 import httplib
5 import time 5 import time
6 6
7 hashes = [] 7 hashes = []
8 count = 0 8 count = 0
9 9
10 def AddHashes(hashes): 10 def UpdateHashes(hashes):
11 body = urllib.urlencode({"data": ",".join(hashes)}) 11 body = urllib.urlencode({'data': ''.join(hashes)})
12
13 headers = { 12 headers = {
14 'Content-Type': 'application/x-www-form-urlencoded', 13 'Content-Type': 'application/x-www-form-urlencoded',
15 'Content-Length': len(body), 14 'Content-Length': len(body),
16 } 15 }
17 16
18 try: 17 try:
19 # conn = httplib.HTTPConnection("localhost:8080") 18 #conn = httplib.HTTPConnection("localhost:8080")
20 conn = httplib.HTTPConnection("malfind.appspot.com") 19 conn = httplib.HTTPConnection('malfind.appspot.com')
21 conn.request("POST", "/update", body, headers) 20 conn.request('POST', '/update', body, headers)
22 response = conn.getresponse() 21 response = conn.getresponse()
23 conn.close() 22 conn.close()
24 print response.status, response.reason 23 print response.status, response.reason
25 return response.status == 200 24 return response.status == 200
26 25
27 except Exception, e: 26 except Exception, e:
28 print e 27 print e
29 return False 28 return False
30 29
31 30
32 def TryAddHashes(hashes): 31 def TryUpdateHashes(hashes):
33 retries = 0 32 retries = 0
34 while retries < 2: 33 while retries < 2:
35 if AddHashes(hashes): 34 if UpdateHashes(hashes):
36 hashes = [] 35 hashes = []
37 break 36 break
38 37
39 print "Error, Retrying in 60 secs" 38 print 'Error, Retrying in 60 secs'
40 time.sleep(60) 39 time.sleep(60)
41 retries += 1 40 retries += 1
42 41
43 if retries == 2: 42 if retries == 2:
44 print "Too many errors, aborting" 43 print 'Too many errors, aborting'
45 sys.exit(-1) 44 sys.exit(-1)
46 45
47
48 for line in open('/tmp/sbcache.txt'): 46 for line in open('/tmp/sbcache.txt'):
49 if not line[0] == '+': 47 if not line.startswith('+') and not line.startswith('-'):
50 print 'Ignoring ' + line.strip('\n') 48 print 'Ignoring ' + line.strip('\n')
51 continue 49 continue
52 50
53 count += 1 51 count += 1
54 if count < 19000: 52 if count < 19000:
55 continue 53 continue
56 54
57 hashes.append(line.strip('+').strip('\t\n')) 55 hashes.append(line.strip('\t\n'))
58
59 if count % 50 == 0: 56 if count % 50 == 0:
60 print count 57 print count
61 TryAddHashes(hashes) 58 TryUpdateHashes(hashes)
62 hashes = [] 59 hashes = []
63 time.sleep(0.2) 60 time.sleep(0.2)
64 61
65 TryAddHashes(hashes) 62 TryUpdateHashes(hashes)
66 63
67 print "Success" 64 print 'Success'
OLDNEW

Powered by Google App Engine
This is Rietveld r305