]> scripts.mit.edu Git - wizard.git/commitdiff
Add version detection.
authorEdward Z. Yang <ezyang@mit.edu>
Sat, 22 Aug 2009 02:21:35 +0000 (22:21 -0400)
committerEdward Z. Yang <ezyang@mit.edu>
Sat, 22 Aug 2009 02:21:35 +0000 (22:21 -0400)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
wizard/app/mediawiki.py
wizard/command/upgrade.py
wizard/deploy.py

index 40358cec594806fc38cc9ce9236ec299f4073fa9..ef7c1ea605de7c6b5f2de0bd8346cb8aac35fb6c 100644 (file)
@@ -1,4 +1,5 @@
 import re
+import distutils.version
 import os
 
 from wizard import app, deploy, install, shell, util
@@ -43,6 +44,12 @@ class Application(deploy.Application):
         return handler
     def checkConfig(self, deployment):
         return os.path.isfile(os.path.join(deployment.location, "LocalSettings.php"))
+    def detectVersion(self, deployment):
+        contents = deployment.read("includes/DefaultSettings.php")
+        regex = make_filename_regex("wgVersion")[1]
+        match = regex.search(contents)
+        if not match: return None
+        return distutils.version.LooseVersion(match.group(2)[1:-1])
     def install(self, options):
         try:
             os.unlink("LocalSettings.php")
index 1867d51affb316b89689f4f00ecf0f2b872e2bec..ab7bfc71d44ff8154af0e2a54f582f80f3fe41b2 100644 (file)
@@ -28,6 +28,7 @@ def main(argv, baton):
         d.verifyTag(options.srv_path)
         d.verifyGit(options.srv_path)
         d.verifyConfigured()
+        d.verifyVersion()
         repo = d.application.repository(options.srv_path)
         version = calculate_newest_version(sh, repo)
         if version == d.app_version.scripts_tag:
@@ -183,3 +184,4 @@ temporary directory, finding conflicted files with `git status`,
 resolving the files, adding them using `git add`, and then
 committing your changes with `git commit` (your log message
 will be ignored), and then running `wizard upgrade --continue`."""
+
index e591d36426ba46ecd288b6b636513cae56ea761b..89f8232c681d124be16859cf8cf67b9758e1f324 100644 (file)
@@ -174,6 +174,17 @@ class Deployment(object):
         if not self.configured:
             raise NotConfiguredError(self.location)
 
+    def verifyVersion(self):
+        """
+        Checks if our version and the version number recorded in a file
+        are consistent.
+        """
+        real = self.application.detectVersion(self)
+        if not real:
+            raise VersionDetectionError
+        elif not str(real) == self.app_version.pristine_tag.partition('-')[2]:
+            raise VersionMismatchError(real, self.version)
+
     @property
     def configured(self):
         """Whether or not an autoinstall has been configured/installed for use."""
@@ -340,6 +351,11 @@ class Application(object):
         non-versioned data in an application.
         """
         raise NotImplemented
+    def detectVersion(self, deployment):
+        """
+        Checks source files to determine the version manually.
+        """
+        return None
     @property
     def extractors(self):
         """
@@ -582,6 +598,22 @@ ERROR: HEAD is not a descendant of %s.  This probably
 means that an upstream rebase occurred, and new tags were
 pulled, but local user commits were never rebased.""" % self.tag
 
+class VersionDetectionError(Error):
+    def __str__(self):
+        return """
+
+ERROR: Could not detect the real version of the application."""
+
+class VersionMismatchError(Error):
+    def __init__(self, real_version, git_version):
+        self.real_version = real_version
+        self.git_version = git_version
+    def __str__(self):
+        return """
+
+ERROR: The detected version %s did not match the Git
+version %s.""" % (self.real_version, self.git_version)
+
 _application_list = [
     "mediawiki", "wordpress", "joomla", "e107", "gallery2",
     "phpBB", "advancedbook", "phpical", "trac", "turbogears", "django",