-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhd5_example.py
72 lines (58 loc) · 2.06 KB
/
hd5_example.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
import os
from tables import *
class FileSystem(IsDescription):
label = StringCol(16, pos=1) # 16-character String
path = StringCol(16, pos=2) # 16-character String
name = StringCol(16, pos=3) # 16-character String
size = Int32Col(pos=4) # integer
time = Int32Col(pos=5) # integer
hash = StringCol(16, pos=6) # 16-character String
checked = UInt8Col(pos=7) # unsigned byte
class Hd5():
def __init__(self, **kwargs):
self.edited = False
self.index = {}
if 'filename' in kwargs and kwargs['filename']:
self.filename = kwargs['filename']
else:
self.filename = 'files.hd5'
if os.path.exists(self.filename):
self.db = openFile(self.filename, mode="r+")
self.group = self.db.root.group
self.table = self.db.root.group.table
self.index = {r['label']:r.nrow for r in self.table.iterrows()}
else:
self.db = openFile(self.filename, mode = "w", title = "Test file")
self.group = self.db.createGroup("/", 'group', 'Detector information')
self.table = self.db.createTable(self.group, 'table', FileSystem, "Readout example")
self.db.flush()
def set(self, k, l):
row = self.table.row
row['label'] = l[0]
row['path'] = l[1]
row['name'] = l[2]
row['size'] = l[3]
row['time'] = l[4]
row['hash'] = l[5]
row['checked'] = l[6]
row.append()
self.table.flush()
self.index[l[0]] = row.nrow
self.edited = True
def get(self, k):
return self.table[self.index[k]]
def exists(self, k):
return k in self.index
def values(self):
return self.table.iterrows()
def delete(self, k):
self.edited = True
#del self.db[k]
return #
def iteritems(self):
return #self.db.iteritems()
def sync(self):
if self.edited:
self.table.flush()
def close(self):
self.db.close()