File: export-svg-layer.py

package info (click to toggle)
game-data-packager 73
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm
  • size: 23,420 kB
  • sloc: python: 11,086; sh: 609; makefile: 59
file content (39 lines) | stat: -rw-r--r-- 1,070 bytes parent folder | download
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
#!/usr/bin/python3
# encoding=utf-8
#
# Copyright © 2022 Simon McVittie
# SPDX-License-Identifier: GPL-2.0-or-later

import os
import subprocess
import sys
import tempfile

def main(source, layer, output):
    with tempfile.TemporaryDirectory() as temp:
        subprocess.run(
            [
                'xmlstarlet',
                'ed',
                '-d',
                ("//*[local-name() = 'g' and @inkscape:groupmode = 'layer' "
                 "and @id != '{}']".format(layer)),
            ],
            check=True,
            stdin=open(source, 'r'),
            stdout=open(os.path.join(temp, 'layer.svg'), 'w'),
        )
        subprocess.run(
            [
                'inkscape',
                '--export-area-page',
                '--export-plain-svg',
                '--export-filename=' + output,
                os.path.join(temp, 'layer.svg'),
            ],
            check=True,
            stdin=open(os.path.join(temp, 'layer.svg'), 'r'),
        )

if __name__ == '__main__':
    main(sys.argv[1], sys.argv[2], sys.argv[3])