2021-03-12 04:17:19 +00:00
|
|
|
# Authors: see git history
|
|
|
|
#
|
|
|
|
# Copyright (c) 2010 Authors
|
|
|
|
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
|
|
|
|
2020-03-07 03:39:25 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2018-08-20 02:14:10 +00:00
|
|
|
from os.path import dirname
|
|
|
|
|
2020-03-07 03:39:25 +00:00
|
|
|
from jinja2 import Environment, FileSystemLoader
|
2018-08-20 02:14:10 +00:00
|
|
|
|
|
|
|
_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")
|
|
|
|
|
2018-08-22 00:32:50 +00:00
|
|
|
|
2018-08-20 02:14:10 +00:00
|
|
|
def build_environment():
|
|
|
|
env = Environment(
|
2018-08-22 00:32:50 +00:00
|
|
|
loader=FileSystemLoader(template_path),
|
|
|
|
autoescape=True,
|
2018-08-20 02:14:10 +00:00
|
|
|
extensions=['jinja2.ext.i18n']
|
|
|
|
)
|
|
|
|
|
2020-03-07 03:39:25 +00:00
|
|
|
if "BUILD" in os.environ:
|
|
|
|
# building a ZIP release, with inkstitch packaged as a binary
|
2021-03-04 17:40:53 +00:00
|
|
|
# Command tag and icons path
|
2020-03-07 03:39:25 +00:00
|
|
|
if sys.platform == "win32":
|
2021-09-26 09:42:17 +00:00
|
|
|
env.globals["command_tag"] = '<command location="inx">../bin/inkstitch.exe</command>'
|
2024-11-18 10:39:57 +00:00
|
|
|
env.globals["icon_path"] = '../bin/icons/'
|
2021-03-04 17:40:53 +00:00
|
|
|
elif sys.platform == "darwin":
|
2021-12-08 21:18:41 +00:00
|
|
|
env.globals["command_tag"] = '<command location="inx">../../MacOS/inkstitch</command>'
|
2024-11-18 10:39:57 +00:00
|
|
|
env.globals["icon_path"] = '../icons/'
|
2020-03-07 03:39:25 +00:00
|
|
|
else:
|
2021-09-26 09:42:17 +00:00
|
|
|
env.globals["command_tag"] = '<command location="inx">../bin/inkstitch</command>'
|
2024-11-18 10:39:57 +00:00
|
|
|
env.globals["icon_path"] = '../bin/icons/'
|
2020-03-07 03:39:25 +00:00
|
|
|
else:
|
|
|
|
# user is running inkstitch.py directly as a developer
|
2021-09-26 09:42:17 +00:00
|
|
|
env.globals["command_tag"] = '<command location="inx" interpreter="python">../inkstitch.py</command>'
|
2024-11-18 10:39:57 +00:00
|
|
|
env.globals["icon_path"] = '../icons/'
|
2018-08-20 02:14:10 +00:00
|
|
|
return env
|
|
|
|
|
2018-08-22 00:32:50 +00:00
|
|
|
|
2018-08-20 02:14:10 +00:00
|
|
|
def write_inx_file(name, contents):
|
2019-04-17 00:05:45 +00:00
|
|
|
inx_file_name = "inkstitch_%s.inx" % name
|
2021-09-26 09:42:17 +00:00
|
|
|
with open(os.path.join(inx_path, inx_file_name), 'w', encoding="utf-8") as inx_file:
|
2021-03-04 17:40:53 +00:00
|
|
|
print(contents, file=inx_file)
|