]> scripts.mit.edu Git - wizard.git/commitdiff
Implement post-installation machinery for Wordpress.
authorEdward Z. Yang <ezyang@mit.edu>
Wed, 4 Nov 2009 17:48:09 +0000 (12:48 -0500)
committerEdward Z. Yang <ezyang@mit.edu>
Wed, 4 Nov 2009 17:48:09 +0000 (12:48 -0500)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
wizard/app/mediawiki.py
wizard/app/php.py
wizard/app/wordpress.py
wizard/command/install.py
wizard/deploy.py

index e94abc213e265c817bb8bd3225d53a94cb24e667..8a338c350a7bee6b0447af91b2e46c9aec05efc7 100644 (file)
@@ -6,7 +6,7 @@ from wizard import app, install, resolve, shell, util
 from wizard.app import php
 
 def make_filename_regex(var):
-    return 'LocalSettings.php', re.compile('^(\$' + app.expand_re(var) + r'''\s*=\s*)(.*)(;)''', re.M)
+    return 'LocalSettings.php', php.re_var(var)
 
 seed = util.dictmap(make_filename_regex, {
         'WIZARD_IP': 'IP', # obsolete, remove after we're done
@@ -32,7 +32,7 @@ class Application(app.Application):
         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]
+        regex = php.re_var("wgVersion")
         match = regex.search(contents)
         if not match: return None
         return distutils.version.LooseVersion(match.group(2)[1:-1])
index d2ac57413b05ac077bb4cecd7da7ace9840dbe60..ec5bdeee7b7686797d330a66570c31690d7e3813 100644 (file)
@@ -2,6 +2,9 @@ import re
 
 from wizard import app, util
 
+def re_var(var):
+    return re.compile('^(\$' + app.expand_re(var) + r'''\s*=\s*)(.*)(;)''', re.M)
+
 def make_filename_regex(var):
     return 'php.ini', re.compile('^(' + app.expand_re(var) + r'\s*=\s*)(.*)()$', re.M)
 
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,
index ca637bc6f597d1b76865a854d64d7911ce274dff..b0efb13b5ea7457d809359ba2dcf4120fbc9e1df 100644 (file)
@@ -12,7 +12,7 @@ def main(argv, baton):
     input = prompt.make(old_options.prompt, old_options.non_interactive)
 
     appstr = args[0]
-    dir = args[1]
+    dir = os.path.abspath(args[1])
 
     if not old_options.help and os.path.exists(dir) and os.listdir(dir):
         raise DirectoryExistsError
@@ -34,7 +34,7 @@ Autoinstalls the application %s in the directory DIR.""" % (appname, appname))
     if old_options.help:
         parser.print_help()
         sys.exit(1)
-    options, _ = parser.parse_all(args[2:] + command.make_base_args(old_options)) # accumulate
+    options, _ = parser.parse_all(args[2:] + command.make_base_args(old_options)
     if old_options.non_interactive:
         opthandler.handle(options)
     else:
@@ -48,7 +48,8 @@ Autoinstalls the application %s in the directory DIR.""" % (appname, appname))
             sh.call("git", "reset", "-q", "--hard", appstr)
         input.infobox("Installing...")
         application.install(distutils.version.LooseVersion(version), options)
-        git.commit_configure()
+        if not old_options.no_commit:
+            git.commit_configure()
     input.infobox("Congratulations, your new install is now accessible at:\n\nhttp://%s%s" % (options.web_host, options.web_path), width=80)
 
 def configure_parser(parser, baton):
@@ -56,6 +57,8 @@ def configure_parser(parser, baton):
             default=False, help="Force to use non-ncurses interactive interface")
     parser.add_option("--non-interactive", dest="non_interactive", action="store_true",
             default=False, help="Force program to be non-interactive and use SETUPARGS.  Use --help with APP to find argument names.")
+    parser.add_option("--no-commit", dest="no_commit", action="store_true",
+            default=False, help="Do not generate an 'installation commit' after configuring the application.")
     baton.push(parser, "srv_path")
 
 def parse_args(argv, baton):
index cc43d85b947e2700f5c8661aebfd23ce00b1497a..22750586511e61f2773ffd3b0c7bddd11197aba1 100644 (file)
@@ -255,7 +255,13 @@ class Deployment(object):
                 except shell.CallError:
                     pass
         if not self._app_version:
-            self._app_version = self.old_log[-1].version
+            try:
+                self._app_version = self.old_log[-1].version
+            except old_log.ScriptsVersionNoSuchFile:
+                pass
+        if not self._app_version:
+            appname = shell.Shell().eval("git", "config", "remote.origin.url").rpartition("/")[2].partition(".")[0]
+            self._app_version = app.ApplicationVersion.make(appname, "unknown")
         return self._app_version
     @staticmethod
     def parse(line):