X-Git-Url: https://scripts.mit.edu/gitweb/wizard.git/blobdiff_plain/98af8454c63eac3d49414275111c2e44addf81e6..430c57db12f96825e907aae5359a69497b5c8544:/wizard/app/__init__.py diff --git a/wizard/app/__init__.py b/wizard/app/__init__.py index 867a106..391f8d8 100644 --- a/wizard/app/__init__.py +++ b/wizard/app/__init__.py @@ -51,6 +51,9 @@ def applications(): _applications = dict([(n,Application.make(n)) for n in _application_list ]) return _applications +def getApplication(appname): + """Retrieves application instance given a name""" + return applications()[appname] class Application(object): """ @@ -237,58 +240,10 @@ 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 - if util.mixed_newlines(file): - # this code only works on Unix - def get_newline(filename): - f = open(filename, "U") - # for some reason I need two - f.readline() - f.readline() - if not isinstance(f.newlines, str): - raise Exception("Assert: expected newlines to be string, instead was %s" % repr(f.newlines)) - 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) - f.close() - return get_newline(f.name), f.name - def convert(filename, dest_nl): - contents = open(filename, "U").read().replace("\n", dest_nl) - open(filename, "wb").write(contents) - logging.info("Mixed newlines detected in %s", file) - common_nl, common_file = create_reference(1) - our_nl, our_file = create_reference(2) - their_nl, their_file = create_reference(3) - remerge = False - if common_nl != their_nl: - # upstream can't keep their newlines straight - logging.info("Converting common file (1) from %s to %s newlines", repr(common_nl), repr(their_nl)) - convert(common_file, their_nl) - remerge = True - if our_nl != their_nl: - # common case - logging.info("Converting our file (2) from %s to %s newlines", repr(our_nl), repr(their_nl)) - convert(our_file, their_nl) - remerge = True - if remerge: - 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) - logging.info("New merge was clean") - sh.call("git", "add", file) - continue - except shell.CallError: - pass - logging.info("Merge was still unclean") - else: - logging.warning("Mixed newlines detected in %s, but no remerge possible", file) # manual resolutions if file in self.resolutions: contents = open(file, "r").read() @@ -299,7 +254,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: @@ -680,13 +635,11 @@ 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: - shutil.rmtree(outdir) raise BackupFailure(e.stderr) def restore_database(backup_dir, deployment): @@ -703,13 +656,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): @@ -717,10 +669,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