File: export-svg-layer.py

package info (click to toggle)
game-data-packager 85.1
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 33,332 kB
  • sloc: python: 15,320; sh: 713; ansic: 95; makefile: 60
file content (41 lines) | stat: -rw-r--r-- 1,095 bytes parent folder | download | duplicates (2)
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
#!/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: str, layer: str, output: str) -> None:
    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])