aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec <dolsen@gentoo.org>2018-07-02 14:52:53 -0700
committerBrian Dolbec <dolsen@gentoo.org>2018-07-06 22:22:11 -0700
commit80a59eed95c17a8702da10f54f9b6fdf8e90a880 (patch)
tree52a1b04fffaee9cb88bc87755ccfe0b691d413ba
parentgkeys/fetch.py: New Fetch class (diff)
downloadgentoo-keys-80a59eed95c17a8702da10f54f9b6fdf8e90a880.tar.gz
gentoo-keys-80a59eed95c17a8702da10f54f9b6fdf8e90a880.tar.bz2
gentoo-keys-80a59eed95c17a8702da10f54f9b6fdf8e90a880.zip
gkeys/lock.py: New LockDir class
Signed-off-by: Brian Dolbec <dolsen@gentoo.org>
-rw-r--r--gkeys/gkeys/lock.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/gkeys/gkeys/lock.py b/gkeys/gkeys/lock.py
new file mode 100644
index 0000000..5614335
--- /dev/null
+++ b/gkeys/gkeys/lock.py
@@ -0,0 +1,31 @@
+
+import os
+
+from snakeoil import fileutils
+from snakeoil import osutils
+from catalyst.fileops import ensure_dirs
+
+
+LockInUse = osutils.LockException
+
+
+class LockDir(object):
+ """An object that creates locks inside dirs"""
+
+ def __init__(self, lockdir):
+ #self.gid = 250
+ self.lockfile = os.path.join(lockdir, '.gkeys_lock')
+ ensure_dirs(lockdir)
+ fileutils.touch(self.lockfile, mode=0o664)
+ #os.chown(self.lockfile, -1, self.gid)
+ self.lock = osutils.FsLock(self.lockfile)
+
+ def read_lock(self):
+ self.lock.acquire_read_lock()
+
+ def write_lock(self):
+ self.lock.acquire_write_lock()
+
+ def unlock(self):
+ # Releasing a write lock is the same as a read lock.
+ self.lock.release_write_lock()