-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvalDGPdb.py
80 lines (58 loc) · 1.86 KB
/
EvalDGPdb.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import multiprocessing as mp
import os
from subprocess import PIPE, Popen
import fnmatch
import sqlite3
path = 'hdrs'
num_processes = mp.cpu_count()
connection=sqlite3.connect('DGP.db')
c=connection.cursor()
c.execute('PRAGMA journal_mode=wal')
def cmdline(command):
process = Popen(
args=command,
stdout=PIPE,
shell=True
)
return process.communicate()[0]
def taskEvalglare(file):
evaluate(file)
def evaluate(file):
filename = str(os.path.basename(file).split('.hdr')[0])
if not checkDB(filename):
if fnmatch.fnmatch(file, '*.hdr'):
res = cmdline('evalglare -d ' + file + ' | tail -n1 ')
if res !=b'':
dgp = (((res).decode("utf-8")).split(':')[1]).split(' ')[1]
ev= (((res).decode("utf-8")).split(':')[1]).split(' ')[3]
connection = sqlite3.connect('DGP.db')
c2 = connection.cursor()
try:
c2.execute("INSERT INTO id_dgp_ev VALUES (?,?,?)",(filename,dgp,ev))
connection.commit()
except sqlite3.OperationalError:
pass
connection.close()
def checkDB(filename):
connection = sqlite3.connect('DGP.db')
c1 = connection.cursor()
c1.execute('PRAGMA journal_mode=wal')
try:
c1.execute("CREATE TABLE IF NOT EXISTS id_dgp_ev (ID PRIMARY KEY ,DGP,EV)")
c1.execute("SELECT ID FROM id_dgp_ev WHERE ID=?", (filename,))
exists = c1.fetchall()
connection.commit()
except sqlite3.OperationalError:
pass
connection.close()
if exists:
return True
else:
return False
c.execute("SELECT PATH FROM id_path ")
paths=c.fetchall()
connection.close()
pool = mp.Pool(processes=num_processes)
pool.map(taskEvalglare, [elt[0] for elt in paths])
pool.close()
pool.join()