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