5 from wizard import app, install, resolve, sql, util
6 from wizard.app import php
8 # XXX: We probably want to separate out the re.compile() line
9 def make_filename_regex_define(var):
10 return 'wp-config.php', re.compile('^(define\(\'' + app.expand_re(var) + r''''\s*,\s*)(.*)(\);)''', re.M)
12 seed = util.dictmap(make_filename_regex_define, {
13 'WIZARD_DBSERVER': 'DB_HOST',
14 'WIZARD_DBNAME': 'DB_NAME',
15 'WIZARD_DBUSER': 'DB_USER',
16 'WIZARD_DBPASSWORD': 'DB_PASSWORD',
18 # XXX: I have omitted an implementation for table prefix, on grounds that we
19 # do not permit it to be configured. If we do end up growing support for
20 # arbitrary table prefixes this should be added.
22 class Application(app.Application):
23 parametrized_files = ['wp-config.php'] + php.parametrized_files
24 extractors = app.make_extractors(seed)
25 extractors.update(php.extractors)
26 substitutions = app.make_substitutions(seed)
27 substitutions.update(php.substitutions)
28 install_schema = install.ArgSchema("mysql", "email", "title")
29 def download(self, version):
30 return "http://wordpress.org/wordpress-%s.tar.gz" % version
31 def checkConfig(self, deployment):
32 return os.path.isfile("wp-config.php")
33 def detectVersion(self, deployment):
34 # XXX: Very duplicate code with MediaWiki; refactor
35 contents = deployment.read("wp-includes/version.php")
36 match = php.re_var("wp_version").search(contents)
37 if not match: return None
38 return distutils.version.LooseVersion(match.group(2)[1:-1])
39 def prepareMerge(self, deployment):
40 resolve.fix_newlines("wp-config.php")
41 def install(self, version, options):
42 # XXX: Hmm... we should figure out something about this
44 os.unlink("wp-config.php")
49 'dbhost': options.mysql_host,
50 'uname': options.mysql_user,
51 'dbname': options.mysql_db,
52 'pwd': options.mysql_password,
58 'weblog_title': options.title,
59 'admin_email': options.email,
63 old_mode = os.stat(".").st_mode
64 os.chmod(".", 0777) # XXX: squick squick
65 result = install.fetch(options, "wp-admin/setup-config.php?step=2", post_setup_config)
66 logging.debug("setup-config.php output\n\n" + result)
67 result = install.fetch(options, "wp-admin/install.php?step=2", post_install)
68 logging.debug("install.php output\n\n" + result)
69 os.chmod(".", old_mode)
70 if "Finished" not in result:
71 raise install.Failure()
73 # not sure what to do about this
74 meta = sql.mysql_connect(options)
75 wp_options = meta.tables["wp_options"]
76 wp_options.update().where(wp_options.c.option_name == 'siteurl').values(option_value=options.web_path).execute()
77 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