def __exit__(self, *args):
signal.signal(signal.SIGINT, signal.default_int_handler)
+class LockDirectory(object):
+ """
+ Context for locking a directory.
+ """
+ def __init__(self, lockfile):
+ self.lockfile = lockfile
+ def __enter__(self):
+ try:
+ os.open(self.lockfile, os.O_CREAT | os.O_EXCL)
+ except OSError as e:
+ if e.errno == errno.EEXIST:
+ raise DirectoryLockedError(os.getcwd())
+ elif e.errno == errno.EACCES:
+ raise command.PermissionsError(os.getcwd())
+ raise
+ def __exit__(self, *args):
+ try:
+ os.unlink(self.lockfile)
+ except OSError:
+ pass
+
def chdir(dir):
"""
Changes a directory, but has special exceptions for certain
class NoSuchDirectoryError(IOError):
errno = errno.ENOENT
+
+class DirectoryLockedError(wizard.Error):
+ def __init__(self, dir):
+ self.dir = dir
+ def __str__(self):
+ return """
+
+ERROR: Could not acquire lock on directory. Maybe there is
+another migration process running?
+"""
+