5 from wizard import app, install, resolve, sql, util
6 from wizard.app import php
8 def make_filename_regex_define(var):
9 return 'wp-config.php', php.re_define(var)
11 seed = util.dictmap(make_filename_regex_define, {
12 # these funny names are due to convention set by MediaWiki
13 'WIZARD_DBSERVER': 'DB_HOST',
14 'WIZARD_DBNAME': 'DB_NAME',
15 'WIZARD_DBUSER': 'DB_USER',
16 'WIZARD_DBPASSWORD': 'DB_PASSWORD',
17 'WIZARD_SECRETKEY': 'SECRET_KEY',
18 'WIZARD_AUTH_KEY': 'AUTH_KEY',
19 'WIZARD_SECURE_AUTH_KEY': 'SECURE_AUTH_KEY',
20 'WIZARD_LOGGED_IN_KEY': 'LOGGED_IN_KEY',
21 'WIZARD_NONCE_KEY': 'NONCE_KEY',
23 # XXX: I have omitted an implementation for table prefix, on grounds that we
24 # do not permit it to be configured. If we do end up growing support for
25 # arbitrary table prefixes this should be added.
27 class Application(app.Application):
28 parametrized_files = ['wp-config.php'] + php.parametrized_files
29 extractors = app.make_extractors(seed)
30 extractors.update(php.extractors)
31 substitutions = app.make_substitutions(seed)
32 substitutions.update(php.substitutions)
33 install_schema = install.ArgSchema("mysql", "email", "title")
34 deprecated_keys = set(['WIZARD_SECRETKEY'])
35 def download(self, version):
36 return "http://wordpress.org/wordpress-%s.tar.gz" % version
37 def checkConfig(self, deployment):
38 return os.path.isfile("wp-config.php")
39 def detectVersion(self, deployment):
40 # XXX: Very duplicate code with MediaWiki; refactor
41 contents = deployment.read("wp-includes/version.php")
42 match = php.re_var("wp_version").search(contents)
43 if not match: return None
44 return distutils.version.LooseVersion(match.group(2)[1:-1])
45 def prepareMerge(self, deployment):
46 resolve.fix_newlines("wp-config.php")
47 def install(self, version, options):
48 # XXX: Hmm... we should figure out something about this
50 os.unlink("wp-config.php")
55 'dbhost': options.mysql_host,
56 'uname': options.mysql_user,
57 'dbname': options.mysql_db,
58 'pwd': options.mysql_password,
64 'weblog_title': options.title,
65 'admin_email': options.email,
69 old_mode = os.stat(".").st_mode
70 os.chmod(".", 0777) # XXX: squick squick
71 result = install.fetch(options, "wp-admin/setup-config.php?step=2", post_setup_config)
72 logging.debug("setup-config.php output\n\n" + result)
73 result = install.fetch(options, "wp-admin/install.php?step=2", post_install)
74 logging.debug("install.php output\n\n" + result)
75 os.chmod(".", old_mode)
76 if "Finished" not in result and "Success" not in result:
77 raise install.Failure()
79 # not sure what to do about this
80 meta = sql.mysql_connect(options)
81 wp_options = meta.tables["wp_options"]
82 wp_options.update().where(wp_options.c.option_name == 'siteurl').values(option_value=options.web_path).execute()
83 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