Rev 547 | Rev 550 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 547 | Rev 549 | ||
|---|---|---|---|
| Line 109... | Line 109... | ||
| 109 | 109 | ||
| 110 | def set_title(self,text): |
110 | def set_title(self,text): |
| 111 | self.title = text |
111 | self.title = text |
| 112 | 112 | ||
| 113 | def calldlg(self,*args,**kw): |
113 | def calldlg(self,*args,**kw): |
| - | 114 | "Wrapper for calling 'dialog' program" |
|
| 114 | indesc, outdesc = os.pipe() |
115 | indesc, outdesc = os.pipe() |
| 115 | pid = os.fork() |
116 | pid = os.fork() |
| 116 | if not pid: |
117 | if not pid: |
| 117 | os.close(2) |
118 | os.close(2) |
| 118 | os.dup(outdesc) |
119 | os.dup(outdesc) |
| Line 174... | Line 175... | ||
| 174 | print data |
175 | print data |
| 175 | raise EOFError |
176 | raise EOFError |
| 176 | return data |
177 | return data |
| 177 | 178 | ||
| 178 | def read_defaults(fname,defaults): |
179 | def read_defaults(fname,defaults): |
| - | 180 | "Read saved values from last configuration run" |
|
| 179 | f = file(fname,'r') |
181 | f = file(fname,'r') |
| 180 | for line in f: |
182 | for line in f: |
| 181 | res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line) |
183 | res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line) |
| 182 | if res: |
184 | if res: |
| 183 | defaults[res.group(1)] = res.group(2) |
185 | defaults[res.group(1)] = res.group(2) |
| 184 | f.close() |
186 | f.close() |
| 185 | 187 | ||
| 186 | def check_condition(text, defaults): |
188 | def check_condition(text, defaults): |
| - | 189 | "Check that the condition specified on input line is True" |
|
| 187 | result = False |
190 | result = False |
| 188 | conds = text.split('|') |
191 | conds = text.split('|') |
| 189 | for cond in conds: |
192 | for cond in conds: |
| 190 | condname,condval = cond.split('=') |
193 | condname,condval = cond.split('=') |
| 191 | if not defaults.has_key(condname): |
194 | if not defaults.has_key(condname): |
| Line 197... | Line 200... | ||
| 197 | if condval == defaults[condname]: |
200 | if condval == defaults[condname]: |
| 198 | return True |
201 | return True |
| 199 | return False |
202 | return False |
| 200 | 203 | ||
| 201 | def parse_config(input, output, dlg, defaults={}): |
204 | def parse_config(input, output, dlg, defaults={}): |
| - | 205 | "Parse configuration file and create Makefile.config on the fly" |
|
| 202 | f = file(input, 'r') |
206 | f = file(input, 'r') |
| 203 | outf = file(output, 'w') |
207 | outf = file(output, 'w') |
| 204 | 208 | ||
| 205 | outf.write('#########################################\n') |
209 | outf.write('#########################################\n') |
| 206 | outf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n') |
210 | outf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n') |
| Line 209... | Line 213... | ||
| 209 | comment = '' |
213 | comment = '' |
| 210 | default = None |
214 | default = None |
| 211 | choices = [] |
215 | choices = [] |
| 212 | for line in f: |
216 | for line in f: |
| 213 | if line.startswith('!'): |
217 | if line.startswith('!'): |
| - | 218 | # Ask a question |
|
| 214 | res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line) |
219 | res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line) |
| 215 | if not res: |
220 | if not res: |
| 216 | raise RuntimeError("Weird line: %s" % line) |
221 | raise RuntimeError("Weird line: %s" % line) |
| 217 | varname = res.group(2) |
222 | varname = res.group(2) |
| 218 | vartype = res.group(3) |
223 | vartype = res.group(3) |
| Line 247... | Line 252... | ||
| 247 | default = None |
252 | default = None |
| 248 | choices = [] |
253 | choices = [] |
| 249 | continue |
254 | continue |
| 250 | 255 | ||
| 251 | if line.startswith('@'): |
256 | if line.startswith('@'): |
| - | 257 | # Add new line into the 'choice array' |
|
| 252 | res = re.match(r'@\s*(?:\[(.*?)\])?\s*"(.*?)"\s*(.*)$', line) |
258 | res = re.match(r'@\s*(?:\[(.*?)\])?\s*"(.*?)"\s*(.*)$', line) |
| 253 | if not res: |
259 | if not res: |
| 254 | raise RuntimeError("Bad line: %s" % line) |
260 | raise RuntimeError("Bad line: %s" % line) |
| 255 | if res.group(1): |
261 | if res.group(1): |
| 256 | if not check_condition(res.group(1),defaults): |
262 | if not check_condition(res.group(1),defaults): |
| 257 | continue |
263 | continue |
| 258 | choices.append((res.group(2), res.group(3))) |
264 | choices.append((res.group(2), res.group(3))) |
| 259 | continue |
265 | continue |
| - | 266 | ||
| 260 | 267 | # All other things print to output file |
|
| 261 | outf.write(line) |
268 | outf.write(line) |
| 262 | if re.match(r'^#[^#]', line): |
269 | if re.match(r'^#[^#]', line): |
| - | 270 | # Last comment before question will be displayed to the user |
|
| 263 | comment = line[1:].strip() |
271 | comment = line[1:].strip() |
| 264 | elif line.startswith('##'): |
272 | elif line.startswith('##'): |
| - | 273 | # Set title of the dialog window |
|
| 265 | dlg.set_title(line[2:].strip()) |
274 | dlg.set_title(line[2:].strip()) |
| 266 | 275 | ||
| 267 | outf.close() |
276 | outf.close() |
| 268 | f.close() |
277 | f.close() |
| 269 | 278 | ||