Ejemplo n.º 1
0
 def second_lock(self):
     lock = FileLock(self.testfile, timeout=0)
     try:
         lock.acquire()
     except FileLockException:
         sys.exit(1)
     lock.release()
Ejemplo n.º 2
0
 def test_stale(self):
     """Handling of stale lock files."""
     lock = FileLock(self.testfile)
     lockfile = open(lock.lockfile, 'w')
     lock.acquire()
     lockfile.close()
     lock.release()
Ejemplo n.º 3
0
 def test_double(self):
     """Test of double locking."""
     lock1 = FileLock(self.testfile)
     lock2 = FileLock(self.testfile, timeout=0)
     lock1.acquire()
     self.assertRaises(FileLockException, lock2.acquire)
     lock1.release()
     lock2.acquire()
     lock2.release()
Ejemplo n.º 4
0
 def test_lock_twice(self):
     '''
     Basic locking test.
     '''
     lock = FileLock('lock-test')
     lock.acquire()
     lock.acquire()
     self.assertTrue(lock.is_locked)
     lock.release()
     self.assertFalse(lock.is_locked)
Ejemplo n.º 5
0
 def test_context(self):
     """Test of context handling."""
     lock = FileLock(self.testfile)
     lock2 = FileLock(self.testfile, timeout=0)
     with lock:
         self.assertTrue(lock.is_locked)
         self.assertTrue(lock.check_lock())
         self.assertRaises(FileLockException, lock2.acquire)
     self.assertFalse(lock.is_locked)
     self.assertFalse(lock.check_lock())
Ejemplo n.º 6
0
 def test_context(self):
     """Test of context handling."""
     lock = FileLock(self.testfile)
     lock2 = FileLock(self.testfile, timeout=0)
     with lock:
         self.assertTrue(lock.is_locked)
         self.assertTrue(lock.check_lock())
         self.assertRaises(FileLockException, lock2.acquire)
     self.assertFalse(lock.is_locked)
     self.assertFalse(lock.check_lock())
Ejemplo n.º 7
0
 def test_double(self):
     '''
     Test of double locking.
     '''
     lock1 = FileLock('lock-test')
     lock2 = FileLock('lock-test', timeout=0)
     lock1.acquire()
     self.assertRaises(FileLockException, lock2.acquire)
     lock1.release()
     lock2.acquire()
     lock2.release()
Ejemplo n.º 8
0
 def test_context(self):
     '''
     Test of context handling.
     '''
     lock = FileLock('lock-test')
     lock2 = FileLock('lock-test', timeout=0)
     with lock:
         self.assertTrue(lock.is_locked)
         self.assertTrue(lock.check_lock())
         self.assertRaises(FileLockException, lock2.acquire)
     self.assertFalse(lock.is_locked)
     self.assertFalse(lock.check_lock())
Ejemplo n.º 9
0
 def test_process(self):
     '''
     Test of double locking.
     '''
     lock = FileLock('lock-test')
     lock.acquire()
     process = Process(target=self.second_lock)
     process.start()
     process.join()
     self.assertEqual(process.exitcode, 1)
     lock.release()
     process = Process(target=self.second_lock)
     process.start()
     process.join()
     self.assertEqual(process.exitcode, 0)
Ejemplo n.º 10
0
 def test_process(self):
     """Test of double locking."""
     lock = FileLock(self.testfile)
     lock.acquire()
     try:
         process = Process(target=self.second_lock)
         process.start()
         process.join()
         self.assertEqual(process.exitcode, 1)
     finally:
         lock.release()
     process = Process(target=self.second_lock)
     process.start()
     process.join()
     self.assertEqual(process.exitcode, 0)
Ejemplo n.º 11
0
 def git_lock(self):
     '''
     Returns lock object for current translation instance.
     '''
     if self._lock is None:
         self._lock = FileLock(self.get_git_lock_path(), timeout=20)
     return self._lock
Ejemplo n.º 12
0
 def test_lock(self):
     """Basic locking test."""
     lock = FileLock(self.testfile)
     lock.acquire()
     self.assertTrue(lock.is_locked)
     self.assertTrue(lock.check_lock())
     lock.release()
     self.assertFalse(lock.is_locked)
     self.assertFalse(lock.check_lock())
Ejemplo n.º 13
0
 def test_lock(self):
     '''
     Basic locking test.
     '''
     lock = FileLock('lock-test')
     lock.acquire()
     self.assertTrue(lock.is_locked)
     self.assertTrue(lock.check_lock())
     lock.release()
     self.assertFalse(lock.is_locked)
     self.assertFalse(lock.check_lock())
