]> scripts.mit.edu Git - wizard.git/blob - wizard/app/wordpress.py
Add more testing documentation on prompting of Ian Smith.
[wizard.git] / wizard / app / wordpress.py
1 import os
2 import re
3 import logging
4 import distutils
5 import urlparse
6
7 from wizard import app, install, resolve, sql, util
8 from wizard.app import php
9
10 def make_filename_regex_define(var):
11     """See :ref:`versioning config <seed>` for more information."""
12     return 'wp-config.php', php.re_define(var)
13
14 seed = util.dictmap(make_filename_regex_define, {
15     # these funny names are due to convention set by MediaWiki
16     'WIZARD_DBSERVER': 'DB_HOST',
17     'WIZARD_DBNAME': 'DB_NAME',
18     'WIZARD_DBUSER': 'DB_USER',
19     'WIZARD_DBPASSWORD': 'DB_PASSWORD',
20     'WIZARD_SECRETKEY': 'SECRET_KEY',
21     'WIZARD_AUTH_KEY': 'AUTH_KEY',
22     'WIZARD_SECURE_AUTH_KEY': 'SECURE_AUTH_KEY',
23     'WIZARD_LOGGED_IN_KEY': 'LOGGED_IN_KEY',
24     'WIZARD_NONCE_KEY': 'NONCE_KEY',
25     })
26
27 class Application(app.Application):
28     database = "mysql"
29     parametrized_files = ['wp-config.php'] + php.parametrized_files
30     extractors = app.make_extractors(seed)
31     extractors.update(php.extractors)
32     substitutions = app.make_substitutions(seed)
33     substitutions.update(php.substitutions)
34     install_schema = install.ArgSchema("db", "email", "title")
35     deprecated_keys = set(['WIZARD_SECRETKEY'])
36     random_keys = set(['WIZARD_SECRETKEY', 'WIZARD_AUTH_KEY', 'WIZARD_SECURE_AUTH_KEY', 'WIZARD_LOGGED_IN_KEY', 'WIZARD_NONCE_KEY'])
37     def download(self, version):
38         return "http://wordpress.org/wordpress-%s.tar.gz" % version
39     def checkConfig(self, deployment):
40         return os.path.isfile("wp-config.php")
41     def checkWeb(self, deployment):
42         # XXX: this sucks pretty hard
43         return self.checkWebPage(deployment, "", "<html")
44     def detectVersion(self, deployment):
45         return self.detectVersionFromFile("wp-includes/version.php", php.re_var("wp_version"))
46     def prepareMerge(self, deployment):
47         # This file shouldn't really be edited by users, but be careful: it's
48         # stored as DOS and not as UNIX, so you'll get conflicts if you add this line:
49         # resolve.fix_newlines("wp-config.php")
50         pass
51     def install(self, version, options):
52         util.soft_unlink("wp-config.php")
53
54         post_setup_config = {
55                 'dbhost': options.dsn.host,
56                 'uname': options.dsn.username,
57                 'dbname': options.dsn.database,
58                 'pwd': options.dsn.password,
59                 'prefix': '',
60                 'submit': 'Submit',
61                 'step': '2',
62                 }
63         post_install = {
64                 'weblog_title': options.title,
65                 'admin_email': options.email,
66                 'submit': 'Continue',
67                 'step': '2',
68                 }
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 app.InstallFailure()
78
79         # not sure what to do about this
80         meta = sql.connect(options.dsn)
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
84         # should also set the username and admin password
85         php.ini_replace_vars()
86     def upgrade(self, d, version, options):
87         result = d.fetch("wp-admin/upgrade.php?step=1")
88         if "Upgrade Complete" not in result and "No Upgrade Required" not in result:
89             raise app.UpgradeFailure(result)
90     def backup(self, deployment, backup_dir, options):
91         app.backup_database(backup_dir, deployment)
92     def restore(self, deployment, backup_dir, options):
93         app.restore_database(backup_dir, deployment)
94     def remove(self, deployment, options):
95         app.remove_database(deployment)
96
97 Application.resolutions = {
98 'wp-config.php': [
99     ("""
100 <<<<<<<
101
102 /** WordPress absolute path to the Wordpress directory. */
103 |||||||
104 /** WordPress absolute path to the Wordpress directory. */
105 =======
106 /** Absolute path to the WordPress directory. */
107 >>>>>>>
108 """, [0])
109 ],
110 }