Skip to content

Commit

Permalink
Merge pull request #116 from metanorma/feature/prevent-interactivity-…
Browse files Browse the repository at this point in the history
…on-inkscape-eps-inport

metanorma/metanorma-cli#309 modify eps_input.inx autorotate param
  • Loading branch information
CAMOBAP authored Aug 5, 2023
2 parents 8a40b74 + a839a62 commit 880e525
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ jobs:
test-gem-docker-gh-rubygem-setup-action:
name: Test gh-rubygems-setup-action & docker-gem-install in docker
runs-on: ubuntu-latest
container: docker://metanorma/metanorma
container:
image: metanorma/metanorma:ubuntu-latest
steps:
- uses: actions/checkout@v3

Expand Down
10 changes: 10 additions & 0 deletions inkscape-setup-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@ runs:
if os.system(cmd) != 0:
print("Command {} FAILED!".format(cmd))
sys.exit(1)
# https://github.com/metanorma/metanorma-cli/issues/309
- name: Update eps_input.inx to allow noninteractive EPS processing
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo python ${GITHUB_ACTION_PATH//\\//}/fix_eps_input_autorotate_param.py
else
python ${GITHUB_ACTION_PATH//\\//}/fix_eps_input_autorotate_param.py
fi
shell: bash
53 changes: 53 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,53 @@
#!/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 eps_input_path in eps_input_paths:
if not os.path.exists(eps_input_path):
print("{} doesn't exists. Skip".format(eps_input_path))
continue

tree = ET.parse(eps_input_path)
root = tree.getroot()

print("{} before processing:".format(eps_input_path))
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(eps_input_path)

print("{} after processing:".format(eps_input_path))
print(minidom.parseString(ET.tostring(root)).toprettyxml())

0 comments on commit 880e525

Please sign in to comment.