source: dcdatagen.py@ 439:21a64d42fa00

Last change on this file since 439:21a64d42fa00 was 439:21a64d42fa00, checked in by István Váradi <ivaradi@…>, 10 years ago

Implemented the code and PO file generator for the delay codes with a small number of delay codes (re #154)

  • Property exe set to *
File size: 17.0 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# Script that generates the delay code data files from a common data base
5#
6# It generates the following files:
7# - src/mlx/gui/dcdata.py: a Python module that contains the data structures
8# describing the delay code information for each aircraft type.
9# - locale/en/mlx_delay.po, local/hu/mlx_delay.po: PO files containing the
10# delay code texts. Those texts are referred to from dcdata.py
11
12#----------------------------------------------------------------------------
13
14import os
15
16#----------------------------------------------------------------------------
17
18# The list of language codes. The strings should be arrays of at least this
19# length
20languageCodes = ["en", "hu"]
21
22#----------------------------------------------------------------------------
23
24# Row type: a caption
25CAPTION = 1
26
27# Row type: an actual delay code
28DELAYCODE = 2
29
30#----------------------------------------------------------------------------
31
32# Prefixes for the generated tables
33tablePrefixes = [ "modern", "ot" ]
34
35# Type groups
36typeGroups = [ ["B736", "B737", "B738", "B738C", "B733", "B734", "B735",
37 "DH8D", "B762", "B763", "CRJ2", "F70" ],
38 ["DC3", "T134", "T154", "YK40"] ]
39
40#----------------------------------------------------------------------------
41
42# The associated row or column is for the modern fleet
43FOR_MODERN = 1
44
45# The associated row or column is for the old-timer fleet
46FOR_OT = 2
47
48#----------------------------------------------------------------------------
49
50# The complete delay code table
51table = (("info_delay_",
52 "lambda row: row[0].strip()"),
53 [ ["MA", "MA"], ["IATA", "IATA"], ["Code", "Kód"],
54 ["Name", "Név"],["Description", "Leírás" ] ],
55 [ FOR_OT, FOR_MODERN | FOR_OT, FOR_MODERN,
56 FOR_OT | FOR_MODERN, FOR_OT | FOR_MODERN ],
57 [ (CAPTION, FOR_MODERN | FOR_OT,
58 ["Others", "Egyebek"] ),
59 (DELAYCODE, FOR_OT,
60 ["012 ", "01 ", None,
61 ["LATE PARTS OR MATERIALS", "KÉSEI ALKATRÉSZ VAGY ANYAG"],
62 ["Parts and/or materials shipped late from the warehouse",
63 "Kései alkatrész és/vagy anyagkiszállítás a raktárból"]]),
64 (DELAYCODE, FOR_MODERN,
65 [None, "06 ", "OA ",
66 ["NO GATES/STAND AVAILABLE", "NINCS SZABAD KAPU/ÁLLÓHELY"],
67 ["Due to own airline activity",
68 "Saját tevékenység miatt"]]),
69 (DELAYCODE, FOR_MODERN,
70 [None, "09", "SG",
71 ["SCHEDULED GROUND TIME", "ÜTEMEZETT FORDULÓ IDŐ"],
72 ["Planned turnaround time less than declared minimum",
73 "A tervezett forduló idő rövidebb a minimálisnál"]]),
74 (CAPTION, FOR_MODERN | FOR_OT,
75 ["Passenger and baggage",
76 "Utas és poggyászkezelés"] ),
77 (DELAYCODE, FOR_MODERN | FOR_OT,
78 ["111", "11", "PD",
79 ["LATE CHECK-IN", "KÉSEI JEGYKEZELÉS"],
80 ["Check-in reopened for late passengers",
81 "Check-in járatzárás után"]]),
82 (DELAYCODE, FOR_MODERN | FOR_OT,
83 ["121", "12", "PL",
84 ["LATE CHECK-IN", "KÉSEI JEGYKEZELÉS"],
85 ["Check-in not completed by flight closure time",
86 "Torlódás az indulási csarnokban"]]),
87 (DELAYCODE, FOR_MODERN | FOR_OT,
88 ["132", "13", "PE",
89 ["CHECK-IN ERROR", "JEGYKEZELÉSI HIBA"],
90 ["Error with passenger or baggage details",
91 "Téves utas és poggyászfelvétel"]]),
92 (DELAYCODE, FOR_MODERN | FOR_OT,
93 ["142", "14", "PO",
94 ["OVERSALES", "TÚLKÖNYVELÉS"],
95 ["Booking errors – not resolved at check-in",
96 "Téves könyvelés, a jegykezelés során nem megoldott"]]),
97 (DELAYCODE, FOR_MODERN,
98 [None, "15", "PH",
99 ["BOARDING", "BESZÁLLÍTÁS"],
100 ["Discrepancies and paging, missing checked in passengers",
101 "Beszállítási rendellenesség, hiányzó utasok"]]),
102 (DELAYCODE, FOR_OT,
103 ["151", "15", None,
104 ["BOARDING", "BESZÁLLÍTÁS"],
105 ["Boarding discrepancies due to the passenger's fault",
106 "Beszállítási rendellenesség utas hibájából"]]),
107 (DELAYCODE, FOR_OT,
108 ["152", "", None,
109 ["BOARDING", "BESZÁLLÍTÁS"],
110 ["Boarding discrepancies due to the tranzit's fault",
111 "Beszállítási rendellenesség tranzit hibájából"]]),
112 (DELAYCODE, FOR_MODERN | FOR_OT,
113 ["161", "16", "PS",
114 ["COMMERCIAL PUBLICITY/\nPASSENGER CONVENIENCE",
115 "NYILVÁNOS FOGADÁS/\nUTASKÉNYELMI SZEMPONTOK"],
116 ["Local decision to delay for VIP or press; \ndelay due to offload of passengers following family bereavement",
117 "Késleltetés helyi döntés alapján reptérzár,\nbetegség/halál, VIP, sajtó, TV miatt"]]),
118 (DELAYCODE, FOR_MODERN,
119 [None, "17", "PC",
120 ["CATERING ORDER", "CATERING MEGRENDELÉS"],
121 ["Late or incorrect order given to supplier",
122 "Kései vagy téves megrendelés leadása a szállítónak"]]),
123 (DELAYCODE, FOR_OT,
124 ["171", "17", None,
125 ["CATERING ORDER", "CATERING MEGRENDELÉS"],
126 ["Late catering order in case of an additional group of people",
127 "Kései catering megrendelés, extra csoport jelentkezése esetén"]]),
128 (DELAYCODE, FOR_OT,
129 ["172", "", None,
130 ["CATERING ORDER", "CATERING MEGRENDELÉS"],
131 ["Late catering order due to negligence",
132 "Kései catering megrendelés gondatlanságból"]]),
133 (DELAYCODE, FOR_MODERN | FOR_OT,
134 ["182", "18", "PD",
135 ["BAGGAGE PROCESSING", "POGGYÁSZKEZELÉS"],
136 ["Késő vagy tévesen szortírozott poggyász",
137 "Late or incorrectly sorted baggage"]]),
138 # (DELAYCODE, FOR_MODERN | FOR_OT,
139 # ["", "", "",
140 # ["", ""],
141 # ["",
142 # ""]]),
143 # (DELAYCODE, FOR_MODERN | FOR_OT,
144 # ["", "", "",
145 # ["", ""],
146 # ["",
147 # ""]]),
148 # (DELAYCODE, FOR_MODERN | FOR_OT,
149 # ["", "", "",
150 # ["", ""],
151 # ["",
152 # ""]]),
153 # (DELAYCODE, FOR_MODERN | FOR_OT,
154 # ["", "", "",
155 # ["", ""],
156 # ["",
157 # ""]]),
158 # (DELAYCODE, FOR_MODERN | FOR_OT,
159 # ["", "", "",
160 # ["", ""],
161 # ["",
162 # ""]]),
163 # (DELAYCODE, FOR_MODERN | FOR_OT,
164 # ["", "", "",
165 # ["", ""],
166 # ["",
167 # ""]]),
168 # (DELAYCODE, FOR_MODERN | FOR_OT,
169 # ["", "", "",
170 # ["", ""],
171 # ["",
172 # ""]]),
173 # (DELAYCODE, FOR_MODERN | FOR_OT,
174 # ["", "", "",
175 # ["", ""],
176 # ["",
177 # ""]]),
178 # (DELAYCODE, FOR_MODERN | FOR_OT,
179 # ["", "", "",
180 # ["", ""],
181 # ["",
182 # ""]]),
183 # (DELAYCODE, FOR_MODERN | FOR_OT,
184 # ["", "", "",
185 # ["", ""],
186 # ["",
187 # ""]]),
188 # (DELAYCODE, FOR_MODERN | FOR_OT,
189 # ["", "", "",
190 # ["", ""],
191 # ["",
192 # ""]]),
193 # (DELAYCODE, FOR_MODERN | FOR_OT,
194 # ["", "", "",
195 # ["", ""],
196 # ["",
197 # ""]]),
198 # (DELAYCODE, FOR_MODERN | FOR_OT,
199 # ["", "", "",
200 # ["", ""],
201 # ["",
202 # ""]]),
203 # (DELAYCODE, FOR_MODERN | FOR_OT,
204 # ["", "", "",
205 # ["", ""],
206 # ["",
207 # ""]]),
208 # (DELAYCODE, FOR_MODERN | FOR_OT,
209 # ["", "", "",
210 # ["", ""],
211 # ["",
212 # ""]]),
213 # (DELAYCODE, FOR_MODERN | FOR_OT,
214 # ["", "", "",
215 # ["", ""],
216 # ["",
217 # ""]]),
218 # (DELAYCODE, FOR_MODERN | FOR_OT,
219 # ["", "", "",
220 # ["", ""],
221 # ["",
222 # ""]]),
223 # (DELAYCODE, FOR_MODERN | FOR_OT,
224 # ["", "", "",
225 # ["", ""],
226 # ["",
227 # ""]]),
228 # (DELAYCODE, FOR_MODERN | FOR_OT,
229 # ["", "", "",
230 # ["", ""],
231 # ["",
232 # ""]]),
233 # (DELAYCODE, FOR_MODERN | FOR_OT,
234 # ["", "", "",
235 # ["", ""],
236 # ["",
237 # ""]]),
238 # (DELAYCODE, FOR_MODERN | FOR_OT,
239 # ["", "", "",
240 # ["", ""],
241 # ["",
242 # ""]]),
243 # (DELAYCODE, FOR_MODERN | FOR_OT,
244 # ["", "", "",
245 # ["", ""],
246 # ["",
247 # ""]]),
248 # (DELAYCODE, FOR_MODERN | FOR_OT,
249 # ["", "", "",
250 # ["", ""],
251 # ["",
252 # ""]]),
253 # (DELAYCODE, FOR_MODERN | FOR_OT,
254 # ["", "", "",
255 # ["", ""],
256 # ["",
257 # ""]]),
258 # (DELAYCODE, FOR_MODERN | FOR_OT,
259 # ["", "", "",
260 # ["", ""],
261 # ["",
262 # ""]]),
263 # (DELAYCODE, FOR_MODERN | FOR_OT,
264 # ["", "", "",
265 # ["", ""],
266 # ["",
267 # ""]]),
268 # (DELAYCODE, FOR_MODERN | FOR_OT,
269 # ["", "", "",
270 # ["", ""],
271 # ["",
272 # ""]]),
273 # (DELAYCODE, FOR_MODERN | FOR_OT,
274 # ["", "", "",
275 # ["", ""],
276 # ["",
277 # ""]]),
278 # (DELAYCODE, FOR_MODERN | FOR_OT,
279 # ["", "", "",
280 # ["", ""],
281 # ["",
282 # ""]]),
283 # (DELAYCODE, FOR_MODERN | FOR_OT,
284 # ["", "", "",
285 # ["", ""],
286 # ["",
287 # ""]]),
288 # (DELAYCODE, FOR_MODERN | FOR_OT,
289 # ["", "", "",
290 # ["", ""],
291 # ["",
292 # ""]]),
293 # (DELAYCODE, FOR_MODERN | FOR_OT,
294 # ["", "", "",
295 # ["", ""],
296 # ["",
297 # ""]]),
298 # (DELAYCODE, FOR_MODERN | FOR_OT,
299 # ["", "", "",
300 # ["", ""],
301 # ["",
302 # ""]]),
303 # (DELAYCODE, FOR_MODERN | FOR_OT,
304 # ["", "", "",
305 # ["", ""],
306 # ["",
307 # ""]]),
308 # (DELAYCODE, FOR_MODERN | FOR_OT,
309 # ["", "", "",
310 # ["", ""],
311 # ["",
312 # ""]]),
313 # (DELAYCODE, FOR_MODERN | FOR_OT,
314 # ["", "", "",
315 # ["", ""],
316 # ["",
317 # ""]]),
318 # (DELAYCODE, FOR_MODERN | FOR_OT,
319 # ["", "", "",
320 # ["", ""],
321 # ["",
322 # ""]]),
323 # (DELAYCODE, FOR_MODERN | FOR_OT,
324 # ["", "", "",
325 # ["", ""],
326 # ["",
327 # ""]]),
328 # (DELAYCODE, FOR_MODERN | FOR_OT,
329 # ["", "", "",
330 # ["", ""],
331 # ["",
332 # ""]]),
333 # (DELAYCODE, FOR_MODERN | FOR_OT,
334 # ["", "", "",
335 # ["", ""],
336 # ["",
337 # ""]]),
338 # (DELAYCODE, FOR_MODERN | FOR_OT,
339 # ["", "", "",
340 # ["", ""],
341 # ["",
342 # ""]]),
343 # (DELAYCODE, FOR_MODERN | FOR_OT,
344 # ["", "", "",
345 # ["", ""],
346 # ["",
347 # ""]]),
348 ])
349
350#-------------------------------------------------------------------------------
351
352def generateMsgStr(file, text):
353 """Generate an 'msgstr' entry for the given text."""
354 lines = text.splitlines()
355 numLines = len(lines)
356 if numLines==0:
357 print >> file, "msgstr \"\""
358 elif numLines==1:
359 print >> file, "msgstr \"%s\"" % (lines[0])
360 else:
361 print >> file, "msgstr \"\""
362 for i in range(0, numLines):
363 print >> file, "\"%s%s\"" % (lines[i], "" if i==(numLines-1) else "\\n")
364 print >> file
365
366#-------------------------------------------------------------------------------
367
368def generateFiles(baseDir):
369 """Generate the various files."""
370 dcdata = None
371 poFiles = []
372
373 try:
374 dcdataPath = os.path.join(baseDir, "src", "mlx", "gui", "dcdata.py")
375 dcdata = open(dcdataPath, "wt")
376
377 numLanguages = len(languageCodes)
378 for language in languageCodes:
379 poPath = os.path.join(baseDir, "locale", language, "mlx_delay.po")
380 poFile = open(poPath, "wt")
381 poFiles.append(poFile)
382 print >> poFile, "msgid \"\""
383 print >> poFile, "msgstr \"\""
384 print >> poFile, "\"Content-Type: text/plain; charset=utf-8\\n\""
385 print >> poFile, "\"Content-Transfer-Encoding: 8bit\\n\""
386
387 (baseData, headings, headingFlags, rows) = table
388 (poPrefix, extractor) = baseData
389
390 for i in range(0, len(headings)):
391 heading = headings[i]
392 for j in range(0, numLanguages):
393 poFile = poFiles[j]
394 print >> poFile, "msgid \"%sheading%d\"" % (poPrefix, i)
395 generateMsgStr(poFile, heading[j])
396
397
398 rowIndex = 0
399 for (type, _tableMask, columns) in rows:
400 if type==CAPTION:
401 for i in range(0, numLanguages):
402 poFile = poFiles[i]
403 print >> poFile, "msgid \"%srow%d\"" % (poPrefix, rowIndex)
404 generateMsgStr(poFile, columns[i])
405 elif type==DELAYCODE:
406 columnIndex = 0
407 for column in columns:
408 if isinstance(column, list):
409 for i in range(0, numLanguages):
410 poFile = poFiles[i]
411 print >> poFile, "msgid \"%srow%d_col%d\"" % \
412 (poPrefix, rowIndex, columnIndex)
413 generateMsgStr(poFile, column[i])
414 columnIndex += 1
415 rowIndex += 1
416
417 print >> dcdata, "import mlx.const as const"
418 print >> dcdata, "from mlx.i18n import xstr"
419 print >> dcdata
420 print >> dcdata, "CAPTION = 1"
421 print >> dcdata, "DELAYCODE = 2"
422
423 tableMask = 1
424 for i in range(0, len(tablePrefixes)):
425 print >> dcdata, "_%s_data = (" % (tablePrefixes[i],)
426 print >> dcdata, " %s," % (extractor,)
427 print >> dcdata, " [",
428
429 columnIndexes = []
430 for j in range(0, len(headings)):
431 if ( (headingFlags[j]&tableMask)==tableMask ):
432 if columnIndexes:
433 print >> dcdata, ",",
434 print >> dcdata, "xstr(\"%sheading%d\")" % (poPrefix, j),
435 columnIndexes.append(j)
436
437 print >> dcdata, "],"
438
439 print >> dcdata, " ["
440
441 rowIndex = 0
442 for (type, mask, columns) in rows:
443 if (mask&tableMask)!=tableMask:
444 rowIndex += 1
445 continue
446
447 if type==CAPTION:
448 print >> dcdata, " (CAPTION, xstr(\"%srow%d\"))," % \
449 (poPrefix, rowIndex)
450 elif type==DELAYCODE:
451 print >> dcdata, " (DELAYCODE, ["
452 for j in columnIndexes:
453 column = columns[j]
454 if j!=columnIndexes[0]:
455 print >> dcdata, ","
456 if isinstance(column, list):
457 print >> dcdata, " xstr(\"%srow%d_col%d\")" % \
458 (poPrefix, rowIndex, j),
459 else:
460 print >> dcdata, " \"%s\"" % \
461 (column,),
462 print >> dcdata, "] ),"
463 rowIndex += 1
464
465 print >> dcdata, " ]"
466
467 print >> dcdata, ")"
468 print >> dcdata
469
470 tableMask <<= 1
471
472 print >> dcdata, "def getTable(aircraftType):"
473 first = True
474 for i in range(0, len(tablePrefixes)):
475 tablePrefix = tablePrefixes[i]
476 for typeSuffix in typeGroups[i]:
477 print >> dcdata, " %s aircraftType==const.AIRCRAFT_%s:" % \
478 ("if" if first else "elif", typeSuffix)
479 print >> dcdata, " return _%s_data" % (tablePrefix,)
480 first = False
481
482 print >> dcdata, " else:"
483 print >> dcdata, " return None"
484 finally:
485 for poFile in poFiles:
486 poFile.close()
487 if dcdata is not None:
488 dcdata.close()
489
490#-------------------------------------------------------------------------------
491
492if __name__ == "__main__":
493 generateFiles(os.path.dirname(__file__))
Note: See TracBrowser for help on using the repository browser.