Back to index

nordugrid-arc-nox  1.1.0~rc6
basestore.py
Go to the documentation of this file.
00001 import arc
00002 import os, threading, traceback
00003 
00004 from arcom.logger import Logger
00005 log = Logger(arc.Logger(arc.Logger_getRootLogger(), 'arcom.BaseStore'))
00006 
00007 class BaseStore:
00008     
00009     def __init__(self, storecfg, non_existent_object = {}):
00010         """ Constructor of BaseStore.
00011 
00012         BaseStore(storecfg)
00013 
00014         'storecfg' is an XMLNode with a 'DataDir'
00015         'non_existent_object' will be returned if an object not found
00016         """
00017         # get the datadir from the storecfg XMLNode
00018         self.datadir = str(storecfg.Get('DataDir'))
00019         # set the value which we should return if there an object does not exist
00020         self.non_existent_object = non_existent_object
00021         # if the given data directory does not exist, try to create it
00022         if not os.path.exists(self.datadir):
00023             os.mkdir(self.datadir)
00024         # initialize a lock which can be used to avoid race conditions
00025         self.llock = threading.Lock()
00026 
00027     def lock(self, blocking = True):
00028         """ Acquire the lock.
00029 
00030         lock(blocking = True)
00031 
00032         'blocking': if blocking is True, then this only returns when the lock is acquired.
00033         If it is False, then it returns immediately with False if the lock is not available,
00034         or with True if it could be acquired.
00035         """
00036         return self.llock.acquire(blocking)
00037 
00038     def unlock(self):
00039         """ Release the lock.
00040 
00041         unlock()
00042         """
00043         self.llock.release()
00044