|
47 |
__all__ = ['ConfigHandlers'] |
47 |
__all__ = ['ConfigHandlers'] |
48 |
|
48 |
|
49 |
VARIABLE_PATTERN = re.compile('@%@([^@]+)@%@') |
49 |
VARIABLE_PATTERN = re.compile('@%@([^@]+)@%@') |
50 |
VARIABLE_TOKEN = re.compile('@%@') |
50 |
VARIABLE_TOKEN = re.compile('@%@.*?@%@') |
51 |
EXECUTE_TOKEN = re.compile('@!@') |
51 |
EXECUTE_TOKEN = re.compile('@!@.*?@!@', re.MULTILINE | re.DOTALL) |
52 |
WARNING_PATTERN = re.compile('(UCRWARNING|BCWARNING|UCRWARNING_ASCII)=(.+)') |
52 |
WARNING_PATTERN = re.compile('(UCRWARNING|BCWARNING|UCRWARNING_ASCII)=(.+)') |
53 |
|
53 |
|
54 |
INFO_DIR = '/etc/univention/templates/info' |
54 |
INFO_DIR = '/etc/univention/templates/info' |
|
75 |
|
75 |
|
76 |
def run_filter(template, directory, srcfiles=set(), opts=dict()): |
76 |
def run_filter(template, directory, srcfiles=set(), opts=dict()): |
77 |
"""Process a template file: susbstitute variables.""" |
77 |
"""Process a template file: susbstitute variables.""" |
78 |
while True: |
78 |
out = [] |
79 |
i = VARIABLE_TOKEN.finditer(template) |
79 |
lastPos = 0 |
80 |
try: |
80 |
for i in VARIABLE_TOKEN.finditer(template): |
81 |
start = i.next() |
81 |
name = template[i.start()+3:i.start()-3] |
82 |
end = i.next() |
|
|
83 |
name = template[start.end():end.start()] |
84 |
|
82 |
|
85 |
if name in directory: |
83 |
if name in directory: |
86 |
value = directory[name] |
84 |
value = directory[name] |
|
|
85 |
else: |
86 |
match = WARNING_PATTERN.match(name) |
87 |
if match: |
88 |
mode, prefix = match.groups() |
89 |
if mode == "UCRWARNING_ASCII": |
90 |
value = warning_string(prefix, srcfiles=srcfiles, |
91 |
enforce_ascii=True) |
92 |
else: |
93 |
value = warning_string(prefix, srcfiles=srcfiles) |
87 |
else: |
94 |
else: |
88 |
match = WARNING_PATTERN.match(name) |
95 |
value = '' |
89 |
if match: |
|
|
90 |
mode, prefix = match.groups() |
91 |
if mode == "UCRWARNING_ASCII": |
92 |
value = warning_string(prefix, srcfiles=srcfiles, |
93 |
enforce_ascii=True) |
94 |
else: |
95 |
value = warning_string(prefix, srcfiles=srcfiles) |
96 |
else: |
97 |
value = '' |
98 |
|
96 |
|
99 |
if isinstance(value, (list, tuple)): |
97 |
if isinstance(value, (list, tuple)): |
100 |
value = value[0] |
98 |
value = value[0] |
101 |
template = template[:start.start()] + value + template[end.end():] |
|
|
102 |
except StopIteration: |
103 |
break |
104 |
|
99 |
|
105 |
while True: |
100 |
out.append(template[lastPos:i.start()]) |
106 |
i = EXECUTE_TOKEN.finditer(template) |
101 |
out.append(value) |
107 |
try: |
102 |
lastPos = i.end() |
108 |
start = i.next() |
|
|
109 |
end = i.next() |
110 |
|
103 |
|
111 |
proc = subprocess.Popen((__PYTHON_EXECUTABLE,), |
104 |
out.append(template[lastPos:]) |
112 |
stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
105 |
template = ''.join(out) |
113 |
close_fds=True) |
106 |
|
114 |
child_stdin, child_stdout = proc.stdin, proc.stdout |
107 |
out = [] |
115 |
child_stdin.write('''\ |
108 |
lastPos = 0 |
|
|
109 |
for i in EXECUTE_TOKEN.finditer(template): |
110 |
proc = subprocess.Popen((__PYTHON_EXECUTABLE,), |
111 |
stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
112 |
close_fds=True) |
113 |
child_stdin, child_stdout = proc.stdin, proc.stdout |
114 |
child_stdin.write('''\ |
116 |
# -*- coding: utf-8 -*- |
115 |
# -*- coding: utf-8 -*- |
117 |
import univention.config_registry |
116 |
import univention.config_registry |
118 |
configRegistry = univention.config_registry.ConfigRegistry() |
117 |
configRegistry = univention.config_registry.ConfigRegistry() |
|
120 |
# for compatibility |
119 |
# for compatibility |
121 |
baseConfig = configRegistry |
120 |
baseConfig = configRegistry |
122 |
''') |
121 |
''') |
123 |
child_stdin.write(template[start.end():end.start()]) |
122 |
child_stdin.write(template[i.start()+3:i.end()-3]) |
124 |
child_stdin.close() |
123 |
child_stdin.close() |
125 |
value = child_stdout.read() |
124 |
value = child_stdout.read() |
126 |
child_stdout.close() |
125 |
child_stdout.close() |
127 |
template = template[:start.start()] + value + template[end.end():] |
|
|
128 |
|
126 |
|
129 |
except StopIteration: |
127 |
out.append(template[lastPos:i.start()]) |
130 |
break |
128 |
out.append(value) |
|
|
129 |
lastPos = i.end() |
131 |
|
130 |
|
|
|
131 |
out.append(template[lastPos:]) |
132 |
template = ''.join(out) |
133 |
|
132 |
return template |
134 |
return template |
133 |
|
135 |
|
134 |
|
136 |
|