]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/command/migrate.py
Implement locks for upgrade, add d.upgrade()
[wizard.git] / wizard / command / migrate.py
index 4e5837d73d30ae0439d135bc59759a0af559a8ab..3949ae8ced0dd1b4d8242009dd5582aa5b8ec159 100644 (file)
@@ -47,16 +47,8 @@ def main(argv, baton):
     tag     = version.scripts_tag
 
     # XXX: turn this into a context
-    try:
+    with util.LockDirectory(".scripts-migrate-lock"):
         try:
-            try:
-                os.open(".scripts-migrate-lock", os.O_CREAT | os.O_EXCL)
-            except OSError as e:
-                if e.errno == errno.EEXIST:
-                    raise DirectoryLockedError
-                elif e.errno == errno.EACCES:
-                    raise command.PermissionsError(dir)
-                raise
             if options.force: perform_force(options)
             make_repository(sh, options, repo, tag)
             check_variables(deployment, options)
@@ -67,11 +59,6 @@ def main(argv, baton):
                 shutil.rmtree(".scripts")
             if os.path.exists(".git"):
                 shutil.rmtree(".git")
-    finally:
-        try:
-            os.unlink(".scripts-migrate-lock")
-        except OSError:
-            pass
 
 def parse_args(argv, baton):
     usage = """usage: %prog migrate [ARGS] DIR
@@ -174,13 +161,3 @@ ERROR: Directory already contains a .git and
 both of these directories will be removed.
 """
 
-class DirectoryLockedError(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?
-"""
-