-
Notifications
You must be signed in to change notification settings - Fork 0
/
processor.py
executable file
·55 lines (48 loc) · 1.5 KB
/
processor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python
import threading
from Queue import Queue
import hashlib
import os
import shutil
from logger import Logger
from rpcmonitor import RpcMonitor
from dbmanager import DbManager
import ndutil
class Processor(threading.Thread):
def __init__(self, logger, rpcMonitor, dpQueue, pdLock, pdQueue, dbManager, dirWorking, dirStore, name):
super(Processor, self).__init__()
self.logger = logger
self.rpcMonitor = rpcMonitor
self.dpQueue = dpQueue
self.pdLock = pdLock
self.pdQueue = pdQueue
self.dbManager = dbManager
self.dirWorking = dirWorking
self.dirStore = dirStore
self.name = name
def run(self):
self.rpcMonitor.setDownloadedTotal(0)
self.rpcMonitor.setDuplicatedTotal(0)
while True:
data, fileName = self.dpQueue.get(1)
#filte 0KB file
if ndutil.getSize(fileName) == 0:
self.pdLock.acquire()
self.pdQueue.put(data, 1)
self.rpcMonitor.incPdQueueSize()
self.pdLock.release()
continue
#duplicate?
md5Value = ndutil.getMd5(fileName)
path = self.dbManager.get_path_by_hashval(md5Value)
if path is not None:
self.dbManager.update_item(data, 'NULL', path, md5Value, 1)
self.rpcMonitor.incDuplicatedTotal()
self.logger.logger('Duplicated %s' % path)
os.remove(fileName)
continue
newFileName = '%s/%s.apk' % (self.dirStore, md5Value)
shutil.move(fileName, newFileName)
self.dbManager.update_item(data, 'NULL', newFileName, md5Value, 1)
self.rpcMonitor.incDownloadedTotal()
self.logger.logger('Downloaded %s' % data)