]> scripts.mit.edu Git - wizard.git/blob - wizard/app/wordpress.py
Fix bug in prepare-pristine, add secret key to wordpress, docs update.
[wizard.git] / wizard / app / wordpress.py
1 import os
2 import re
3 import logging
4
5 from wizard import app, install, resolve, sql, util
6 from wizard.app import php
7
8 def make_filename_regex_define(var):
9     return 'wp-config.php', php.re_define(var)
10
11 seed = util.dictmap(make_filename_regex_define, {
12     'WIZARD_DBSERVER': 'DB_HOST',
13     'WIZARD_DBNAME': 'DB_NAME',
14     'WIZARD_DBUSER': 'DB_USER',
15     'WIZARD_DBPASSWORD': 'DB_PASSWORD',
16     'WIZARD_SECRETKEY': 'SECRET_KEY',
17     })
18 # XXX: I have omitted an implementation for table prefix, on grounds that we
19 # do not permit it to be configured. If we do end up growing support for
20 # arbitrary table prefixes this should be added.
21
22 class Application(app.Application):
23     parametrized_files = ['wp-config.php'] + php.parametrized_files
24     extractors = app.make_extractors(seed)
25     extractors.update(php.extractors)
26     substitutions = app.make_substitutions(seed)
27     substitutions.update(php.substitutions)
28     install_schema = install.ArgSchema("mysql", "email", "title")
29     def download(self, version):
30         return "http://wordpress.org/wordpress-%s.tar.gz" % version
31     def checkConfig(self, deployment):
32         return os.path.isfile("wp-config.php")
33     def detectVersion(self, deployment):
34         # XXX: Very duplicate code with MediaWiki; refactor
35         contents = deployment.read("wp-includes/version.php")
36         match = php.re_var("wp_version").search(contents)
37         if not match: return None
38         return distutils.version.LooseVersion(match.group(2)[1:-1])
39     def prepareMerge(self, deployment):
40         resolve.fix_newlines("wp-config.php")
41     def install(self, version, options):
42         # XXX: Hmm... we should figure out something about this
43         try:
44             os.unlink("wp-config.php")
45         except OSError:
46             pass
47
48         post_setup_config = {
49                 'dbhost': options.mysql_host,
50                 'uname': options.mysql_user,
51                 'dbname': options.mysql_db,
52                 'pwd': options.mysql_password,
53                 'prefix': '',
54                 'submit': 'Submit',
55                 'step': '2',
56                 }
57         post_install = {
58                 'weblog_title': options.title,
59                 'admin_email': options.email,
60                 'submit': 'Continue',
61                 'step': '2',
62                 }
63         old_mode = os.stat(".").st_mode
64         os.chmod(".", 0777) # XXX: squick squick
65         result = install.fetch(options, "wp-admin/setup-config.php?step=2", post_setup_config)
66         logging.debug("setup-config.php output\n\n" + result)
67         result = install.fetch(options, "wp-admin/install.php?step=2", post_install)
68         logging.debug("install.php output\n\n" + result)
69         os.chmod(".", old_mode)
70         if "Finished" not in result and "Success" not in result:
71             raise install.Failure()
72
73         # not sure what to do about this
74         meta = sql.mysql_connect(options)
75         wp_options = meta.tables["wp_options"]
76         wp_options.update().where(wp_options.c.option_name == 'siteurl').values(option_value=options.web_path).execute()
77         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