From da73fc34e030897f8c56c4c5982bafb5ac66a7dc Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Wed, 4 Nov 2009 12:48:09 -0500 Subject: [PATCH 1/1] Implement post-installation machinery for Wordpress. Signed-off-by: Edward Z. Yang --- wizard/app/mediawiki.py | 4 ++-- wizard/app/php.py | 3 +++ wizard/app/wordpress.py | 40 +++++++++++++++++++++++++++++++++++++-- wizard/command/install.py | 9 ++++++--- wizard/deploy.py | 8 +++++++- 5 files changed, 56 insertions(+), 8 deletions(-) diff --git a/wizard/app/mediawiki.py b/wizard/app/mediawiki.py index e94abc2..8a338c3 100644 --- a/wizard/app/mediawiki.py +++ b/wizard/app/mediawiki.py @@ -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]) diff --git a/wizard/app/php.py b/wizard/app/php.py index d2ac574..ec5bdee 100644 --- a/wizard/app/php.py +++ b/wizard/app/php.py @@ -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) diff --git a/wizard/app/wordpress.py b/wizard/app/wordpress.py index 93187c5..123f355 100644 --- a/wizard/app/wordpress.py +++ b/wizard/app/wordpress.py @@ -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, diff --git a/wizard/command/install.py b/wizard/command/install.py index ca637bc..b0efb13 100644 --- a/wizard/command/install.py +++ b/wizard/command/install.py @@ -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): diff --git a/wizard/deploy.py b/wizard/deploy.py index cc43d85..2275058 100644 --- a/wizard/deploy.py +++ b/wizard/deploy.py @@ -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): -- 2.45.1