def test_lock_twice_with_unlock(lock_dir_path, key_path, lock_type): exclusive = LOCK_TYPES[lock_type] assert dirlock.trylock( path=lock_dir_path, excl=exclusive, key_path=key_path ) unlock(lock_dir_path, key_path) assert dirlock.trylock( path=lock_dir_path, excl=exclusive, key_path=key_path )
def test_lock_twice(lock_dir_path, key_path, lock_type): exclusive = LOCK_TYPES[lock_type] assert dirlock.trylock( path=lock_dir_path, excl=exclusive, key_path=key_path ) if exclusive: assert not dirlock.trylock( path=lock_dir_path, excl=exclusive, key_path=key_path ) else: assert dirlock.trylock( path=lock_dir_path, excl=exclusive, key_path=key_path )
def test_lock_once(lock_dir_path, key_path, lock_type): assert dirlock.trylock( path=lock_dir_path, excl=LOCK_TYPES[lock_type], key_path=key_path )
def trylock_exclusive(lock_dir_path, key_path): return dirlock.trylock(lock_dir_path, True, key_path)
if __name__ == '__main__': logging.basicConfig( stream=sys.stdout, level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) optlist, args = getopt.gnu_getopt(sys.argv[1:], '', ['create=']) templates_dir = args[0] create_url = None for opt, arg in optlist: if opt == '--create': create_url = arg if create_url: initialize(templates_dir, create_url) fd, temp_path = tempfile.mkstemp() os.write(fd, uuid.uuid1().hex) os.close(fd) try: if dirlock.trylock(templates_dir, True, temp_path): logging.info('Successfully locked templates directory') update(templates_dir) else: logging.info('Skipping templates update, templates in use') finally: os.unlink(temp_path)
def trylock_uuid(testdir, excl): return dirlock.trylock(testdir, excl, prefix.paths.uuid())