5 from wizard import app, install, resolve, sql, util
6 from wizard.app import php
8 # XXX: We probably want to separate out the re.compile() line
9 def make_filename_regex_define(var):
10 return 'wp-config.php', re.compile('^(define\(\'' + app.expand_re(var) + r''''\s*,\s*)(.*)(\);)''', re.M)
12 seed = util.dictmap(make_filename_regex_define, {
13 'WIZARD_DBSERVER': 'DB_HOST',
14 'WIZARD_DBNAME': 'DB_NAME',
15 'WIZARD_DBUSER': 'DB_USER',
16 'WIZARD_DBPASSWORD': 'DB_PASSWORD',
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.
22 class Application(app.Application):
23 # XXX: php.ini should be grabbed over from the php module
24 parametrized_files = ['wp-config.php', 'php.ini']
25 extractors = app.make_extractors(seed)
26 extractors.update(php.extractors)
27 substitutions = app.make_substitutions(seed)
28 substitutions.update(php.substitutions)
29 install_schema = install.ArgSchema("mysql", "email", "title")
30 def download(self, version):
31 return "http://wordpress.org/wordpress-%s.tar.gz" % version
32 def checkConfig(self, deployment):
33 return os.path.isfile("wp-config.php")
34 def detectVersion(self, deployment):
35 # XXX: Very duplicate code with MediaWiki; refactor
36 contents = deployment.read("wp-includes/version.php")
37 match = php.re_var("wp_version").search(contents)
38 if not match: return None
39 return distutils.version.LooseVersion(match.group(2)[1:-1])
40 def prepareMerge(self, deployment):
41 resolve.fix_newlines("wp-config.php")
42 def install(self, version, options):
43 # XXX: Hmm... we should figure out something about this
45 os.unlink("wp-config.php")
50 'dbhost': options.mysql_host,
51 'uname': options.mysql_user,
52 'dbname': options.mysql_db,
53 'pwd': options.mysql_password,
59 'weblog_title': options.title,
60 'admin_email': options.email,
64 old_mode = os.stat(".").st_mode
65 os.chmod(".", 0777) # XXX: squick squick
66 result = install.fetch(options, "wp-admin/setup-config.php?step=2", post_setup_config)
67 logging.debug("setup-config.php output\n\n" + result)
68 result = install.fetch(options, "wp-admin/install.php?step=2", post_install)
69 logging.debug("install.php output\n\n" + result)
70 os.chmod(".", old_mode)
71 if "Finished" not in result:
72 raise install.Failure()
74 # not sure what to do about this
75 meta = sql.mysql_connect(options)
76 wp_options = meta.tables["wp_options"]
77 wp_options.update().where(wp_options.c.option_name == 'siteurl').values(option_value=options.web_path).execute()
78 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