]> scripts.mit.edu Git - wizard.git/blob - wizard/app/php.py
Convert ad hoc shell calls to singleton instance; fix upgrade bug.
[wizard.git] / wizard / app / php.py
1 """
2 Common data and functions for use in PHP applications.
3
4 .. testsetup:: *
5
6     from wizard.app.php import *
7 """
8
9 import re
10
11 from wizard import app, util
12
13 def re_var(var):
14     """
15     Generates a regexp for assignment to ``var`` in PHP; the quoted
16     value is the second subpattern.
17
18     >>> re_var('key').search("$key = 'val';").group(2)
19     "'val'"
20     """
21     return re.compile('^(\$' + app.expand_re(var) + r'''\s*=\s*)(.*)(;)''', re.M)
22
23 def re_define(var):
24     """
25     Generates a regexp for the definition of a constant in PHP; the
26     quoted value is the second subpattern.
27
28     >>> re_define('FOO').search("define('FOO', 'bar');").group(2)
29     "'bar'"
30     """
31     return re.compile('^(define\([\'"]' + app.expand_re(var) + r'''['"]\s*,\s*)(.*)(\);)''', re.M)
32
33 def _make_filename_regex(var):
34     return 'php.ini', re.compile('^(' + app.expand_re(var) + r'\s*=\s*)(.*)()$', re.M)
35
36 seed = util.dictmap(_make_filename_regex, {
37         'WIZARD_SESSIONNAME': 'session.name',
38         'WIZARD_TMPDIR': ('upload_tmp_dir', 'session.save_path'),
39         })
40
41 #: Common extractors for parameters in :file:`php.ini`.
42 extractors = app.make_extractors(seed)
43 #: Common substitutions for parameters in :file:`php.ini`.
44 substitutions = app.make_substitutions(seed)
45 #: A list containing :file:`php.ini`.
46 parametrized_files = ["php.ini"]
47 #: Nop for consistency.
48 deprecated_keys = set([])
49