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