]> scripts.mit.edu Git - wizard.git/blob - wizard/app/mediawiki.py
Rough draft of installation functionality.
[wizard.git] / wizard / app / mediawiki.py
1 import re
2 import os
3
4 from wizard import app, deploy, install, util
5 from wizard.app import php
6
7 def make_filename_regex(var):
8     return 'LocalSettings.php', re.compile('^(\$' + re.escape(var) + r'''\s*=\s*)(.*)(;)$''', re.M)
9
10 make_extractor = app.filename_regex_extractor(make_filename_regex)
11
12 class Application(deploy.Application):
13     parametrized_files = ['LocalSettings.php', 'php.ini']
14     @property
15     def extractors(self):
16         if not self._extractors:
17             self._extractors = util.dictmap(make_extractor,
18                 {'WIZARD_IP': 'IP' # obsolete, remove after we're done
19                 ,'WIZARD_SITENAME': 'wgSitename'
20                 ,'WIZARD_SCRIPTPATH': 'wgScriptPath'
21                 ,'WIZARD_EMERGENCYCONTACT': 'wgEmergencyContact'
22                 ,'WIZARD_DBSERVER': 'wgDBserver'
23                 ,'WIZARD_DBNAME': 'wgDBname'
24                 ,'WIZARD_DBUSER': 'wgDBuser'
25                 ,'WIZARD_DBPASSWORD': 'wgDBpassword'
26                 ,'WIZARD_PROXYKEY': 'wgProxyKey'
27                 })
28             self._extractors.update(php.extractors)
29         return self._extractors
30     @property
31     def install_handler(self):
32         handler = install.ArgHandler("mysql", "admin", "email")
33         handler.add(install.Arg("title", help="Title of your new MediaWiki install"))
34         return handler
35     def install(self, options):
36         try:
37             os.unlink("LocalSettings.php")
38         except OSError:
39             pass
40
41         postdata = {
42             'Sitename': options.title,
43             'EmergencyContact': options.email,
44             'LanguageCode': 'en',
45             'DBserver': options.mysql_host,
46             'DBname': options.mysql_db,
47             'DBuser': options.mysql_user,
48             'DBpassword': options.mysql_password,
49             'DBpassword2': options.mysql_password,
50             'defaultEmail': options.email,
51             'SysopName': options.admin_name,
52             'SysopPass': options.admin_password,
53             'SysopPass2': options.admin_password,
54             }
55         result = install.fetch(options, 'config/index.php', post=postdata)
56         if options.verbose: print result
57         if result.find("Installation successful") == -1:
58             raise install.Failure()
59         os.rename('config/LocalSettings.php', 'LocalSettings.php')
60