summaryrefslogtreecommitdiff
path: root/bin/generate-inx-files
blob: 553e184dc9472f37ce58a9ccacb0e5ae4d86fc3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python

# Implemented support for multiple diverse versions of Inkstitch extensions in Inkscape.
#   - useful for testing and development
#   - useful for comparing different versions of Inkstitch


# this script generates inx files in inx/ directory from xml templates in templates/ directory
# - added support for alternative id registration and menu names for Inkscape extensions
#   - each xml template should be modified to use the new id_inkstitch and menu_inkstitch:
#        <id>org.inkstitch.....</id>    ---> <id>org.{{ id_inkstitch }}.....</id>
#        <submenu name="Ink/Stitch"     ---> <submenu name="{{ menu_inkstitch }}"
#     or input/output xml template should be modified to use the filetypename:
#        <filetypename>Ink/Stitch:...   ---> <filetypename>{{ menu_inkstitch }}:...


# Here's an example of how to use two Inkstitch extensions:
#   - install Inkstitch in two different locations (e.g. inkstitch and inkstitch-k)
#       - check out the Inkstitch repository in two different locations
#   - ensure 'make inx' is executed in both locations
#       - this will generate also inx/locale/ files
#   - generate modified inx files for second location
#       - in the second location:
#            > generate-inx-files -a k
#   - install the inx files in Inkscape extensions directory
#       - symlink .config/inkscape/extensions/inkstitch   -> inkstitch
#       - symlink .config/inkscape/extensions/inkstitch-k -> inkstitch-k
#   - modify .config/inkscape/keys/default.xml if necessary
#   - run Inkscape with both Inkstitch extensions enabled
#       - first version:  Extensions > Ink/Stitch
#       - second version: Extensions > Ink/Stitch-k

import sys
import os
from pathlib import Path
import argparse

# add inkstitch lib dir to python path
parent_dir = Path(__file__).resolve().parents[1]
sys.path.append(str(parent_dir))  # we need import from lib/ directory

# find inkex module
try:
    import inkex     # if it is already in the path, do nothing
except ImportError:  # if not, add inkscape version
    import subprocess
    inkscape_path = 'inkscape'
    # for now assume inkscape is in the path and raise an error if inkscape is not in the path
    system_path = subprocess.run([inkscape_path, "--system-data-directory"], capture_output=True, text=True).stdout.strip()
    inkex_path = os.path.join(system_path, "extensions")
    sys.path.append(inkex_path)

    # possible last attempt to import inkex may be as follows:
    # sys.path.append(os.path.join("/usr/share/inkscape/extensions"))
    # default inkex.py location on macOS
    # sys.path.append("/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/")


from lib.inx.generate import generate_inx_files

# parse arguments
#   -a, --alter letter a-z: generate inx files for the given alter
parser = argparse.ArgumentParser(description='Generate INX files, supporting multiple active inkstitch extensions in inkscape.')
parser.add_argument('-a', '--alter', type=str, help='Letter a-z representing the alter')
args = parser.parse_args()

# print(f"generate_inx_files: alter={args.alter}")

inx_path = parent_dir / "inx"
inx_path.mkdir(parents=True, exist_ok=True)

# if -a is not given, args.alter is None - not alternative inx, but generate default inx
generate_inx_files(args.alter)