]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Move FileLock out of repo_utils
authorZack Cerza <zack@redhat.com>
Thu, 9 Feb 2017 20:53:57 +0000 (13:53 -0700)
committerZack Cerza <zack@redhat.com>
Fri, 24 Feb 2017 16:03:33 +0000 (09:03 -0700)
Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/repo_utils.py
teuthology/util/__init__.py [new file with mode: 0644]
teuthology/util/flock.py [new file with mode: 0644]

index 6e80bde4ea0e3f7b402b9e28e453fb4b10008b1e..fee402e744872d18b341f5960912eb89155d22ed 100644 (file)
@@ -1,4 +1,3 @@
-import fcntl
 import logging
 import os
 import re
@@ -6,8 +5,9 @@ import shutil
 import subprocess
 import time
 
+from teuthology.util.flock import FileLock
 from .config import config
-from .contextutil import safe_while, MaxWhileTries
+from .contextutil import MaxWhileTries, safe_while
 from .exceptions import BootstrapError, BranchNotFoundError, GitError
 
 log = logging.getLogger(__name__)
@@ -349,24 +349,3 @@ def bootstrap_teuthology(dest_path):
             shutil.rmtree(venv_path, ignore_errors=True)
             raise BootstrapError("Bootstrap failed!")
         touch_file(sentinel)
-
-
-class FileLock(object):
-    def __init__(self, filename, noop=False):
-        self.filename = filename
-        self.file = None
-        self.noop = noop
-
-    def __enter__(self):
-        if not self.noop:
-            assert self.file is None
-            self.file = file(self.filename, 'w')
-            fcntl.lockf(self.file, fcntl.LOCK_EX)
-        return self
-
-    def __exit__(self, exc_type, exc_val, exc_tb):
-        if not self.noop:
-            assert self.file is not None
-            fcntl.lockf(self.file, fcntl.LOCK_UN)
-            self.file.close()
-            self.file = None
diff --git a/teuthology/util/__init__.py b/teuthology/util/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/teuthology/util/flock.py b/teuthology/util/flock.py
new file mode 100644 (file)
index 0000000..4264216
--- /dev/null
@@ -0,0 +1,22 @@
+import fcntl
+
+
+class FileLock(object):
+    def __init__(self, filename, noop=False):
+        self.filename = filename
+        self.file = None
+        self.noop = noop
+
+    def __enter__(self):
+        if not self.noop:
+            assert self.file is None
+            self.file = file(self.filename, 'w')
+            fcntl.lockf(self.file, fcntl.LOCK_EX)
+        return self
+
+    def __exit__(self, exc_type, exc_val, exc_tb):
+        if not self.noop:
+            assert self.file is not None
+            fcntl.lockf(self.file, fcntl.LOCK_UN)
+            self.file.close()
+            self.file = None