Skip to content

Commit

Permalink
Move python code to standalone file
Browse files Browse the repository at this point in the history
  • Loading branch information
CAMOBAP committed Aug 4, 2023
1 parent 22d6935 commit b4dfcfe
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 46 deletions.
48 changes: 2 additions & 46 deletions inkscape-setup-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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())
run: source ${GITHUB_ACTION_PATH//\\//}/fix_eps_input_autorotate_param.py
shell: bash
52 changes: 52 additions & 0 deletions inkscape-setup-action/fix_eps_input_autorotate_param.py
Original file line number Diff line number Diff line change
@@ -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())

0 comments on commit b4dfcfe

Please sign in to comment.