From: Edward Z. Yang Date: Thu, 30 Jul 2009 20:21:17 +0000 (-0400) Subject: Add mediawiki variable extraction support for deployments. X-Git-Url: https://scripts.mit.edu/gitweb/wizard.git/commitdiff_plain/bf58b59267060bdb462476d824b086131b444cd4?hp=6eae78b3d8ed73a0266ef09a30e4b09e791dd9fb Add mediawiki variable extraction support for deployments. Signed-off-by: Edward Z. Yang --- diff --git a/wizard/app/__init__.py b/wizard/app/__init__.py index e69de29..a4a6ca2 100644 --- a/wizard/app/__init__.py +++ b/wizard/app/__init__.py @@ -0,0 +1,23 @@ +import os.path + +def filename_regex_extractor(f): + """This is a decorator to apply to functions that take a name and return + (filename, RegexObject) tuples. It converts it into a function + that takes a name and returns another function (the actual extractor) + which takes a deployment and returns the value of the extracted variable. + + Its Haskell-style type signature would be: + (String -> (Filename, Regex)) -> (String -> (Deployment -> String)) + + It's a little bit like a transformer.""" + def g(var): + file, regex = f(var) + def h(deployment): + contents = deployment.read(file) # cached + match = regex.search(contents) + if not match: return None + # assumes that the first match is the one we want. Hopefully + # our regexes can be clever enough to make this work + return match.group(1) + return h + return g diff --git a/wizard/app/mediawiki.py b/wizard/app/mediawiki.py index 9931b1b..7ae7583 100644 --- a/wizard/app/mediawiki.py +++ b/wizard/app/mediawiki.py @@ -1,20 +1,26 @@ import re -from wizard import deploy +from wizard import app, deploy, util +from wizard.app import php -def make_regex(var): - return re.compile('^\$' + var + r'''\s*=\s*((["\']).*\2;)$''', re.M) - -wizard_to_var = \ - {'WIZARD_IP': 'IP' # obsolete - ,'WIZARD_SITENAME': 'wgSitename' - ,'WIZARD_SCRIPTPATH': 'wgScriptPath' - ,'WIZARD_EMERGENCYCONTACT': 'wgEmergencyContact' - ,'WIZARD_DBSERVER': 'wgDBserver' - ,'WIZARD_DBNAME': 'wgDBname' - ,'WIZARD_DBUSER': 'wgDBuser' - ,'WIZARD_DBPASSWORD': 'wgDBpassword' - ,'WIZARD_PROXYKEY': 'wgProxyKey'} +@app.filename_regex_extractor +def make_extractor(var): + return 'LocalSettings.php', re.compile('^\$' + re.escape(var) + r'''\s*=\s*((["\']).*\2);$''', re.M) class Application(deploy.Application): - pass + @property + def extractors(self): + if not self._extractors: + self._extractors = util.dictmap(make_extractor, + {'WIZARD_IP': 'IP' # obsolete + ,'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 diff --git a/wizard/app/php.py b/wizard/app/php.py index 0d9fcfd..9093edf 100644 --- a/wizard/app/php.py +++ b/wizard/app/php.py @@ -1,3 +1,13 @@ -php_ini_regexes = \ - {'WIZARD_SESSIONNAME': None, - 'WIZARD_TMPDIR': None} +import re + +from wizard import app, util + +@app.filename_regex_extractor +def make_extractor(var): + return 'php.ini', re.compile('^' + re.escape(var) + r'\s*=\s*(.*)$', re.M) + +extractors = util.dictmap(make_extractor, + {'WIZARD_SESSIONNAME': 'session.name' + ,'WIZARD_TMPDIR': 'upload_tmp_dir' + }) + diff --git a/wizard/app/tests/mediawiki/LocalSettings.php b/wizard/app/tests/mediawiki/LocalSettings.php new file mode 100644 index 0000000..433adcb --- /dev/null +++ b/wizard/app/tests/mediawiki/LocalSettings.php @@ -0,0 +1,128 @@ +