summaryrefslogtreecommitdiff
path: root/bin/gen-input-inx
blob: 6351d062ec9b9414b26bc161a3fba464ba74b4e2 (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
#!/usr/bin/env python

import sys, os
from os.path import dirname
from libembroidery import *
from jinja2 import Environment, FileSystemLoader, select_autoescape


def build_environment():
    template_dir = os.path.join(dirname(dirname(os.path.realpath(__file__))), "templates")

    return Environment(
        loader = FileSystemLoader(template_dir),
        autoescape = True
    )


def libembroidery_input_formats():
    formatList = embFormatList_create()
    curFormat = formatList
    while(curFormat):
        extension = embFormat_extension(curFormat)
        description = embFormat_description(curFormat)
        reader_state = embFormat_readerState(curFormat)

        if reader_state.strip() and embFormat_type(curFormat) != EMBFORMAT_OBJECTONLY:
            # extension includes the dot, so we'll remove it
            yield extension[1:], description

        curFormat = curFormat.next


def main():
    env = build_environment()
    template = env.get_template('embroider_input.inx')

    for format, description in libembroidery_input_formats():
        inx = template.render(format=format, description=description)

        with open("inx/inkstitch_input_%s.inx" % format.upper(), 'w') as inx_file:
            inx_file.write(inx)


if __name__ == "__main__":
    sys.exit(main())