import re import os from wizard import app, deploy, install, util from wizard.app import php def make_filename_regex(var): return 'LocalSettings.php', re.compile('^(\$' + re.escape(var) + r'''\s*=\s*)(.*)(;)$''', re.M) make_extractor = app.filename_regex_extractor(make_filename_regex) class Application(deploy.Application): parametrized_files = ['LocalSettings.php', 'php.ini'] @property def extractors(self): if not self._extractors: self._extractors = util.dictmap(make_extractor, {'WIZARD_IP': 'IP' # obsolete, remove after we're done ,'WIZARD_SITENAME': 'wgSitename' ,'WIZARD_SCRIPTPATH': 'wgScriptPath' ,'WIZARD_EMERGENCYCONTACT': 'wgEmergencyContact' ,'WIZARD_DBSERVER': 'wgDBserver' ,'WIZARD_DBNAME': 'wgDBname' ,'WIZARD_DBUSER': 'wgDBuser' ,'WIZARD_DBPASSWORD': 'wgDBpassword' ,'WIZARD_PROXYKEY': 'wgProxyKey' }) self._extractors.update(php.extractors) return self._extractors @property def install_handler(self): handler = install.ArgHandler("mysql", "admin", "email") handler.add(install.Arg("title", help="Title of your new MediaWiki install")) return handler def install(self, options): try: os.unlink("LocalSettings.php") except OSError: pass postdata = { 'Sitename': options.title, 'EmergencyContact': options.email, 'LanguageCode': 'en', 'DBserver': options.mysql_host, 'DBname': options.mysql_db, 'DBuser': options.mysql_user, 'DBpassword': options.mysql_password, 'DBpassword2': options.mysql_password, 'defaultEmail': options.email, 'SysopName': options.admin_name, 'SysopPass': options.admin_password, 'SysopPass2': options.admin_password, } result = install.fetch(options, 'config/index.php', post=postdata) if options.verbose: print result if result.find("Installation successful") == -1: raise install.Failure() os.rename('config/LocalSettings.php', 'LocalSettings.php')