From b4dfcfe987c4f269b6d82872011f38ee6d0a4d31 Mon Sep 17 00:00:00 2001 From: Alexande B Date: Fri, 4 Aug 2023 23:52:41 +0200 Subject: [PATCH] Move python code to standalone file --- inkscape-setup-action/action.yml | 48 +---------------- .../fix_eps_input_autorotate_param.py | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+), 46 deletions(-) create mode 100644 inkscape-setup-action/fix_eps_input_autorotate_param.py diff --git a/inkscape-setup-action/action.yml b/inkscape-setup-action/action.yml index 9f05236..b6c633d 100644 --- a/inkscape-setup-action/action.yml +++ b/inkscape-setup-action/action.yml @@ -33,49 +33,5 @@ runs: # https://github.com/metanorma/metanorma-cli/issues/309 - name: Update eps_input.inx to allow noninteractive EPS processing - shell: python - run: | - import os - import platform - import xml.etree.ElementTree as ET - import xml.dom.minidom as minidom - - home_path = os.path.expanduser("~") - - eps_input_paths = { - "Darwin": ["/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/eps_input.inx", "/usr/share/inkscape/extensions/eps_input.inx"], - "Windows": ["{}\\AppData\\Roaming\\inkscape\\eps_input.inx".format(home_path)], - "Linux": ["/usr/share/inkscape/extensions/eps_input.inx"] - }.get(platform.system(), []) - - eps_input_paths.append("~/.config/inkscape/eps_input.inx") - - default_ns = "http://www.inkscape.org/namespace/inkscape/extension" - ET.register_namespace("", default_ns) - - for inx in eps_input_paths: - if not os.path.exists(inx): - print("{} doesn't exists. Skip".format(inx)) - continue - - tree = ET.parse(inx) - root = tree.getroot() - - print("{} before processing:".format(inx)) - print(minidom.parseString(ET.tostring(root)).toprettyxml(indent=" ")) - - orig_param = tree.find("./param[@name='autorotate']", namespaces={"": default_ns}) - if orig_param is not None: - root.remove(orig_param) - print("Original autorotate param {} removed".format(orig_param)) - - new_param = ET.Element("param", - attrib={"name": "autorotate", - "type": "string", "gui-hidden": "true"}) - new_param.text = "None" - root.append(new_param) - - tree.write("./test.xml") - - print("{} after processing:".format(inx)) - print(minidom.parseString(ET.tostring(root)).toprettyxml()) \ No newline at end of file + run: source ${GITHUB_ACTION_PATH//\\//}/fix_eps_input_autorotate_param.py + shell: bash diff --git a/inkscape-setup-action/fix_eps_input_autorotate_param.py b/inkscape-setup-action/fix_eps_input_autorotate_param.py new file mode 100644 index 0000000..ab81612 --- /dev/null +++ b/inkscape-setup-action/fix_eps_input_autorotate_param.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +import os +import platform +import xml.etree.ElementTree as ET +import xml.dom.minidom as minidom + +home_path = os.path.expanduser("~") +esp_share_path = "share/inkscape/extensions/eps_input.inx" +eps_input_paths = { + "Darwin": [ + os.path.join("/Applications/Inkscape.app/Contents/Resources", esp_share_path), + os.path.join("/usr", esp_share_path) + ], + "Windows": [ + os.path.join("C:\\Program Files\\Inkscape", esp_share_path), + os.path.join(home_path, "AppData\\Roaming\\inkscape\\eps_input.inx") + ], + "Linux": [os.path.join("/usr", esp_share_path)] +}.get(platform.system(), []) + +default_ns = "http://www.inkscape.org/namespace/inkscape/extension" + +ET.register_namespace("", default_ns) + +for inx in eps_input_paths: + if not os.path.exists(inx): + print("{} doesn't exists. Skip".format(inx)) + continue + + tree = ET.parse(inx) + root = tree.getroot() + + print("{} before processing:".format(inx)) + print(minidom.parseString(ET.tostring(root)).toprettyxml(indent=" ")) + + orig_param = tree.find("./param[@name='autorotate']", + namespaces={"": default_ns}) + if orig_param is not None: + root.remove(orig_param) + print("Original autorotate param {} removed".format(orig_param)) + + new_param = ET.Element("param", + attrib={"name": "autorotate", + "type": "string", "gui-hidden": "true"}) + new_param.text = "None" + root.append(new_param) + + tree.write() + + print("{} after processing:".format(inx)) + print(minidom.parseString(ET.tostring(root)).toprettyxml()) \ No newline at end of file