Ejemplo n.º 14
0
 def test_lock_twice(self):
     '''
     Basic locking test.
     '''
     lock = FileLock(self.testfile)
     lock.acquire()
     lock.acquire()
     self.assertTrue(lock.is_locked)
     lock.release()
     self.assertTrue(lock.is_locked)
     lock.release()
     self.assertFalse(lock.is_locked)
Ejemplo n.º 15
0
 def test_lock(self):
     """Basic locking test."""
     lock = FileLock(self.testfile)
     lock.acquire()
     self.assertTrue(lock.is_locked)
     self.assertTrue(lock.check_lock())
     lock.release()
     self.assertFalse(lock.is_locked)
     self.assertFalse(lock.check_lock())
Ejemplo n.º 16
0
    def repository_lock(self):
        '''
        Returns lock object for current translation instance.
        '''
        if self.is_repo_link:
            return self.linked_subproject.repository_lock

        if self._repository_lock is None:
            lock_path = os.path.join(self.project.get_path(),
                                     self.slug + '.lock')
            self._repository_lock = FileLock(lock_path, timeout=30)
        return self._repository_lock
Ejemplo n.º 17
0
 def __init__(self, path, branch=None, component=None):
     self.path = path
     if branch is None:
         self.branch = self.default_branch
     else:
         self.branch = branch
     self.component = component
     self.last_output = ''
     self.lock = FileLock(self.path.rstrip('/').rstrip('\\') + '.lock',
                          timeout=120)
     if not self.is_valid():
         self.init()
Ejemplo n.º 18
0
 def test_stale(self):
     """Handling of stale lock files."""
     lock = FileLock(self.testfile)
     lockfile = open(lock.lockfile, 'w')
     lock.acquire()
     lockfile.close()
     lock.release()
Ejemplo n.º 19
0
 def second_lock(self):
     lock = FileLock(self.testfile, timeout=0)
     try:
         lock.acquire()
     except FileLockException:
         sys.exit(1)
     lock.release()
Ejemplo n.º 20
0
 def test_stale(self):
     '''
     Handling of stale lock files.
     '''
     lock = FileLock('lock-test')
     lockfile = open(lock.lockfile, 'w')
     lock.acquire()
     lockfile.close()
     lock.release()
Ejemplo n.º 21
0
 def __init__(self, path, branch=None, component=None, local=False):
     self.path = path
     if branch is None:
         self.branch = self.default_branch
     else:
         self.branch = branch
     self.component = component
     self.last_output = ''
     self.lock = FileLock(self.path.rstrip('/').rstrip('\\') + '.lock',
                          timeout=120)
     if not local:
         # Create ssh wrapper for possible use
         create_ssh_wrapper()
     if not self.is_valid():
         self.init()
Ejemplo n.º 22
0
 def test_process(self):
     '''
     Test of double locking.
     '''
     lock = FileLock(self.testfile)
     lock.acquire()
     process = Process(target=self.second_lock)
     process.start()
     process.join()
     self.assertEqual(process.exitcode, 1)
     lock.release()
     process = Process(target=self.second_lock)
     process.start()
     process.join()
     self.assertEqual(process.exitcode, 0)
Ejemplo n.º 23
0
 def test_double(self):
     '''
     Test of double locking.
     '''
     lock1 = FileLock(self.testfile)
     lock2 = FileLock(self.testfile, timeout=0)
     lock1.acquire()
     self.assertRaises(FileLockException, lock2.acquire)
     lock1.release()
     lock2.acquire()
     lock2.release()
Ejemplo n.º 24
0
 def test_lock_invalid(self):
     '''
     Basic locking test.
     '''
     lock = FileLock(os.path.join(self.testdir, 'invalid', 'lock', 'path'))
     self.assertRaises(OSError, lock.acquire)
Ejemplo n.º 25
0
 def second_lock(self):
     lock = FileLock(self.testfile, timeout=0)
     lock.acquire()
     lock.release()
Ejemplo n.º 26
0
 def second_lock(self):
     lock = FileLock(self.testfile, timeout=0)
     lock.acquire()
     lock.release()
Ejemplo n.º 27
0
 def test_lock_invalid(self):
     '''
     Basic locking test.
     '''
     lock = FileLock('/invalid/lock/path')
     self.assertRaises(OSError, lock.acquire)
Ejemplo n.º 28
0
 def second_lock(self):
     lock = FileLock('lock-test', timeout=0)
     lock.acquire()
     lock.release()
Ejemplo n.º 29
0
 def lock(self):
     """Returns lock object for the repository"""
     if self._lock is None:
         self._lock = FileLock(self.path.rstrip('/') + '.lock', timeout=30)
     return self._lock