]> scripts.mit.edu Git - wizard.git/commitdiff
Implement parametrization.
authorEdward Z. Yang <ezyang@mit.edu>
Sat, 1 Aug 2009 06:14:11 +0000 (02:14 -0400)
committerEdward Z. Yang <ezyang@mit.edu>
Sat, 1 Aug 2009 06:14:11 +0000 (02:14 -0400)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
wizard/app/__init__.py
wizard/app/mediawiki.py
wizard/command/upgrade.py
wizard/deploy.py

index 1e924335a5c2f2cad31f95ea66eac44ce3b4a2fa..4f8448e9ae7e47c23fd5c82c75647eface50cdb7 100644 (file)
@@ -24,3 +24,4 @@ def filename_regex_extractor(f):
             return match.group(2)
         return h
     return g
+
index d36d93874021b31dcf2b193f0ec1584689036fd8..50be96c76a56750ce83103e2056d3b4ccdc47e76 100644 (file)
@@ -4,11 +4,12 @@ from wizard import app, deploy, util
 from wizard.app import php
 
 def make_filename_regex(var):
-    return 'LocalSettings.php', re.compile('^\$(' + re.escape(var) + r'''\s*=\s*)(.*)(;)$''', re.M)
+    return 'LocalSettings.php', re.compile('^(\$' + re.escape(var) + r'''\s*=\s*)(.*)(;)$''', re.M)
 
 make_extractor = app.filename_regex_extractor(make_filename_regex)
 
 class Application(deploy.Application):
+    parametrized_files = ['LocalSettings.php', 'php.ini']
     @property
     def extractors(self):
         if not self._extractors:
index 2af853cccbc16b43edc6ebdd51028d179b3cd0f5..b81ba4ada3604f0d9119ad61d6ac616bf890fff8 100644 (file)
@@ -55,10 +55,11 @@ def main(argv, baton):
             except util.NoOperatorInfo:
                 pass
             # naive merge algorithm:
-            sh.call("git", "merge", "-m", message, "scripts/master")
+            sh.call("git", "merge", "-m", message, "scripts/master")
             # crazy merge algorithm:
-            #original_scripts_tag = d # something here
-            #sh.call("git", "checkout", original_scripts_tag)
+            original_scripts_tag = "v" + str(d.version)
+            sh.call("git", "checkout", original_scripts_tag)
+            d.parametrize(temp_wc_dir)
         except shell.CallError:
             print temp_wc_dir
             raise MergeFailed
index 2736a7cba03b21e3d4f8a48d02a9217fbd80a5ae..1541a58fcb3048763d46991441993a79cc82ea17 100644 (file)
@@ -2,6 +2,7 @@ import os.path
 import fileinput
 import dateutil.parser
 import distutils.version
+import tempfile
 
 import wizard
 from wizard import log
@@ -50,7 +51,7 @@ class Deployment(object):
                         if you don't mind having stale data; generally
                         'wizard list' and commands that operate of of the
                         versions store will set this."""
-        self.location = location
+        self.location = os.path.realpath(location)
         self._app_version = version
         # some cache variables
         self._read_cache = {}
@@ -65,6 +66,11 @@ class Deployment(object):
     def extract(self):
         """Extracts all the values of all variables from deployment."""
         return self.application.extract(self)
+    def parametrize(self, dir):
+        """Edits files in dir to replace WIZARD_* variables with literal
+        instances.  This is used for constructing virtual merge bases, and
+        as such dir will generally not equal self.location."""
+        return self.application.parametrize(self, dir)
     def updateVersion(self, version):
         """Bump the version of this deployment.
 
@@ -136,11 +142,13 @@ class Deployment(object):
 class Application(object):
     """Represents the generic notion of an application, i.e.
     mediawiki or phpbb."""
+    parametrized_files = []
     def __init__(self, name):
         self.name = name
         self.versions = {}
         # cache variables
         self._extractors = {}
+        self._parametrizers = {}
     @property
     def repository(self):
         """Returns the Git repository that would contain this application."""
@@ -158,6 +166,22 @@ class Application(object):
         for k,extractor in self.extractors.items():
             result[k] = extractor(deployment)
         return result
+    def parametrize(self, deployment, dir):
+        """Takes a generic source checkout at dir and parametrizes
+        it according to the values of deployment."""
+        variables = deployment.extract()
+        for file in self.parametrized_files:
+            fullpath = os.path.join(dir, file)
+            f = open(fullpath, "r")
+            contents = f.read()
+            f.close()
+            for key, value in variables.items():
+                if value is None: continue
+                contents = contents.replace(key, value)
+            tmp = tempfile.NamedTemporaryFile(delete=False)
+            tmp.write(contents)
+            tmp.close()
+            os.rename(tmp.name, fullpath)
     @property
     def extractors(self):
         return {}