Beispiel #1
0
def lock(lockFile):
    """
    Creates a lock file if one is not present.  If a lock file already exists,
    an exception will be thrown.
    """
    if os.path.exists(lockFile):
        with open(lockFile) as lock:
            pid = lock.readline()
        if not re.match(r"^[0-9]+$", pid):
            os.remove(lockFile)
        elif _isPidRunning(pid):
            raise Exception("A backup is currently running [{}]".format(pid))
        else:
            os.remove(lockFile)
    backup.createLockFile(lockFile)
Beispiel #2
0
 def test_removeLockFile(self):
     lockFile = join(self._backupHome, "test.lock")
     backup.createLockFile(lockFile)
     backup.removeLockFile(lockFile)
     self.assertFalse(os.path.exists(lockFile))