Extract DvcLock logic to a separate class

This commit is contained in:
Dmitry Petrov
2017-05-15 19:44:56 -07:00
parent 29de545752
commit 43e80bec4a
9 changed files with 67 additions and 111 deletions
+2 -13
View File
@@ -1,9 +1,8 @@
import os
import fasteners
from boto.s3.connection import S3Connection
from dvc.command.base import CmdBase
from dvc.command.base import CmdBase, DvcLock
from dvc.exceptions import DvcException
from dvc.logger import Logger
from dvc.runtime import Runtime
@@ -30,19 +29,9 @@ class CmdDataRemove(CmdBase):
pass
def run(self):
if self.is_locker:
lock = fasteners.InterProcessLock(self.git.lock_file)
gotten = lock.acquire(timeout=5)
if not gotten:
Logger.info('[Cmd-Remove] Cannot perform the cmd since DVC is busy and locked. Please retry the cmd later.')
return 1
try:
with DvcLock(self.is_locker, self.git):
if not self.remove_all_targets():
return 1
finally:
if self.is_locker:
lock.release()
return 0