summaryrefslogtreecommitdiffstats
path: root/share/extensions/tools
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
commitcca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch)
tree146f39ded1c938019e1ed42d30923c2ac9e86789 /share/extensions/tools
parentInitial commit. (diff)
downloadinkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.tar.xz
inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.zip
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'share/extensions/tools')
-rw-r--r--share/extensions/tools/generate_argparse_conf.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/share/extensions/tools/generate_argparse_conf.py b/share/extensions/tools/generate_argparse_conf.py
new file mode 100644
index 0000000..d99337b
--- /dev/null
+++ b/share/extensions/tools/generate_argparse_conf.py
@@ -0,0 +1,69 @@
+# coding=utf-8
+import os
+from string import Template
+import xml.etree.ElementTree as ET
+import argparse
+
+parser = argparse.ArgumentParser(
+ description="Reads an *.inx file and generates initialization code for argparse"
+)
+parser.add_argument("input")
+args = parser.parse_args()
+
+if os.path.isabs(args.input):
+ inpath = args.input
+else:
+ folder = os.path.dirname(os.path.realpath(__file__))
+ inpath = os.path.normpath(os.path.join(folder, args.input))
+
+templateWithType = Template(
+ 'self.arg_parser.add_argument("--$param", type=$type, dest="$param", default=$default)'
+)
+templateWithoutType = Template(
+ 'self.arg_parser.add_argument("--$param", dest="$param", default=$default)'
+)
+
+
+def handle_param_node(node):
+ if node.attrib["type"] == "float":
+ cmd = templateWithType.substitute(
+ param=node.attrib["name"], type="float", default=node.text
+ )
+ print(cmd)
+ elif node.attrib["type"] == "int":
+ cmd = templateWithType.substitute(
+ param=node.attrib["name"], type="int", default=node.text
+ )
+ print(cmd)
+ elif node.attrib["type"] == "boolean":
+ cmd = templateWithType.substitute(
+ param=node.attrib["name"],
+ type="inkex.inkbool",
+ default='"' + node.text + '"',
+ )
+ print(cmd)
+ elif node.attrib["type"] == "enum":
+ cmd = templateWithoutType.substitute(
+ param=node.attrib["name"], default='"' + node[0].text + '"'
+ )
+ print(cmd)
+ elif node.attrib["type"] == "notebook":
+ cmd = templateWithoutType.substitute(
+ param=node.attrib["name"], default='"' + node[0].attrib["name"] + '"'
+ )
+ print(cmd)
+ else:
+ # TODO: Implement other types of args
+ raise NotImplementedError
+
+
+def process_node(node):
+ for child in node:
+ if child.tag.endswith("param"):
+ handle_param_node(child)
+ process_node(child)
+
+
+tree = ET.parse(inpath)
+root = tree.getroot()
+process_node(root)