]> scripts.mit.edu Git - wizard.git/commitdiff
Implement Wordpress installer for 2.0.2 w/ sqlalchemy.
authorEdward Z. Yang <ezyang@mit.edu>
Tue, 3 Nov 2009 02:37:28 +0000 (21:37 -0500)
committerEdward Z. Yang <ezyang@mit.edu>
Tue, 3 Nov 2009 02:37:28 +0000 (21:37 -0500)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
TODO
tests/test-install-wordpress.sh [new file with mode: 0755]
wizard/app/mediawiki.py
wizard/app/wordpress.py
wizard/command/prepare_new.py
wizard/command/prepare_pristine.py
wizard/install/__init__.py
wizard/sql.py [new file with mode: 0644]

diff --git a/TODO b/TODO
index 34000ff1008d98daef707d21cb25a0085d8cec74..b85c57f03ca1cdd1c57aa099789ec01bea324c68 100644 (file)
--- a/TODO
+++ b/TODO
@@ -118,6 +118,8 @@ OVERALL PLAN:
 
     3. Run wizard `prepare-pristine APP-VERSION`
 
+    X. Commit, with name "Appname x.y.z"
+
     4. Checkout the master branch
 
     5. [FOR EXISTING REPOSITORIES]
diff --git a/tests/test-install-wordpress.sh b/tests/test-install-wordpress.sh
new file mode 100755 (executable)
index 0000000..68a6b6c
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/bash -e
+
+TESTNAME="upgrade_wordpress"
+source ./setup
+
+#wizard install wordpress-$VERSION-scripts "$TESTDIR" -- --title="My Blog"
+wizard install wordpress "$TESTDIR" -- --title="My Blog"
index 9a9ea30f9de55a9fc05a3bca30ba9157842c32ae..e94abc213e265c817bb8bd3225d53a94cb24e667 100644 (file)
@@ -27,8 +27,7 @@ class Application(app.Application):
     extractors.update(php.extractors)
     substitutions = app.make_substitutions(seed)
     substitutions.update(php.substitutions)
-    install_schema = install.ArgSchema("mysql", "admin", "email")
-    install_schema.add(install.Arg("title", help="Title of your new MediaWiki install"))
+    install_schema = install.ArgSchema("mysql", "admin", "email", "title")
     def checkConfig(self, deployment):
         return os.path.isfile(os.path.join(deployment.location, "LocalSettings.php"))
     def detectVersion(self, deployment):
index 72cf7314b4a05377d3c9b4f6291cf136a7a38824..93187c551db607b1030fd4c7a85b37cac1b44a04 100644 (file)
@@ -1,6 +1,39 @@
-from wizard import app
+import sqlalchemy
+import os
+
+from wizard import app, install, sql
 from wizard.app import php
 
 class Application(app.Application):
+    install_schema = install.ArgSchema("mysql", "email", "title")
     def download(self, version):
         return "http://wordpress.org/wordpress-%s.tar.gz" % version
+    def install(self, version, options):
+        post_setup_config = {
+                'dbhost': options.mysql_host,
+                'uname': options.mysql_user,
+                'dbname': options.mysql_db,
+                'pwd': options.mysql_password,
+                'prefix': '',
+                'submit': 'Submit',
+                'step': '2',
+                }
+        post_install = {
+                'weblog_title': options.title,
+                'admin_email': options.email,
+                'submit': 'Continue',
+                'step': '2',
+                }
+        old_mode = os.stat(".").st_mode
+        os.chmod(".", 0777) # XXX: squick squick
+        install.fetch(options, "wp-admin/setup-config.php?step=2", post_setup_config)
+        result = install.fetch(options, "wp-admin/install.php?step=2", post_install)
+        os.chmod(".", old_mode)
+        if "Finished" not in result:
+            raise install.Failure()
+
+        # not sure what to do about this
+        meta = sql.mysql_connect(options)
+        wp_options = meta.tables["wp_options"]
+        wp_options.update().where(wp_options.c.option_name == 'siteurl').values(option_value=options.web_path).execute()
+        wp_options.update().where(wp_options.c.option_name == 'home').values(option_value="http://%s%s" % (options.web_host, options.web_path)).execute() # XXX: what if missing leading slash; this should be put in a function
index e6f5952cb121079c725d33567c0d726fd42a4fa0..56416022e23c7ac2ff54df835aa7a1842158ee3e 100644 (file)
@@ -1,9 +1,11 @@
 import os
 
+from wizard import command
+
 def main(argv, baton):
     options, args = parse_args(argv, baton)
     os.mkdir(".scripts")
-    open(".scripts/.htaccess").write("Deny from all\n")
+    open(".scripts/.htaccess", "w").write("Deny from all\n")
 
 def parse_args(argv, baton):
     usage = """usage: %prog prepare-new
index c545cf88f8ae9e8d223e39c89d33bb19d7af4cff..d6ba256552f3b8084aa0a0a15c78ba113919a906 100644 (file)
@@ -17,7 +17,7 @@ def main(argv, baton):
             infile = urllib.urlopen(url)
             shutil.copyfileobj(infile, outfile)
     else:
-        base = os.path.basename(args[0])
+        base = args[0]
     # extract the files, but be smart: if only one directory is output,
     # move the contents of that directory here
     sh.call("tar", "xf", base)
index 6eab708b22cbf4c0fca7b8e25455ffc6d5ac09a5..b22849a190dc6ece92ca46dbb237ec91d7f0483b 100644 (file)
@@ -46,6 +46,7 @@ def preloads():
             'mysql': MysqlArgSet(),
             'admin': AdminArgSet(),
             'email': EmailArgSet(),
+            'title': TitleArgSet(),
             }
 
 class Strategy(object):
@@ -230,6 +231,13 @@ class EmailArgSet(ArgSet):
                 Arg("email", help="Administrative email"),
                 ]
 
+class TitleArgSet(ArgSet):
+    """Common arguments when a title is required."""
+    def __init__(self):
+        self.args = [
+                Arg("title", help="Title of your new site"),
+                ]
+
 class ArgSchema(object):
     """
     Schema container for arguments.
diff --git a/wizard/sql.py b/wizard/sql.py
new file mode 100644 (file)
index 0000000..a0a6387
--- /dev/null
@@ -0,0 +1,15 @@
+import sqlalchemy
+
+def mysql_connect(options):
+    """Convenience method for connecting to a MySQL database."""
+    engine = sqlalchemy.create_engine(sqlalchemy.engine.url.URL(
+        "mysql",
+        username=options.mysql_user,
+        password=options.mysql_password,
+        host=options.mysql_host,
+        database=options.mysql_db,
+        ))
+    meta = sqlalchemy.MetaData()
+    meta.bind = engine
+    meta.reflect()
+    return meta