]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/app/wordpress.py
Implement post-installation machinery for Wordpress.
[wizard.git] / wizard / app / wordpress.py
index 93187c551db607b1030fd4c7a85b37cac1b44a04..123f35507c4119807de83c36eb0b3c280fca60be 100644 (file)
@@ -1,14 +1,50 @@
-import sqlalchemy
 import os
+import re
 
-from wizard import app, install, sql
+from wizard import app, install, resolve, sql, util
 from wizard.app import php
 
+# XXX: We probably want to separate out the re.compile() line
+def make_filename_regex_define(var):
+    return 'wp-config.php', re.compile('^(define\(\'' + app.expand_re(var) + r''''\s*,\s*)(.*)(\);)''', re.M)
+
+seed = util.dictmap(make_filename_regex_define, {
+    'WIZARD_DBSERVER': 'DB_HOST',
+    'WIZARD_DBNAME': 'DB_NAME',
+    'WIZARD_DBUSER': 'DB_USER',
+    'WIZARD_DBPASSWORD': 'DB_PASSWORD',
+    })
+# XXX: I have omitted an implementation for table prefix, on grounds that we
+# do not permit it to be configured. If we do end up growing support for
+# arbitrary table prefixes this should be added.
+
 class Application(app.Application):
+    # XXX: php.ini should be grabbed over from the php module
+    parametrized_files = ['wp-config.php', 'php.ini']
+    extractors = app.make_extractors(seed)
+    extractors.update(php.extractors)
+    substitutions = app.make_substitutions(seed)
+    substitutions.update(php.substitutions)
     install_schema = install.ArgSchema("mysql", "email", "title")
     def download(self, version):
         return "http://wordpress.org/wordpress-%s.tar.gz" % version
+    def checkConfig(self, deployment):
+        return os.path.isfile("wp-config.php")
+    def detectVersion(self, deployment):
+        # XXX: Very duplicate code with MediaWiki; refactor
+        contents = deployment.read("wp-includes/version.php")
+        match = php.re_var("wp_version").search(contents)
+        if not match: return None
+        return distutils.version.LooseVersion(match.group(2)[1:-1])
+    def prepareMerge(self, deployment):
+        resolve.fix_newlines("wp-config.php")
     def install(self, version, options):
+        # XXX: Hmm... we should figure out something about this
+        try:
+            os.unlink("wp-config.php")
+        except OSError:
+            pass
+
         post_setup_config = {
                 'dbhost': options.mysql_host,
                 'uname': options.mysql_user,