Back to index

obnam  1.1
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
obnamlib.lockmgr.LockManager Class Reference

List of all members.

Public Member Functions

def __init__
def sort
def lock
def unlock

Public Attributes

 timeout
 data

Private Member Functions

def _read_boot_id
def _time
def _sleep
def _lockname
def _lock_one
def _unlock_one

Private Attributes

 _fs

Detailed Description

Lock and unlock sets of directories at once.

Definition at line 23 of file lockmgr.py.


Constructor & Destructor Documentation

def obnamlib.lockmgr.LockManager.__init__ (   self,
  fs,
  timeout,
  client 
)

Definition at line 27 of file lockmgr.py.

00027 
00028     def __init__(self, fs, timeout, client):
00029         self._fs = fs
00030         self.timeout = timeout
00031         data = ["[lockfile]"]
00032         data = data + ["client=" + client]
00033         data = data + ["pid=%d" % os.getpid()]
00034         data = data + self._read_boot_id()
00035         self.data = '\r\n'.join(data)


Member Function Documentation

def obnamlib.lockmgr.LockManager._lock_one (   self,
  dirname 
) [private]

Definition at line 60 of file lockmgr.py.

00060 
00061     def _lock_one(self, dirname):
00062         started = self._time()
00063         while True:
00064             lock_name = self._lockname(dirname)
00065             try:
00066                 self._fs.lock(lock_name, self.data)
00067             except obnamlib.LockFail:
00068                 if self._time() - started >= self.timeout:
00069                     raise obnamlib.LockFail('Lock timeout: %s' % lock_name)
00070             else:
00071                 return
00072             self._sleep()
        

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.lockmgr.LockManager._lockname (   self,
  dirname 
) [private]

Definition at line 56 of file lockmgr.py.

00056 
00057     def _lockname(self, dirname):
00058         return os.path.join(dirname, 'lock')
00059 
        

Here is the caller graph for this function:

Definition at line 36 of file lockmgr.py.

00036 
00037     def _read_boot_id(self):
00038         try:
00039             with open("/proc/sys/kernel/random/boot_id", "r") as f:
00040                 boot_id = f.read().strip()
00041         except: # pragma: no cover
00042             return []
00043         else:
00044             return ["boot_id=%s" % boot_id]

def obnamlib.lockmgr.LockManager._sleep (   self) [private]

Definition at line 48 of file lockmgr.py.

00048 
00049     def _sleep(self): # pragma: no cover
00050         time.sleep(1)
        

Here is the caller graph for this function:

def obnamlib.lockmgr.LockManager._time (   self) [private]

Definition at line 45 of file lockmgr.py.

00045 
00046     def _time(self): # pragma: no cover
00047         return time.time()
        

Here is the caller graph for this function:

def obnamlib.lockmgr.LockManager._unlock_one (   self,
  dirname 
) [private]

Definition at line 73 of file lockmgr.py.

00073 
00074     def _unlock_one(self, dirname):
00075         self._fs.unlock(self._lockname(dirname))
        

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.lockmgr.LockManager.lock (   self,
  dirnames 
)
Lock ALL the directories.

Definition at line 76 of file lockmgr.py.

00076 
00077     def lock(self, dirnames):
00078         '''Lock ALL the directories.'''
00079         we_locked = []
00080         for dirname in self.sort(dirnames):
00081             try:
00082                 self._lock_one(dirname)
00083             except obnamlib.LockFail:
00084                 self.unlock(we_locked)
00085                 raise
00086             else:
00087                 we_locked.append(dirname)

Here is the call graph for this function:

def obnamlib.lockmgr.LockManager.sort (   self,
  dirnames 
)

Definition at line 51 of file lockmgr.py.

00051 
00052     def sort(self, dirnames):
00053         def bytelist(s):
00054             return [ord(s) for s in str(s)]
00055         return sorted(dirnames, key=bytelist)

Here is the caller graph for this function:

def obnamlib.lockmgr.LockManager.unlock (   self,
  dirnames 
)
Unlock ALL the directories.

Definition at line 88 of file lockmgr.py.

00088 
00089     def unlock(self, dirnames):
00090         '''Unlock ALL the directories.'''
00091         for dirname in self.sort(dirnames):
00092             self._unlock_one(dirname)
00093 

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 28 of file lockmgr.py.

Definition at line 34 of file lockmgr.py.

Definition at line 29 of file lockmgr.py.


The documentation for this class was generated from the following file: