]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/app/__init__.py
Convert ad hoc shell calls to singleton instance; fix upgrade bug.
[wizard.git] / wizard / app / __init__.py
index 4b64f8034eaf4aa99e4eb553d1b1c14aeaf7b2c8..1d01966363bb45863db242c6f4120fdf7c7c372e 100644 (file)
@@ -237,14 +237,13 @@ class Application(object):
         default implementation uses :attr:`resolutions`.
         """
         resolved = True
-        sh = shell.Shell()
         files = set()
-        for status in sh.eval("git", "ls-files", "--unmerged").splitlines():
+        for status in shell.eval("git", "ls-files", "--unmerged").splitlines():
             files.add(status.split()[-1])
         for file in files:
             # check for newline mismatch
             # HACK: using git diff to tell if files are binary or not
-            if not len(sh.eval("git", "diff", file).splitlines()) == 1 and util.mixed_newlines(file):
+            if not len(shell.eval("git", "diff", file).splitlines()) == 1 and util.mixed_newlines(file):
                 # this code only works on Unix
                 def get_newline(filename):
                     f = open(filename, "U")
@@ -257,7 +256,7 @@ class Application(object):
                     return f.newlines
                 def create_reference(id):
                     f = tempfile.NamedTemporaryFile(prefix="wizardResolve", delete=False)
-                    sh.call("git", "cat-file", "blob", ":%d:%s" % (id, file), stdout=f)
+                    shell.call("git", "cat-file", "blob", ":%d:%s" % (id, file), stdout=f)
                     f.close()
                     return get_newline(f.name), f.name
                 def convert(filename, dest_nl):
@@ -282,9 +281,9 @@ class Application(object):
                     logging.info("Remerging %s", file)
                     with open(file, "wb") as f:
                         try:
-                            sh.call("git", "merge-file", "--stdout", our_file, common_file, their_file, stdout=f)
+                            shell.call("git", "merge-file", "--stdout", our_file, common_file, their_file, stdout=f)
                             logging.info("New merge was clean")
-                            sh.call("git", "add", file)
+                            shell.call("git", "add", file)
                             continue
                         except shell.CallError:
                             pass
@@ -301,7 +300,7 @@ class Application(object):
                         logging.info("Did resolution with spec:\n" + spec)
                 open(file, "w").write(contents)
                 if not resolve.is_conflict(contents):
-                    sh.call("git", "add", file)
+                    shell.call("git", "add", file)
                 else:
                     resolved = False
             else:
@@ -682,11 +681,10 @@ def backup_mysql_database(outdir, deployment):
     """
     Database backups for MySQL using the :command:`mysqldump` utility.
     """
-    sh = shell.Shell()
     outfile = os.path.join(outdir, "db.sql")
     try:
-        sh.call("mysqldump", "--compress", "-r", outfile, *get_mysql_args(deployment.dsn))
-        sh.call("gzip", "--best", outfile)
+        shell.call("mysqldump", "--compress", "-r", outfile, *get_mysql_args(deployment.dsn))
+        shell.call("gzip", "--best", outfile)
     except shell.CallError as e:
         raise BackupFailure(e.stderr)
 
@@ -704,13 +702,12 @@ def restore_mysql_database(backup_dir, deployment):
     """
     Database restoration for MySQL by piping SQL commands into :command:`mysql`.
     """
-    sh = shell.Shell()
     if not os.path.exists(backup_dir):
         raise RestoreFailure("Backup %s doesn't exist", backup_dir.rpartition("/")[2])
     sql = open(os.path.join(backup_dir, "db.sql"), 'w+')
-    sh.call("gunzip", "-c", os.path.join(backup_dir, "db.sql.gz"), stdout=sql)
+    shell.call("gunzip", "-c", os.path.join(backup_dir, "db.sql.gz"), stdout=sql)
     sql.seek(0)
-    sh.call("mysql", *get_mysql_args(deployment.dsn), stdin=sql)
+    shell.call("mysql", *get_mysql_args(deployment.dsn), stdin=sql)
     sql.close()
 
 def remove_database(deployment):
@@ -718,10 +715,9 @@ def remove_database(deployment):
     Generic database removal function.  Actually, not so generic because we
     go and check if we're on scripts and if we are run a different command.
     """
-    sh = shell.Shell()
     if deployment.dsn.host == "sql.mit.edu":
         try:
-            sh.call("/mit/scripts/sql/bin/drop-database", deployment.dsn.database)
+            shell.call("/mit/scripts/sql/bin/drop-database", deployment.dsn.database)
             return
         except shell.CallError:
             pass