]> scripts.mit.edu Git - wizard.git/commitdiff
Fix wizard -> wizard_bin bug, fix dry run, create .scripts/variables
authorEdward Z. Yang <ezyang@mit.edu>
Fri, 31 Jul 2009 02:12:17 +0000 (22:12 -0400)
committerEdward Z. Yang <ezyang@mit.edu>
Fri, 31 Jul 2009 02:12:17 +0000 (22:12 -0400)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
wizard/app/mediawiki.py
wizard/command/migrate.py
wizard/deploy.py
wizard/shell.py

index 15d3e429723e7e838893197aeeba08b0c22aa44f..d36d93874021b31dcf2b193f0ec1584689036fd8 100644 (file)
@@ -13,7 +13,7 @@ class Application(deploy.Application):
     def extractors(self):
         if not self._extractors:
             self._extractors = util.dictmap(make_extractor,
-                {'WIZARD_IP': 'IP' # obsolete
+                {'WIZARD_IP': 'IP' # obsolete, remove after we're done
                 ,'WIZARD_SITENAME': 'wgSitename'
                 ,'WIZARD_SCRIPTPATH': 'wgScriptPath'
                 ,'WIZARD_EMERGENCYCONTACT': 'wgEmergencyContact'
index cfe461929779b022c452119c14aceecbc40844d3..fd39dbe1cbd78c8a02b39ae3f0d349075743e98a 100644 (file)
@@ -15,7 +15,8 @@ def main(argv, baton):
     command.chdir(dir)
     check_if_already_migrated(options)
 
-    version = calculate_version()
+    deployment = make_deployment() # uses chdir
+    version = deployment.app_version
     repo    = version.application.repository
     tag     = version.scripts_tag
 
@@ -24,8 +25,12 @@ def main(argv, baton):
     sh = shell.Shell(options.dry_run)
     check_if_tag_exists(sh, repo, tag)
     make_repository(sh, options, repo, tag)
+    make_variables(deployment, options)
 
-    os.rename(".scripts-version", ".scripts/old-version") # archive
+    if not options.dry_run:
+        os.rename(".scripts-version", ".scripts/old-version") # archive
+    else:
+        logging.info("mv .scripts-version .scripts/old-version")
 
 def parse_args(argv):
     usage = """usage: %prog migrate [ARGS] DIR
@@ -61,10 +66,9 @@ def check_if_already_migrated(options):
                 logging.warning("Force removing .scripts directory")
                 if not options.dry_run: shutil.rmtree(".scripts")
 
-def calculate_version():
+def make_deployment():
     try:
-        d = deploy.Deployment.fromDir(".")
-        return d.app_version
+        return deploy.Deployment(".")
     except IOError as e:
         if e.errno == errno.ENOENT:
             raise NotAutoinstallError(dir)
@@ -125,6 +129,24 @@ def make_repository(sh, options, repo, tag):
         except shell.CallError:
             pass
 
+def make_variables(d, options):
+    """Make .scripts/variables which contains variables based off of
+    what was regexed out of existing configuration files."""
+    variables = d.extract()
+    if not options.dry_run: f = open(".scripts/variables", "w")
+    for k,v in variables.items():
+        if v is None:
+            # once we get everything on the same version, you should
+            # actually start paying attention to these warnings
+            logging.warning("Variable %s not found" % k)
+        else:
+            logging.debug("Variable %s is %s" % (k,v))
+            if not options.dry_run:
+                f.write("%s %s\n" % (k,v))
+            else:
+                logging.info('# write line "%s %s" to .scripts/variables' % (k,v))
+    if not options.dry_run: f.close()
+
 class Error(command.Error):
     """Base exception for all exceptions raised by migrate"""
     pass
index 7908f03791591c3fd95a7066ea63b01e14517701..fa0085b1007c0d2844aa8584990509dc757123c3 100644 (file)
@@ -35,6 +35,8 @@ class Deployment(object):
             self._read_cache[file] = f.read()
             f.close()
         return self._read_cache[file]
+    def extract(self):
+        return self.application.extract(self)
     @property
     def version_file(self):
         return os.path.join(self.location, '.scripts-version')
index bf7e172fb1132711ea675156c5da18a4065e73ca..3ed61a323537024a30edbd30f3b554e96bfc6129 100644 (file)
@@ -8,10 +8,10 @@ from wizard import util
 
 """This is the path to the wizard executable as specified
 by the caller; it lets us recursively invoke wizard"""
-wizard = sys.argv[0]
+wizard_bin = sys.argv[0]
 
 def is_python(args):
-    return args[0] == "python" or args[0] == wizard
+    return args[0] == "python" or args[0] == wizard_bin
 
 class Shell(object):
     """An advanced shell, with the ability to do dry-run and log commands"""