From 1ca054c2fbdd3d3776e98d81476c71414fb16663 Mon Sep 17 00:00:00 2001 From: Aman Sharma Date: Sat, 9 Nov 2019 14:34:19 +0530 Subject: [PATCH] Move error message to a constant --- dvc/lock.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/dvc/lock.py b/dvc/lock.py index dc6c52b23..777afa031 100644 --- a/dvc/lock.py +++ b/dvc/lock.py @@ -16,6 +16,12 @@ from dvc.utils.compat import is_py3 DEFAULT_TIMEOUT = 5 +ERROR_MESSAGE = ( + "cannot perform the cmd since DVC is busy and locked. You can delete " + ".dvc/lock to fix it, but first please make sure there's no other dvc " + "process ongoing by running: {blue}`ps xaf | grep dvc`{nc}." +).format(blue=colorama.Back.BLUE, nc=colorama.Back.RESET) + class LockError(DvcException): """Thrown when unable to acquire the lock for dvc repo.""" @@ -72,14 +78,7 @@ if is_py3: try: super(Lock, self).lock(timedelta(seconds=DEFAULT_TIMEOUT)) except flufl.lock.TimeOutError: - raise LockError( - "cannot perform the cmd since DVC is busy and " - "locked. You can delete .dvc/lock to fix it, but first " - "please make sure there's no other dvc process ongoing " - "by running: {blue}`ps xaf | grep dvc`{nc}.".format( - blue=colorama.Back.BLUE, nc=colorama.Back.RESET - ) - ) + raise LockError(ERROR_MESSAGE) def _set_claimfile(self, pid=None): super(Lock, self)._set_claimfile(pid) @@ -124,14 +123,7 @@ else: try: self._lock = zc.lockfile.LockFile(self.lockfile) except zc.lockfile.LockError: - raise LockError( - "cannot perform the cmd since DVC is busy and " - "locked. You can delete .dvc/lock to fix it, but first " - "please make sure there's no other dvc process ongoing " - "by running: {blue}`ps xaf | grep dvc`{nc}.".format( - blue=colorama.Back.BLUE, nc=colorama.Back.RESET - ) - ) + raise LockError(ERROR_MESSAGE) def lock(self): try: