E5XML/ProjectHandler.py

changeset 613
5a6ee2af8ec0
parent 612
52a95c4536d7
parent 609
463fc2891cbf
child 614
c873699a1181
equal deleted inserted replaced
612:52a95c4536d7 613:5a6ee2af8ec0
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2003 - 2010 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the handler class for reading an XML project file.
8 """
9
10 import os
11
12 from .Config import projectFileFormatVersion
13 from .XMLHandlerBase import XMLHandlerBase
14
15 import Utilities
16
17 class ProjectHandler(XMLHandlerBase):
18 """
19 Class implementing a sax handler to read an XML project file.
20 """
21 def __init__(self, project):
22 """
23 Constructor
24
25 @param project Reference to the project object to store the
26 information into.
27 """
28 XMLHandlerBase.__init__(self)
29
30 self.startDocumentSpecific = self.startDocumentProject
31
32 self.elements.update({
33 'Project' : (self.startProject, self.defaultEndElement),
34 'Language' : (self.defaultStartElement, self.endLanguage),
35 'ProjectWordList' : (self.defaultStartElement, self.endProjectWordList),
36 'ProjectExcludeList' : (self.defaultStartElement,
37 self.endProjectExcludeList),
38 'Hash' : (self.defaultStartElement, self.endHash),
39 'ProgLanguage' : (self.startProgLanguage, self.endProgLanguage),
40 'ProjectType' : (self.defaultStartElement, self.endProjectType),
41 'Description' : (self.defaultStartElement, self.endDescription),
42 'Version' : (self.defaultStartElement, self.endVersion),
43 'Author' : (self.defaultStartElement, self.endAuthor),
44 'Email' : (self.defaultStartElement, self.endEmail),
45 'VcsType' : (self.defaultStartElement, self.endVcsType),
46 'VcsOptions' : (self.startVcsOptions, self.endVcsOptions),
47 'VcsOtherData' : (self.startVcsOtherData, self.endVcsOtherData),
48 'Dir' : (self.defaultStartElement, self.endDir),
49 'Name' : (self.defaultStartElement, self.endName),
50 'Source' : (self.startSource, self.endSource),
51 'Form' : (self.startForm, self.endForm),
52 'Translation' : (self.startTranslation, self.endTranslation),
53 'TranslationPattern' : (self.defaultStartElement,
54 self.endTranslationPattern),
55 'TranslationsBinPath' : (self.startTranslationsBinPath,
56 self.endTranslationsBinPath),
57 'TranslationException' : (self.startTranslationException,
58 self.endTranslationException),
59 'Resource' : (self.startResource, self.endResource),
60 'Interface' : (self.startInterface, self.endInterface),
61 'Other' : (self.startOther, self.endOther),
62 'MainScript' : (self.startMainScript, self.endMainScript),
63 'FiletypeAssociation' : (self.startFiletypeAssociation,
64 self.defaultEndElement),
65 'LexerAssociation' : (self.startLexerAssociation,
66 self.defaultEndElement),
67 'ProjectTypeSpecificData' : (self.startProjectTypeSpecificData,
68 self.endProjectTypeSpecificData),
69 'DocumentationParams' : (self.startDocumentationParams,
70 self.endDocumentationParams),
71 'PackagersParams' : (self.startPackagersParams, self.endPackagersParams),
72 'CheckersParams' : (self.startCheckersParams, self.endCheckersParams),
73 'OtherToolsParams' : (self.startOtherToolsParams, self.endOtherToolsParams),
74 'Eol' : (self.startEol, self.defaultEndElement),
75 # parameters kept for backward compatibility
76 'UIType' : (self.defaultStartElement, self.endUIType),
77 'TranslationPrefix' : (self.startTranslationPrefix,
78 self.endTranslationPrefix),
79 'Eric4DocParams' : (self.startEric4DocParams, self.endEric4DocParams),
80 'Eric4ApiParams' : (self.startEric4ApiParams, self.endEric4ApiParams),
81 'CxfreezeParams' : (self.startCxfreezeParams, self.endCxfreezeParams),
82 'PyLintParams' : (self.startPyLintParams, self.endPyLintParams),
83 })
84
85 self.project = project
86
87 def startDocumentProject(self):
88 """
89 Handler called, when the document parsing is started.
90 """
91 self.version = ''
92 self.pathStack = []
93
94 ###################################################
95 ## below follow the individual handler functions
96 ###################################################
97
98 def endLanguage(self):
99 """
100 Handler method for the "Language" end tag.
101 """
102 self.project.pdata["SPELLLANGUAGE"] = [self.buffer]
103
104 def endProjectWordList(self):
105 """
106 Handler method for the "ProjectWordList" end tag.
107 """
108 path = Utilities.toNativeSeparators(self.buffer)
109 self.project.pdata["SPELLWORDS"] = [path]
110
111 def endProjectExcludeList(self):
112 """
113 Handler method for the "ProjectExcludeList" end tag.
114 """
115 path = Utilities.toNativeSeparators(self.buffer)
116 self.project.pdata["SPELLEXCLUDES"] = [path]
117
118 def endHash(self):
119 """
120 Handler method for the "Hash" end tag.
121 """
122 self.project.pdata["HASH"] = [self.buffer]
123
124 def startProgLanguage(self, attrs):
125 """
126 Handler method for the "Source" start tag.
127
128 @param attrs list of tag attributes
129 """
130 mixedLanguage = int(attrs.get("mixed", "0"))
131 self.project.pdata["MIXEDLANGUAGE"] = [mixedLanguage]
132 self.buffer = ""
133
134 def endProgLanguage(self):
135 """
136 Handler method for the "ProgLanguage" end tag.
137 """
138 self.project.pdata["PROGLANGUAGE"] = [self.buffer]
139
140 def endProjectType(self):
141 """
142 Handler method for the "ProjectType" end tag.
143 """
144 self.project.pdata["PROJECTTYPE"] = [self.buffer]
145
146 def endDescription(self):
147 """
148 Handler method for the "Description" end tag.
149 """
150 self.buffer = self.unescape(self.buffer)
151 if self.version >= '4.3':
152 self.project.pdata["DESCRIPTION"] = [self.decodedNewLines(self.buffer)]
153 else:
154 self.project.pdata["DESCRIPTION"] = [self.buffer]
155
156 def endVersion(self):
157 """
158 Handler method for the "Version" end tag.
159 """
160 self.buffer = self.unescape(self.buffer)
161 self.project.pdata["VERSION"] = [self.buffer]
162
163 def endAuthor(self):
164 """
165 Handler method for the "Author" end tag.
166 """
167 self.buffer = self.unescape(self.buffer)
168 self.project.pdata["AUTHOR"] = [self.buffer]
169
170 def endEmail(self):
171 """
172 Handler method for the "Email" end tag.
173 """
174 self.buffer = self.unescape(self.buffer)
175 self.project.pdata["EMAIL"] = [self.buffer]
176
177 def endVcsType(self):
178 """
179 Handler method for the "VcsType" end tag.
180 """
181 self.project.pdata["VCS"] = [self.buffer]
182
183 def startVcsOptions(self, attrs):
184 """
185 Handler method for the "VcsOptions" start tag.
186
187 @param attrs list of tag attributes
188 """
189 self.defaultStartElement(attrs)
190 self._prepareBasics()
191
192 def endVcsOptions(self):
193 """
194 Handler method for the "VcsOptions" end tag.
195 """
196 try:
197 self.project.pdata["VCSOPTIONS"] = [self.stack[-1]]
198 except IndexError:
199 self.project.pdata["VCSOPTIONS"] = []
200
201 def startVcsOtherData(self, attrs):
202 """
203 Handler method for the "VcsOtherData" start tag.
204
205 @param attrs list of tag attributes
206 """
207 self.defaultStartElement(attrs)
208 self._prepareBasics()
209
210 def endVcsOtherData(self):
211 """
212 Handler method for the "VcsOtherData" end tag.
213 """
214 try:
215 self.project.pdata["VCSOTHERDATA"] = [self.stack[-1]]
216 except IndexError:
217 self.project.pdata["VCSOTHERDATA"] = []
218
219 def startProjectTypeSpecificData(self, attrs):
220 """
221 Handler method for the "ProjectTypeSpecificData" start tag.
222
223 @param attrs list of tag attributes
224 """
225 self.defaultStartElement(attrs)
226 self._prepareBasics()
227
228 def endProjectTypeSpecificData(self):
229 """
230 Handler method for the "ProjectTypeSpecificData" end tag.
231 """
232 try:
233 self.project.pdata["PROJECTTYPESPECIFICDATA"] = self.stack[-1]
234 except IndexError:
235 self.project.pdata["PROJECTTYPESPECIFICDATA"] = {}
236
237 def startDocumentationParams(self, attrs):
238 """
239 Handler method for the "DocumentationParams" start tag.
240
241 @param attrs list of tag attributes
242 """
243 self.defaultStartElement(attrs)
244 self._prepareBasics()
245
246 def endDocumentationParams(self):
247 """
248 Handler method for the "DocumentationParams" end tag.
249 """
250 try:
251 self.project.pdata["DOCUMENTATIONPARMS"] = self.stack[-1]
252 except IndexError:
253 self.project.pdata["DOCUMENTATIONPARMS"] = {}
254
255 def startPackagersParams(self, attrs):
256 """
257 Handler method for the "PackagersParams" start tag.
258
259 @param attrs list of tag attributes
260 """
261 self.defaultStartElement(attrs)
262 self._prepareBasics()
263
264 def endPackagersParams(self):
265 """
266 Handler method for the "PackagersParams" end tag.
267 """
268 try:
269 self.project.pdata["PACKAGERSPARMS"] = self.stack[-1]
270 except IndexError:
271 self.project.pdata["PACKAGERSPARMS"] = {}
272
273 def startCheckersParams(self, attrs):
274 """
275 Handler method for the "CheckersParams" start tag.
276
277 @param attrs list of tag attributes
278 """
279 self.defaultStartElement(attrs)
280 self._prepareBasics()
281
282 def endCheckersParams(self):
283 """
284 Handler method for the "CheckersParams" end tag.
285 """
286 try:
287 self.project.pdata["CHECKERSPARMS"] = self.stack[-1]
288 except IndexError:
289 self.project.pdata["CHECKERSPARMS"] = {}
290
291 def startOtherToolsParams(self, attrs):
292 """
293 Handler method for the "OtherToolsParams" start tag.
294
295 @param attrs list of tag attributes
296 """
297 self.defaultStartElement(attrs)
298 self._prepareBasics()
299
300 def endOtherToolsParams(self):
301 """
302 Handler method for the "OtherToolsParams" end tag.
303 """
304 try:
305 self.project.pdata["OTHERTOOLSPARMS"] = self.stack[-1]
306 except IndexError:
307 self.project.pdata["OTHERTOOLSPARMS"] = {}
308
309 def endDir(self):
310 """
311 Handler method for the "Dir" end tag.
312 """
313 self.pathStack.append(self.buffer)
314
315 def endName(self):
316 """
317 Handler method for the "Name" end tag.
318 """
319 self.pathStack.append(self.buffer)
320
321 def endTranslationPattern(self):
322 """
323 Handler method for the "TranslationPattern" end tag.
324 """
325 self.project.pdata["TRANSLATIONPATTERN"].append(
326 Utilities.toNativeSeparators(self.buffer))
327
328 def startTranslationsBinPath(self, attrs):
329 """
330 Handler method for the "TranslationsBinPath" start tag.
331
332 @param attrs list of tag attributes
333 """
334 self.pathStack = []
335 self.buffer = ""
336
337 def endTranslationsBinPath(self):
338 """
339 Handler method for the "TranslationsBinPath" end tag.
340 """
341 if self.version >= '4.3':
342 path = Utilities.toNativeSeparators(self.buffer)
343 else:
344 path = self.__buildPath()
345 self.project.pdata["TRANSLATIONSBINPATH"].append(path)
346
347 def startSource(self, attrs):
348 """
349 Handler method for the "Source" start tag.
350
351 @param attrs list of tag attributes
352 """
353 self.pathStack = []
354 self.buffer = ""
355
356 def endSource(self):
357 """
358 Handler method for the "Source" end tag.
359 """
360 if self.version >= '4.3':
361 path = Utilities.toNativeSeparators(self.buffer)
362 else:
363 path = self.__buildPath()
364 self.project.pdata["SOURCES"].append(path)
365
366 def startForm(self, attrs):
367 """
368 Handler method for the "Form" start tag.
369
370 @param attrs list of tag attributes
371 """
372 self.pathStack = []
373 self.buffer = ""
374
375 def endForm(self):
376 """
377 Handler method for the "Form" end tag.
378 """
379 if self.version >= '4.3':
380 path = Utilities.toNativeSeparators(self.buffer)
381 else:
382 path = self.__buildPath()
383 self.project.pdata["FORMS"].append(path)
384
385 def startTranslation(self, attrs):
386 """
387 Handler method for the "Translation" start tag.
388
389 @param attrs list of tag attributes
390 """
391 self.pathStack = []
392 self.buffer = ""
393
394 def endTranslation(self):
395 """
396 Handler method for the "Translation" end tag.
397 """
398 if self.version >= '4.3':
399 path = Utilities.toNativeSeparators(self.buffer)
400 else:
401 path = self.__buildPath()
402 self.project.pdata["TRANSLATIONS"].append(path)
403
404 def startTranslationException(self, attrs):
405 """
406 Handler method for the "TranslationException" start tag.
407
408 @param attrs list of tag attributes
409 """
410 self.pathStack = []
411 self.buffer = ""
412
413 def endTranslationException(self):
414 """
415 Handler method for the "TranslationException" end tag.
416 """
417 if self.version >= '4.3':
418 path = Utilities.toNativeSeparators(self.buffer)
419 else:
420 path = self.__buildPath()
421 self.project.pdata["TRANSLATIONEXCEPTIONS"].append(path)
422
423 def startResource(self, attrs):
424 """
425 Handler method for the "Resource" start tag.
426
427 @param attrs list of tag attributes
428 """
429 self.pathStack = []
430 self.buffer = ""
431
432 def endResource(self):
433 """
434 Handler method for the "Resource" end tag.
435 """
436 if self.version >= '4.3':
437 path = Utilities.toNativeSeparators(self.buffer)
438 else:
439 path = self.__buildPath()
440 self.project.pdata["RESOURCES"].append(path)
441
442 def startInterface(self, attrs):
443 """
444 Handler method for the "Interface" start tag.
445
446 @param attrs list of tag attributes
447 """
448 self.pathStack = []
449 self.buffer = ""
450
451 def endInterface(self):
452 """
453 Handler method for the "Interface" end tag.
454 """
455 if self.version >= '4.3':
456 path = Utilities.toNativeSeparators(self.buffer)
457 else:
458 path = self.__buildPath()
459 self.project.pdata["INTERFACES"].append(path)
460
461 def startOther(self, attrs):
462 """
463 Handler method for the "Other" start tag.
464
465 @param attrs list of tag attributes
466 """
467 self.pathStack = []
468 self.buffer = ""
469
470 def endOther(self):
471 """
472 Handler method for the "Other" end tag.
473 """
474 if self.version >= '4.3':
475 path = Utilities.toNativeSeparators(self.buffer)
476 else:
477 path = self.__buildPath()
478 self.project.pdata["OTHERS"].append(path)
479
480 def startMainScript(self, attrs):
481 """
482 Handler method for the "MainScript" start tag.
483
484 @param attrs list of tag attributes
485 """
486 self.pathStack = []
487 self.buffer = ""
488
489 def endMainScript(self):
490 """
491 Handler method for the "MainScript" end tag.
492 """
493 if self.version >= '4.3':
494 path = Utilities.toNativeSeparators(self.buffer)
495 else:
496 path = self.__buildPath()
497 self.project.pdata["MAINSCRIPT"] = [path]
498
499 def startFiletypeAssociation(self, attrs):
500 """
501 Handler method for the "FiletypeAssociation" start tag.
502
503 @param attrs list of tag attributes
504 """
505 pattern = attrs.get("pattern", "")
506 filetype = attrs.get("type", "OTHERS")
507 if pattern:
508 self.project.pdata["FILETYPES"][pattern] = filetype
509
510 def startLexerAssociation(self, attrs):
511 """
512 Handler method for the "LexerAssociation" start tag.
513
514 @param attrs list of tag attributes
515 """
516 pattern = attrs.get("pattern", "")
517 lexer = attrs.get("lexer", "")
518 if pattern:
519 self.project.pdata["LEXERASSOCS"][pattern] = lexer
520
521 def startEol(self, attrs):
522 """
523 Handler method for the "Eol" start tag.
524
525 @param attrs list of tag attributes
526 """
527 index = int(attrs.get("index", "0"))
528 self.project.pdata["EOL"] = [index]
529
530 def __buildPath(self):
531 """
532 Private method to assemble a path.
533
534 @return The ready assembled path. (string)
535 """
536 path = ""
537 if self.pathStack and not self.pathStack[0]:
538 self.pathStack[0] = os.sep
539 for p in self.pathStack:
540 path = os.path.join(path, p)
541 return path
542
543 def startProject(self, attrs):
544 """
545 Handler method for the "Project" start tag.
546
547 @param attrs list of tag attributes
548 """
549 self.version = attrs.get('version', projectFileFormatVersion)
550
551 def getVersion(self):
552 """
553 Public method to retrieve the version of the project.
554
555 @return String containing the version number.
556 """
557 return self.version
558
559 ###############################################################
560 ## below are handler methods kept for backward compatibility
561 ###############################################################
562
563 def endUIType(self):
564 """
565 Handler method for the "UIType" end tag.
566 """
567 self.project.pdata["PROJECTTYPE"] = [self.buffer]
568
569 def startTranslationPrefix(self, attrs):
570 """
571 Handler method for the "TranslationPrefix" start tag.
572
573 @param attrs list of tag attributes
574 """
575 self.pathStack = []
576 self.buffer = ""
577
578 def endTranslationPrefix(self):
579 """
580 Handler method for the "TranslationPrefix" end tag.
581 """
582 if self.version >= '4.3':
583 path = Utilities.toNativeSeparators(self.buffer)
584 else:
585 path = self.__buildPath()
586 if not path.endswith("_"):
587 path = "{0}_".format(path)
588 self.project.pdata["TRANSLATIONPATTERN"].append("{0}%language%.ts".format(path))
589
590 def startEric4DocParams(self, attrs):
591 """
592 Handler method for the "Eric4DocParams" start tag.
593
594 @param attrs list of tag attributes
595 """
596 self.defaultStartElement(attrs)
597 self._prepareBasics()
598
599 def endEric4DocParams(self):
600 """
601 Handler method for the "Eric4DocParams" end tag.
602 """
603 try:
604 self.project.pdata["DOCUMENTATIONPARMS"]["ERIC4DOC"] = self.stack[-1]
605 except IndexError:
606 pass
607
608 def startEric4ApiParams(self, attrs):
609 """
610 Handler method for the "Eric4ApiParams" start tag.
611
612 @param attrs list of tag attributes
613 """
614 self.defaultStartElement(attrs)
615 self._prepareBasics()
616
617 def endEric4ApiParams(self):
618 """
619 Handler method for the "Eric4ApiParams" end tag.
620 """
621 try:
622 self.project.pdata["DOCUMENTATIONPARMS"]["ERIC4API"] = self.stack[-1]
623 except IndexError:
624 pass
625
626 def startCxfreezeParams(self, attrs):
627 """
628 Handler method for the "CxfreezeParams" start tag.
629
630 @param attrs list of tag attributes
631 """
632 self.defaultStartElement(attrs)
633 self._prepareBasics()
634
635 def endCxfreezeParams(self):
636 """
637 Handler method for the "CxfreezeParams" end tag.
638 """
639 try:
640 self.project.pdata["PACKAGERSPARMS"]["CXFREEZE"] = self.stack[-1]
641 except IndexError:
642 self.project.pdata["PACKAGERSPARMS"] = {}
643
644 def startPyLintParams(self, attrs):
645 """
646 Handler method for the "PyLintParams" start tag.
647
648 @param attrs list of tag attributes
649 """
650 self.defaultStartElement(attrs)
651 self._prepareBasics()
652
653 def endPyLintParams(self):
654 """
655 Handler method for the "PyLintParams" end tag.
656 """
657 try:
658 self.project.pdata["CHECKERSPARMS"]["PYLINT"] = self.stack[-1]
659 except IndexError:
660 self.project.pdata["CHECKERSPARMS"] = {}

eric ide

mercurial