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):
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("db", "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 checkWeb(self, deployment):
40 # XXX: this sucks pretty hard
41 return self.checkWebPage(deployment, "", "<html")
42 def detectVersion(self, deployment):
43 return self.detectVersionFromFile("wp-includes/version.php", php.re_var("wp_version"))
44 def prepareMerge(self, deployment):
45 # This file shouldn't really be edited by users, but be careful: it's
46 # stored as DOS and not as UNIX, so you'll get conflicts if you add this line:
47 # resolve.fix_newlines("wp-config.php")
49 def install(self, version, options):
50 util.soft_unlink("wp-config.php")
53 'dbhost': options.dsn.host,
54 'uname': options.dsn.username,
55 'dbname': options.dsn.database,
56 'pwd': options.dsn.password,
62 'weblog_title': options.title,
63 'admin_email': options.email,
67 old_mode = os.stat(".").st_mode
68 os.chmod(".", 0777) # XXX: squick squick
69 result = install.fetch(options, "wp-admin/setup-config.php?step=2", post_setup_config)
70 logging.debug("setup-config.php output\n\n" + result)
71 result = install.fetch(options, "wp-admin/install.php?step=2", post_install)
72 logging.debug("install.php output\n\n" + result)
73 os.chmod(".", old_mode)
74 if "Finished" not in result and "Success" not in result:
75 raise app.InstallFailure()
77 # not sure what to do about this
78 meta = sql.connect(options.dsn)
79 wp_options = meta.tables["wp_options"]
80 wp_options.update().where(wp_options.c.option_name == 'siteurl').values(option_value=options.web_path).execute()
81 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
82 # should also set the username and admin password
83 def upgrade(self, d, version, options):
84 result = d.fetch("wp-admin/upgrade.php?step=1")
85 if "Upgrade Complete" not in result and "No Upgrade Required" not in result:
86 raise app.UpgradeFailure(result)
87 def backup(self, deployment, backup_dir, options):
88 app.backup_database(backup_dir, deployment)
89 def restore(self, deployment, backup_dir, options):
90 app.restore_database(backup_dir, deployment)
91 def remove(self, deployment, options):
92 app.remove_database(deployment)