Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
dtstyle_to_xmp.py
Go to the documentation of this file.
1#!/usr/bin/python3
2# This file is part of darktable,
3# Copyright (C) 2018 Kees Guequierre.
4# Copyright (C) 2021 Hubert Kowalski.
5#
6# darktable is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# darktable is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with darktable. If not, see <http://www.gnu.org/licenses/>.
18#
19#
20#
21#
22#
23#
24#
25#
26#
27 Simple script for converting darktable .dtstyle files to .xmp (version 2)
28#
29from sys import argv
30from os import path
31import xml.etree.ElementTree as ET
32
33if len(argv) != 3 :
34 print ("usage:",argv[0],"style.dtstyle file.xmp")
35 exit(1)
36
37# Check if the input file exists.
38if not path.exists(argv[1]):
39 print ("ERROR: input file:",argv[1],"doesn't exists.")
40 exit(1)
41
42# Check if the requested output file already exist
43if path.exists(argv[2]):
44 print ("ERROR: output file:",argv[2],"already exists.")
45 exit(1)
46
47try:
48 styletree = ET.parse(argv[1]) or die("This doesn't work for me")
49except ET.ParseError:
50 print ("ERROR: input file:",argv[1],"is not a valid dtsyle-file.")
51 exit(1)
52
53styleroot = styletree.getroot()
54
55# Create a new xml structure.
56xmpmeta=ET.Element("x:xmpmeta",{"xmlns:x":"adobe:ns:meta/",
57 "x:xmptk":"XMP Core 4.4.0-Exiv2"})
58rdf=ET.SubElement(xmpmeta,"rdf:RDF",{"xmlns:rdf":"http://www.w3.org/1999/02/22-rdf-syntax-ns#"})
59description=ET.SubElement(rdf,"rdf:Description",{"rdf:about":"",
60 "xmlns:xmp":"http://ns.adobe.com/xap/1.0/",
61 "xmlns:xmpMM":"http://ns.adobe.com/xap/1.0/mm/",
62 "xmlns:dc":"http://purl.org/dc/elements/1.1/",
63 "xmlns:darktable":"http://darktable.sf.net/",
64 "xmp:Rating":"0",
65 "xmpMM:DerivedFrom":"PureAwesome.raw",
66 "darktable:xmp_version":"2",
67 "darktable:raw_params":"0",
68 "darktable:auto_presets_applied":"1"})
69# darktable:history_end is not needed with a conversion, darktable will defaults to the topmost element in the history stack
70# "darktable:history_end":"8"})
71maskid=ET.SubElement(description,"darktable:mask_id")
72maskid.append(ET.Element("rdf:Seq"))
73masktype=ET.SubElement(description,"darktable:mask_type")
74masktype.append(ET.Element("rdf:Seq"))
75maskname=ET.SubElement(description,"darktable:mask_name")
76maskname.append(ET.Element("rdf:Seq"))
77maskversion=ET.SubElement(description,"darktable:mask_version")
78maskversion.append(ET.Element("rdf:Seq"))
79mask=ET.SubElement(description,"darktable:mask")
80mask.append(ET.Element("rdf:Seq"))
81masknb=ET.SubElement(description,"darktable:mask_nb")
82masknb.append(ET.Element("rdf:Seq"))
83masksrc=ET.SubElement(description,"darktable:mask_src")
84masksrc.append(ET.Element("rdf:Seq"))
85darktablehistory=ET.SubElement(description,"darktable:history")
86darktablehistoryid=ET.SubElement(darktablehistory,"rdf:Seq")
87
88# iterate through the dtstyle to find and add the used plugins to the xmp
89for plugins in styleroot.findall('./style/plugin'):
90 enabled = plugins.find('enabled')
91 if enabled.text == "1":
92 li=ET.SubElement(darktablehistoryid,"rdf:li")
93 li.set("darktable:enabled","1")
94
95 modversion = plugins.find('module')
96 if modversion != None:
97 li.set("darktable:modversion",modversion.text)
98
99 operation = plugins.find('operation')
100 if operation != None:
101 li.set("darktable:operation",operation.text)
102
103 params = plugins.find('op_params')
104 if params != None:
105 li.set("darktable:params",params.text)
106
107 blendop_params = plugins.find('blendop_params')
108 if blendop_params != None:
109 li.set("darktable:blendop_params",blendop_params.text)
110
111 blendop_version = plugins.find('blendop_version')
112 if blendop_version != None:
113 li.set("darktable:blendop_version",blendop_version.text)
114
115 multi_name = plugins.find('multi_name')
116 if multi_name != None:
117 if multi_name.text is None:
118 li.set("darktable:multi_name","")
119 else:
120 li.set("darktable:multi_name",multi_name.text)
121
122 multi_priority = plugins.find('multi_priority')
123 if multi_priority != None:
124 li.set("darktable:multi_priority",multi_priority.text)
125
126# Write the newly created xmp to a file
127ET.ElementTree(xmpmeta).write(argv[2],"UTF-8")