]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/app/wordpress.py
Move wizard.scripts module to plugins, added hooks accordingly.
[wizard.git] / wizard / app / wordpress.py
index 62a41389b30d037b075bed11c29a603b45990097..65b99e763f61501b3a3baabf149b781be6efdd3b 100644 (file)
@@ -4,6 +4,7 @@ import logging
 import distutils
 import urlparse
 import hashlib
+import sqlalchemy.exc
 
 from wizard import app, install, resolve, sql, util
 from wizard.app import php
@@ -35,20 +36,25 @@ class Application(app.Application):
     install_schema = install.ArgSchema("db", "admin", "email", "title")
     deprecated_keys = set(['WIZARD_SECRETKEY'])
     random_keys = set(['WIZARD_SECRETKEY', 'WIZARD_AUTH_KEY', 'WIZARD_SECURE_AUTH_KEY', 'WIZARD_LOGGED_IN_KEY', 'WIZARD_NONCE_KEY'])
+    random_blacklist = set(['put your unique phrase here'])
+    def urlFromExtract(self, deployment):
+        try:
+            meta = sql.connect(deployment.dsn)
+            wp_options = meta.tables["wp_options"]
+            query = wp_options.select(wp_options.c.option_name == 'home')
+            return query.execute().fetchone()['option_value']
+        except sqlalchemy.exc.OperationalError:
+            return None
     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 checkWeb(self, deployment):
-        # XXX: this sucks pretty hard
-        return self.checkWebPage(deployment, "", "<html")
+        return self.checkWebPage(deployment, "",
+                outputs=["<html", "WordPress", "feed"],
+                exclude=["Error establishing a database connection"])
     def detectVersion(self, deployment):
         return self.detectVersionFromFile("wp-includes/version.php", php.re_var("wp_version"))
-    def prepareMerge(self, deployment):
-        # This file shouldn't really be edited by users, but be careful: it's
-        # stored as DOS and not as UNIX, so you'll get conflicts if you add this line:
-        # resolve.fix_newlines("wp-config.php")
-        pass
     def install(self, version, options):
         util.soft_unlink("wp-config.php")
 
@@ -105,6 +111,16 @@ class Application(app.Application):
         pluggable_file.write(pluggable)
         pluggable_file.close()
 
+        # replace random variable stubs with real values
+        old_config = open('wp-config.php').read()
+        def replace_with_random(s):
+            return s.replace('put your unique phrase here', util.random_key(), 1)
+        config = replace_with_random(old_config)
+        while config != old_config:
+            old_config = config
+            config = replace_with_random(config)
+        open('wp-config.php', 'w').write(config)
+
         php.ini_replace_vars()
     def upgrade(self, d, version, options):
         result = d.fetch("wp-admin/upgrade.php?step=1")