]> scripts.mit.edu Git - wizard.git/blob - wizard/app/mediawiki.py
Enhancements from our first migration.
[wizard.git] / wizard / app / mediawiki.py
1 import re
2 import os
3
4 from wizard import app, deploy, install, shell, util
5 from wizard.app import php
6
7 def make_filename_regex(var):
8     return 'LocalSettings.php', re.compile('^(\$' + app.expand_re(var) + r'''\s*=\s*)(.*)(;)''', re.M)
9
10 make_extractor = app.filename_regex_extractor(make_filename_regex)
11 make_substitution = app.filename_regex_substitution(make_filename_regex)
12 seed = {
13         'WIZARD_IP': 'IP', # obsolete, remove after we're done
14         'WIZARD_SITENAME': 'wgSitename',
15         'WIZARD_SCRIPTPATH': 'wgScriptPath',
16         'WIZARD_EMERGENCYCONTACT': ('wgEmergencyContact', 'wgPasswordSender'),
17         'WIZARD_DBSERVER': 'wgDBserver',
18         'WIZARD_DBNAME': 'wgDBname',
19         'WIZARD_DBUSER': 'wgDBuser',
20         'WIZARD_DBPASSWORD': 'wgDBpassword',
21         'WIZARD_SECRETKEY': ('wgSecretKey', 'wgProxyKey'),
22         }
23
24 class Application(deploy.Application):
25     parametrized_files = ['LocalSettings.php', 'php.ini']
26     deprecated_keys = set(['WIZARD_IP']) | php.deprecated_keys
27     @property
28     def extractors(self):
29         if not self._extractors:
30             self._extractors = util.dictmap(make_extractor, seed)
31             self._extractors.update(php.extractors)
32         return self._extractors
33     @property
34     def substitutions(self):
35         if not self._substitutions:
36             self._substitutions = util.dictkmap(make_substitution, seed)
37             self._substitutions.update(php.substitutions)
38         return self._substitutions
39     @property
40     def install_handler(self):
41         handler = install.ArgHandler("mysql", "admin", "email")
42         handler.add(install.Arg("title", help="Title of your new MediaWiki install"))
43         return handler
44     def checkConfig(self, deployment):
45         return os.path.isfile(os.path.join(deployment.location, "LocalSettings.php"))
46     def install(self, options):
47         try:
48             os.unlink("LocalSettings.php")
49         except OSError:
50             pass
51
52         os.chmod("config", 0777) # XXX: vaguely sketchy
53
54         postdata = {
55             'Sitename': options.title,
56             'EmergencyContact': options.email,
57             'LanguageCode': 'en',
58             'DBserver': options.mysql_host,
59             'DBname': options.mysql_db,
60             'DBuser': options.mysql_user,
61             'DBpassword': options.mysql_password,
62             'DBpassword2': options.mysql_password,
63             'defaultEmail': options.email,
64             'SysopName': options.admin_name,
65             'SysopPass': options.admin_password,
66             'SysopPass2': options.admin_password,
67             }
68         result = install.fetch(options, 'config/index.php', post=postdata)
69         if options.verbose: print result
70         if result.find("Installation successful") == -1:
71             raise install.Failure()
72         os.rename('config/LocalSettings.php', 'LocalSettings.php')
73     def upgrade(self, options):
74         sh = shell.Shell()
75         sh.call("php", "maintenance/update.php")
76