From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 6AA97138351 for ; Thu, 30 Apr 2020 22:56:26 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 22D2FE0A7D; Thu, 30 Apr 2020 22:56:25 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id CAC5EE0A7C for ; Thu, 30 Apr 2020 22:56:24 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D530534F0C7 for ; Thu, 30 Apr 2020 22:56:23 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 7E2FA200 for ; Thu, 30 Apr 2020 22:56:22 +0000 (UTC) From: "Matt Turner" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Matt Turner" Message-ID: <1587666035.be43719867e694a08699aa07c2f5f519df26b59b.mattst88@gentoo> Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/lock.py X-VCS-Directories: catalyst/ X-VCS-Committer: mattst88 X-VCS-Committer-Name: Matt Turner X-VCS-Revision: be43719867e694a08699aa07c2f5f519df26b59b X-VCS-Branch: master Date: Thu, 30 Apr 2020 22:56:22 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: ae7c06c5-d744-46b7-bdb5-e06be8b82f26 X-Archives-Hash: 04d648a325a130b9ec393ca362782841 commit: be43719867e694a08699aa07c2f5f519df26b59b Author: Matt Turner gentoo org> AuthorDate: Sat Apr 18 04:33:52 2020 +0000 Commit: Matt Turner gentoo org> CommitDate: Thu Apr 23 18:20:35 2020 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=be437198 catalyst: Add read/write_lock contextmanagers Signed-off-by: Matt Turner gentoo.org> catalyst/lock.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/catalyst/lock.py b/catalyst/lock.py index ab005163..e31745b2 100644 --- a/catalyst/lock.py +++ b/catalyst/lock.py @@ -1,6 +1,8 @@ import os +from contextlib import contextmanager + from snakeoil import fileutils from snakeoil import osutils from catalyst.fileops import ensure_dirs @@ -36,3 +38,21 @@ class LockDir(Lock): lockfile = os.path.join(lockdir, '.catalyst_lock') Lock.__init__(self, lockfile) + +@contextmanager +def read_lock(filename): + lock = Lock(filename) + lock.read_lock() + try: + yield + finally: + lock.unlock() + +@contextmanager +def write_lock(filename): + lock = Lock(filename) + lock.write_lock() + try: + yield + finally: + lock.unlock()