aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevan Franchini <twitch153@gentoo.org>2015-05-13 16:39:20 -0400
committerDevan Franchini <twitch153@gentoo.org>2015-05-13 16:39:20 -0400
commit5087e5f1a7e958eb2b28815453c403572e9e2f1f (patch)
tree66fb7e508ba43084efb9c4b213f1a17fa7c88179 /layman/flocker.py
parentdbbase.py: Reorganizes imports (diff)
downloadlayman-5087e5f1a7e958eb2b28815453c403572e9e2f1f.tar.gz
layman-5087e5f1a7e958eb2b28815453c403572e9e2f1f.tar.bz2
layman-5087e5f1a7e958eb2b28815453c403572e9e2f1f.zip
flocker.py: Adds exception raising to relay errors properly
Diffstat (limited to 'layman/flocker.py')
-rw-r--r--layman/flocker.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/layman/flocker.py b/layman/flocker.py
index d40925d..21f34c3 100644
--- a/layman/flocker.py
+++ b/layman/flocker.py
@@ -22,6 +22,17 @@ import fcntl
from layman.compatibility import fileopen
+class LockingException(Exception):
+ '''
+ Exception class for relay errors properly
+ '''
+ def __init__(self, msg):
+ self.msg = msg
+
+
+ def __str__(self):
+ return repr(self.msg)
+
class FileLocker(object):
@@ -39,7 +50,9 @@ class FileLocker(object):
file_mode = 'w+'
lock_mode = fcntl.LOCK_EX
- assert path not in self.locked
+ if path in self.locked:
+ raise LockingException('"%(path)s" is already locked.'
+ % {'path': path})
self.locked.add(path)
fcntl.flock(self.get_file(path, file_mode).fileno(), lock_mode)
@@ -47,7 +60,9 @@ class FileLocker(object):
def unlock_file(self, path):
'''Unlock the file located at path.'''
- assert path in self.locked
+ if path not in self.locked:
+ raise LockingException('"%(path)s" is not locked, unlocking failed'
+ % {'path': path})
fcntl.flock(self.get_file(path).fileno(), fcntl.LOCK_UN)
self.locked.discard(path)