1
2
3
4
5
6 import os
7 import time
8 from extendedLists import Entries, Attributes
9 from diskutils import RLock
10 from mdinterface import CommandException
11
15
16
18 - def __init__(self, dirname,
19 attributes = None,
20 entries = None,
21 blocklength = 1000,
22 cache_size = 3,
23 tries_limit = 200):
24 """dirname is system path to the table files"""
25 self.dirname = dirname
26 if attributes == None:
27 attributes = Attributes(dirname = dirname,
28 blocklength = blocklength,
29 cache_size = cache_size,
30 tries_limit = tries_limit)
31 if entries == None:
32 entries = Entries(dirname = dirname,
33 blocklength = blocklength,
34 cache_size = cache_size,
35 tries_limit = tries_limit)
36 self.attributes = attributes
37 self.entries = entries
38 self.timestamp = time.time()
39 self.update()
40 self._lock = RLock(lockfile = os.path.join(dirname, 'LOCK'),
41 tries_limit = tries_limit)
42
43
46
47
50
51
53 if os.path.isdir(self.dirname):
54 if self.lock():
55 try:
56 self.attributes.load(self.dirname)
57 self.entries.load(self.dirname)
58 self.timestamp = time.time()
59 self.update()
60 finally:
61 self.unlock()
62 else:
63 raise CommandException(9, 'Could not acquire table lock %s' % self.dirname)
64
65
67
68 if self.lock():
69 try:
70 self.update()
71 self.attributes.save(self.dirname)
72 self.entries.save(self.dirname)
73 finally:
74 self.unlock()
75 else:
76 raise CommandException(9, 'Could not acquire table lock %s' % self.dirname)
77
78
80 self.attributeDict = {}
81 self.typeDict = {}
82 for i in range(0, len(self.attributes)):
83 a, t=self.attributes[i]
84 self.attributeDict[a]=i
85 self.typeDict[a] = t
86 self.initRowPointer()
87
88
90 self.currentRow = 0
91 if not len(self.entries):
92 self.currentRow = -1
93