eric6/E5XML/MultiProjectWriter.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7780
41420f82c0ac
child 7960
e8fc383322f7
permissions
-rw-r--r--

Updated copyright for 2021.

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
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2008 - 2021 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
3833
64b5f5fa3b00 Changed multi project files to contain relative paths to the contained project files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3670
diff changeset
10 import os
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import time
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
13 from .XMLStreamWriterBase import XMLStreamWriterBase
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
14 from .Config import multiProjectFileFormatVersion
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 import Preferences
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import Utilities
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
19
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
20 class MultiProjectWriter(XMLStreamWriterBase):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 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
23 """
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
24 def __init__(self, device, multiProject, multiProjectName):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
28 @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
29 @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
30 @param multiProjectName name of the project (string)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
602
2f32aef5cc67 Migrated the multi-project handler to multi-project reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
32 XMLStreamWriterBase.__init__(self, device)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.name = multiProjectName
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.multiProject = multiProject
3833
64b5f5fa3b00 Changed multi project files to contain relative paths to the contained project files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3670
diff changeset
36 self.path = os.path.dirname(device.fileName())
0
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
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3621
diff changeset
48 self.writeComment(" eric6 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",
3833
64b5f5fa3b00 Changed multi project files to contain relative paths to the contained project files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3670
diff changeset
72 Utilities.relativeUniversalPath(project['file'], self.path))
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