Added manifests to Krita resource bundler, updated docs
This commit is contained in:
37
main.py
37
main.py
@@ -22,6 +22,7 @@ import csv
|
||||
import os
|
||||
import shutil
|
||||
import zipfile
|
||||
import hashlib
|
||||
|
||||
def cmyk_to_hex(cp, mp, yp, kp):
|
||||
c = int(cp * 2.55)
|
||||
@@ -67,16 +68,6 @@ def main(file_format, input, output):
|
||||
out.write(f"</SCRIBUSCOLORS>")
|
||||
|
||||
case "krita":
|
||||
with open("mimetype", "w") as mt:
|
||||
mt.write(f"application/x-krita-resourcebundle")
|
||||
with open("meta.xml", "w") as meta:
|
||||
meta.write(f'<?xml version="1.0" encoding="UTF-8"?>\n')
|
||||
meta.write(f'<meta:meta>\n')
|
||||
meta.write(f"<meta:bundle-version>1</meta:bundle-version>\n")
|
||||
meta.write(f"<dc:author>CSV to Palette Generator</dc:author>\n")
|
||||
meta.write(f"<dc:description>Bundle Generated with CSV to Palette Generator</dc:description>\n")
|
||||
meta.write(f"</meta:meta")
|
||||
|
||||
os.mkdir("palettes")
|
||||
out.write(f"GIMP Palette\n")
|
||||
out.write(f"Name: {output}\n")
|
||||
@@ -87,7 +78,28 @@ def main(file_format, input, output):
|
||||
g = int(hex[2:4], 16)
|
||||
b = int(hex[4:6], 16)
|
||||
out.write(f"{r} {g} {b} {row[0]}\n")
|
||||
|
||||
if file_format == "krita":
|
||||
|
||||
palette_hash = hashlib.md5(output_file_format).hexdigest()
|
||||
|
||||
with open("mimetype", "w") as mt:
|
||||
mt.write(f"application/x-krita-resourcebundle")
|
||||
with open("meta.xml", "w") as meta:
|
||||
meta.write(f'<?xml version="1.0" encoding="UTF-8"?>\n')
|
||||
meta.write(f'<meta:meta>\n')
|
||||
meta.write(f"<meta:bundle-version>1</meta:bundle-version>\n")
|
||||
meta.write(f"<dc:author>CSV to Palette Generator</dc:author>\n")
|
||||
meta.write(f"<dc:description>Bundle Generated with CSV to Palette Generator</dc:description>\n")
|
||||
meta.write(f"</meta:meta")
|
||||
os.mkdir("META-INF")
|
||||
with open("manifest.xml", "w") as mani:
|
||||
mani.write(f'<?xml version="1.0" encoding="UTF-8"?>\n')
|
||||
mani.write(f'<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2">\n')
|
||||
mani.write(f'<manifest:file-entry manifest:media-type="application/x-krita-resourcebundle" manifest:full-path="/"/>\n')
|
||||
mani.write(f'<manifest:file-entry manifest:media-type="palettes" manifest:full-path="palettes/{output_file_format}" manifest:md5sum="{palette_hash}"/>\n')
|
||||
mani.write(f'</manifest:manifest>')
|
||||
shutil.move("manifest.xml", "META-INF")
|
||||
shutil.move(output_file_format, "palettes")
|
||||
zipname = f"{output}.bundle"
|
||||
with zipfile.ZipFile(zipname, "w") as zippy:
|
||||
@@ -95,11 +107,14 @@ def main(file_format, input, output):
|
||||
zippy.write("mimetype")
|
||||
zippy.write("palettes")
|
||||
zippy.write("palettes/" + output_file_format)
|
||||
zippy.write("META-INF")
|
||||
zippy.write("META-INF/manifest.xml")
|
||||
os.remove("mimetype")
|
||||
os.remove("meta.xml")
|
||||
os.remove("palettes/" + output_file_format)
|
||||
os.removedirs("palettes")
|
||||
|
||||
os.remove("META-INF/manifest.xml")
|
||||
os.removedirs("META-INF")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
||||
Reference in New Issue
Block a user