summaryrefslogtreecommitdiff
path: root/lib/inx/utils.py
blob: da0a461489135b749214953e665e96a23bbe3b13 (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
import os
from os.path import dirname
from jinja2 import Environment, FileSystemLoader

from ..i18n import translation as inkstitch_translation


_top_path = dirname(dirname(dirname(os.path.realpath(__file__))))
inx_path = os.path.join(_top_path, "inx")
template_path = os.path.join(_top_path, "templates")

def build_environment():
    env = Environment(
        loader = FileSystemLoader(template_path),
        autoescape = True,
        extensions=['jinja2.ext.i18n']
    )

    env.install_gettext_translations(inkstitch_translation)

    return env

def write_inx_file(name, contents):
    inx_file_name = "inkstitch_%s.inx" % name
    with open(os.path.join(inx_path, inx_file_name), 'w') as inx_file:
        print >> inx_file, contents