7 from wizard import app, install, resolve, sql, util
8 from wizard.app import php
10 def make_filename_regex_define(var):
11 return 'wp-config.php', php.re_define(var)
13 seed = util.dictmap(make_filename_regex_define, {
14 # these funny names are due to convention set by MediaWiki
15 'WIZARD_DBSERVER': 'DB_HOST',
16 'WIZARD_DBNAME': 'DB_NAME',
17 'WIZARD_DBUSER': 'DB_USER',
18 'WIZARD_DBPASSWORD': 'DB_PASSWORD',
19 'WIZARD_SECRETKEY': 'SECRET_KEY',
20 'WIZARD_AUTH_KEY': 'AUTH_KEY',
21 'WIZARD_SECURE_AUTH_KEY': 'SECURE_AUTH_KEY',
22 'WIZARD_LOGGED_IN_KEY': 'LOGGED_IN_KEY',
23 'WIZARD_NONCE_KEY': 'NONCE_KEY',
26 class Application(app.Application):
27 parametrized_files = ['wp-config.php'] + php.parametrized_files
28 extractors = app.make_extractors(seed)
29 extractors.update(php.extractors)
30 substitutions = app.make_substitutions(seed)
31 substitutions.update(php.substitutions)
32 install_schema = install.ArgSchema("mysql", "email", "title")
33 deprecated_keys = set(['WIZARD_SECRETKEY'])
34 def download(self, version):
35 return "http://wordpress.org/wordpress-%s.tar.gz" % version
36 def checkConfig(self, deployment):
37 return os.path.isfile("wp-config.php")
38 def checkWeb(self, deployment):
39 # XXX: this sucks pretty hard
40 return self.checkWebPage(deployment, "", "<html")
41 def detectVersion(self, deployment):
42 return self.detectVersionFromFile("wp-includes/version.php", php.re_var("wp_version"))
43 def prepareMerge(self, deployment):
44 # This file shouldn't really be edited by users, but be careful: it's
45 # stored as DOS and not as UNIX, so you'll get conflicts if you add this line:
46 # resolve.fix_newlines("wp-config.php")
48 def install(self, version, options):
49 util.soft_unlink("wp-config.php")
52 'dbhost': options.mysql_host,
53 'uname': options.mysql_user,
54 'dbname': options.mysql_db,
55 'pwd': options.mysql_password,
61 'weblog_title': options.title,
62 'admin_email': options.email,
66 old_mode = os.stat(".").st_mode
67 os.chmod(".", 0777) # XXX: squick squick
68 result = install.fetch(options, "wp-admin/setup-config.php?step=2", post_setup_config)
69 logging.debug("setup-config.php output\n\n" + result)
70 result = install.fetch(options, "wp-admin/install.php?step=2", post_install)
71 logging.debug("install.php output\n\n" + result)
72 os.chmod(".", old_mode)
73 if "Finished" not in result and "Success" not in result:
74 raise app.InstallFailure()
76 # not sure what to do about this
77 meta = sql.mysql_connect(options)
78 wp_options = meta.tables["wp_options"]
79 wp_options.update().where(wp_options.c.option_name == 'siteurl').values(option_value=options.web_path).execute()
80 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
81 # should also set the username and admin password
82 def upgrade(self, d, version, options):
83 result = d.fetch("wp-admin/upgrade.php?step=1")
84 if "Upgrade Complete" not in result and "No Upgrade Required" not in result:
85 raise app.UpgradeFailure(result)
86 def backup(self, deployment, backup_dir, options):
87 app.backup_database(backup_dir, deployment)
88 def restore(self, deployment, backup_dir, options):
89 app.restore_database(backup_dir, deployment)