Krita Source Code Documentation
Loading...
Searching...
No Matches
CPMT_CoMet_XML_Exporter.py
Go to the documentation of this file.
1"""
2SPDX-FileCopyrightText: 2018 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3
4This file is part of the Comics Project Management Tools(CPMT).
5
6SPDX-License-Identifier: GPL-3.0-or-later
7"""
8
9"""
10Write a CoMet xml file to url
11"""
12
13import os
14from xml.dom import minidom
15
16def write_xml(configDictionary = {}, pagesLocationList = [], location = str()):
17 document = minidom.Document()
18 root = document.createElement("comet")
19 root.setAttribute("xmlns:comet", "http://www.denvog.com/comet/")
20 root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
21 root.setAttribute("xsi:schemaLocation", "http://www.denvog.com http://www.denvog.com/comet/comet.xsd")
22 document.appendChild(root)
23
24 title = document.createElement("title")
25 if "title" in configDictionary.keys():
26 title.appendChild(document.createTextNode(str(configDictionary["title"])))
27 else:
28 title.appendChild(document.createTextNode(str("Untitled Comic")))
29 root.appendChild(title)
30 description = document.createElement("description")
31 if "summary" in configDictionary.keys():
32 description.appendChild(document.createTextNode(str(configDictionary["summary"])))
33 else:
34 description.appendChild(document.createTextNode(str("There was no summary upon generation of this file.")))
35 root.appendChild(description)
36 if "seriesName" in configDictionary.keys():
37 series = document.createElement("series")
38 series.appendChild(document.createTextNode(str(configDictionary["seriesName"])))
39 root.appendChild(series)
40 if "seriesNumber" in configDictionary.keys():
41 issue = document.createElement("issue")
42 issue.appendChild(document.createTextNode(str(configDictionary["seriesNumber"])))
43 root.appendChild(issue)
44 if "seriesVolume" in configDictionary.keys():
45 volume = document.createElement("volume")
46 volume.appendChild(document.createTextNode(str(configDictionary["seriesVolume"])))
47 root.appendChild(volume)
48
49 if "publisherName" in configDictionary.keys():
50 publisher = document.createElement("publisher")
51 publisher.appendChild(document.createTextNode(str(configDictionary["publisherName"])))
52 root.appendChild(publisher)
53
54 if "publishingDate" in configDictionary.keys():
55 date = document.createElement("date")
56 date.appendChild(document.createTextNode(str(configDictionary["publishingDate"])))
57 root.appendChild(date)
58
59 if "genre" in configDictionary.keys():
60 genreListConf = configDictionary["genre"]
61 if isinstance(configDictionary["genre"], dict):
62 genreListConf = configDictionary["genre"].keys()
63 for genreE in genreListConf:
64 genre = document.createElement("genre")
65 genre.appendChild(document.createTextNode(str(genreE)))
66 root.appendChild(genre)
67
68 if "characters" in configDictionary.keys():
69 for char in configDictionary["characters"]:
70 character = document.createElement("character")
71 character.appendChild(document.createTextNode(str(char)))
72 root.appendChild(character)
73
74 if "format" in configDictionary.keys():
75 format = document.createElement("format")
76 format.appendChild(document.createTextNode(str(",".join(configDictionary["format"]))))
77 root.appendChild(format)
78
79 if "language" in configDictionary.keys():
80 language = document.createElement("language")
81 language.appendChild(document.createTextNode(str(configDictionary["language"])))
82 root.appendChild(language)
83 if "rating" in configDictionary.keys():
84 rating = document.createElement("rating")
85 rating.appendChild(document.createTextNode(str(configDictionary["rating"])))
86 root.appendChild(rating)
87 #rights = document.createElement("rights")
88 if "pages" in configDictionary.keys():
89 pages = document.createElement("pages")
90 pages.appendChild(document.createTextNode(str(len(configDictionary["pages"]))))
91 root.appendChild(pages)
92
93 if "isbn-number" in configDictionary.keys():
94 identifier = document.createElement("identifier")
95 identifier.appendChild(document.createTextNode(str(configDictionary["isbn-number"])))
96 root.appendChild(identifier)
97
98 if "authorList" in configDictionary.keys():
99 for authorE in range(len(configDictionary["authorList"])):
100 author = document.createElement("creator")
101 authorDict = configDictionary["authorList"][authorE]
102 if "role" in authorDict.keys():
103 if str(authorDict["role"]).lower() in ["writer", "penciller", "editor", "assistant editor", "cover artist", "letterer", "inker", "colorist"]:
104 if str(authorDict["role"]).lower() == "cover artist":
105 author = document.createElement("coverDesigner")
106 elif str(authorDict["role"]).lower() == "assistant editor":
107 author = document.createElement("editor")
108 else:
109 author = document.createElement(str(authorDict["role"]).lower())
110 stringName = []
111 if "last-name" in authorDict.keys():
112 stringName.append(authorDict["last-name"])
113 if "first-name" in authorDict.keys():
114 stringName.append(authorDict["first-name"])
115 if "nickname" in authorDict.keys():
116 stringName.append("(" + authorDict["nickname"] + ")")
117 author.appendChild(document.createTextNode(str(",".join(stringName))))
118 root.appendChild(author)
119
120 if "pages" in configDictionary.keys():
121 if "cover" in configDictionary.keys():
122 pageList = []
123 pageList = configDictionary["pages"]
124 coverNumber = pageList.index(configDictionary["cover"])
125 if len(pagesLocationList) >= coverNumber:
126 coverImage = document.createElement("coverImage")
127 coverImage.appendChild(document.createTextNode(str(os.path.basename(pagesLocationList[coverNumber]))))
128 root.appendChild(coverImage)
129 readingDirection = document.createElement("readingDirection")
130 readingDirection.appendChild(document.createTextNode(str("ltr")))
131 if "readingDirection" in configDictionary.keys():
132 if configDictionary["readingDirection"] == "rightToLeft":
133 readingDirection.appendChild(document.createTextNode(str("rtl")))
134 root.appendChild(readingDirection)
135
136 f = open(location, 'w', newline="", encoding="utf-8")
137 f.write(document.toprettyxml(indent=" "))
138 f.close()
139 return True
write_xml(configDictionary={}, pagesLocationList=[], location=str())