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):
27 parametrized_files = ['wp-config.php'] + php.parametrized_files
28 extractors = app.make_extractors(seed)
29 extractors.update(php.extractors)
30 substitutions = app.make_substitutions(seed)
31 substitutions.update(php.substitutions)
32 install_schema = install.ArgSchema("mysql", "email", "title")
33 deprecated_keys = set(['WIZARD_SECRETKEY'])
34 def download(self, version):
35 return "http://wordpress.org/wordpress-%s.tar.gz" % version
36 def checkConfig(self, deployment):
37 return os.path.isfile("wp-config.php")
38 def checkWeb(self, deployment, out=None):
39 page = deployment.fetch("")
42 return page.find("<html") != -1
43 def detectVersion(self, deployment):
44 # XXX: Very duplicate code with MediaWiki; refactor
45 contents = deployment.read("wp-includes/version.php")
46 match = php.re_var("wp_version").search(contents)
47 if not match: return None
48 return distutils.version.LooseVersion(match.group(2)[1:-1])
49 def prepareMerge(self, deployment):
50 # This file shouldn't really be edited by users, but be careful: it's
51 # stored as DOS and not as UNIX, so you'll get conflicts if you add this line:
52 # resolve.fix_newlines("wp-config.php")
54 def install(self, version, options):
55 # XXX: Hmm... we should figure out something about this
57 os.unlink("wp-config.php")
62 'dbhost': options.mysql_host,
63 'uname': options.mysql_user,
64 'dbname': options.mysql_db,
65 'pwd': options.mysql_password,
71 'weblog_title': options.title,
72 'admin_email': options.email,
76 old_mode = os.stat(".").st_mode
77 os.chmod(".", 0777) # XXX: squick squick
78 result = install.fetch(options, "wp-admin/setup-config.php?step=2", post_setup_config)
79 logging.debug("setup-config.php output\n\n" + result)
80 result = install.fetch(options, "wp-admin/install.php?step=2", post_install)
81 logging.debug("install.php output\n\n" + result)
82 os.chmod(".", old_mode)
83 if "Finished" not in result and "Success" not in result:
84 raise app.InstallFailure()
86 # not sure what to do about this
87 meta = sql.mysql_connect(options)
88 wp_options = meta.tables["wp_options"]
89 wp_options.update().where(wp_options.c.option_name == 'siteurl').values(option_value=options.web_path).execute()
90 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
91 # should also set the username and admin password
92 def upgrade(self, d, version, options):
93 result = d.fetch("wp-admin/upgrade.php?step=1")
94 if "Upgrade Complete" not in result and "No Upgrade Required" not in result:
95 raise app.UpgradeFailure(result)
96 def backup(self, deployment, backup_dir, options):
97 app.backup_database(backup_dir, deployment)
98 def restore(self, deployment, backup_dir, options):
99 app.restore_database(backup_dir, deployment)