E5XML/MultiProjectWriter.py

Sat, 05 Jul 2014 11:41:14 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 05 Jul 2014 11:41:14 +0200
changeset 3669
ac84ac3c0f05
parent 3621
15f23ed3f216
child 3670
f0cb7579c0b4
child 3835
9515e2c4cc8e
permissions
-rw-r--r--

Continued renaming eric5 for PyQt5 to eric6.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
3 # Copyright (c) 2008 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the writer class for writing an XML multi project file.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3060
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
11
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import time
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
14 from .XMLStreamWriterBase import XMLStreamWriterBase
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
15 from .Config import multiProjectFileFormatVersion
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import Preferences
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 import Utilities
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
20
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
21 class MultiProjectWriter(XMLStreamWriterBase):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Class implementing the writer class for writing an XML project file.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
25 def __init__(self, device, multiProject, multiProjectName):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
29 @param device reference to the I/O device to write to (QIODevice)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @param multiProject Reference to the multi project object
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
31 @param multiProjectName name of the project (string)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
33 XMLStreamWriterBase.__init__(self, device)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.name = multiProjectName
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.multiProject = multiProject
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 def writeXML(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 Public method to write the XML to the file.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
42 XMLStreamWriterBase.writeXML(self)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
44 self.writeDTD('<!DOCTYPE MultiProject SYSTEM "MultiProject-{0}.dtd">'
3621
15f23ed3f216 Fixed a few source code style issues found by the updated pe8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3545
diff changeset
45 .format(multiProjectFileFormatVersion))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 # add some generation comments
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
48 self.writeComment(" eric5 multi project file for multi project {0} "
3621
15f23ed3f216 Fixed a few source code style issues found by the updated pe8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3545
diff changeset
49 .format(self.name))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 if Preferences.getMultiProject("XMLTimestamp"):
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
51 self.writeComment(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
52 " Saved: {0} ".format(time.strftime('%Y-%m-%d, %H:%M:%S')))
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
53 self.writeComment(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
54 " Copyright (C) {0} ".format(time.strftime('%Y')))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 # add the main tag
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
57 self.writeStartElement("MultiProject")
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
58 self.writeAttribute("version", multiProjectFileFormatVersion)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 # do description
605
9c7527ecbf6e Removed code to encode and decode newlines from XML stream reader and writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 602
diff changeset
61 self.writeTextElement("Description", self.multiProject.description)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 # do the projects
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
64 self.writeStartElement("Projects")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 for project in self.multiProject.getProjects():
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
66 self.writeStartElement("Project")
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
67 self.writeAttribute("isMaster", str(project['master']))
3545
4a0bbb2d5457 Improved the multi project manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
68 self.writeAttribute("uid", project["uid"])
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
69 self.writeTextElement("ProjectName", project['name'])
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
70 self.writeTextElement(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
71 "ProjectFile",
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
72 Utilities.fromNativeSeparators(project['file']))
605
9c7527ecbf6e Removed code to encode and decode newlines from XML stream reader and writer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 602
diff changeset
73 self.writeTextElement("ProjectDescription", project['description'])
3197
4103c8013c36 Added support for the categorisation of projects to multi projects and changed the multi project file format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
74 self.writeTextElement("ProjectCategory", project['category'])
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
75 self.writeEndElement()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
76 self.writeEndElement()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
78 self.writeEndElement()
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
79 self.writeEndDocument()

eric ide

mercurial