Package Ganga :: Package Utility :: Package external :: Package ARDAMDClient :: Module mdtable
[hide private]
[frames] | no frames]

Source Code for Module Ganga.Utility.external.ARDAMDClient.mdtable

 1  ################################################################################ 
 2  # Ganga Project. http://cern.ch/ganga 
 3  # 
 4  # $Id: mdtable.py,v 1.1 2008-07-17 16:41:02 moscicki Exp $ 
 5  ################################################################################ 
 6  import os 
 7  import time 
 8  from extendedLists import Entries, Attributes 
 9  from diskutils import RLock 
10  from mdinterface import CommandException 
11   
12 -class EmptyTableException(Exception):
13 - def __init__(self):
14 self.raised = True
15 16
17 -class MDTable:
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
44 - def lock(self):
45 return self._lock.acquire()
46 47
48 - def unlock(self):
49 self._lock.release()
50 51
52 - def load(self):
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
66 - def save(self):
67 # mkdir(self.dirname) 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
79 - def update(self):
80 self.attributeDict = {} 81 self.typeDict = {} 82 for i in range(0, len(self.attributes)): 83 a, t=self.attributes[i] # Was a, t=self.attributes[i].split(' ', 1) 84 self.attributeDict[a]=i 85 self.typeDict[a] = t 86 self.initRowPointer()
87 88
89 - def initRowPointer(self):
90 self.currentRow = 0 91 if not len(self.entries): 92 self.currentRow = -1
93