core/tools/build

100 lines
2.4 KiB
Python
Executable file

#!/usr/bin/env python3
import sys as _sys
import os as _os
import json as _json
import stat as _stat
def file_read(path):
handle = open(path, "r")
content = handle.read()
handle.close()
return content
def file_write(path, content):
handle = open(path, "w")
handle.write(content)
handle.close()
def string_coin(template, arguments):
result = template
for (key, value, ) in arguments.items():
result = result.replace("{{%s}}" % key, value)
return result
def python_data_encode(data):
return _json.dumps(data, indent = "\t")
def main():
## consts
dir_source = "source"
dir_build = "build"
sources_logic = [
_os.path.join(dir_source, "logic", "packages.py"),
_os.path.join(dir_source, "logic", "lib.py"),
_os.path.join(dir_source, "logic", "localization.py"),
_os.path.join(dir_source, "logic", "condition.py"),
_os.path.join(dir_source, "logic", "conf.py"),
_os.path.join(dir_source, "logic", "checks", "_interface.py"),
_os.path.join(dir_source, "logic", "checks", "script.py"),
_os.path.join(dir_source, "logic", "checks", "file_state.py"),
_os.path.join(dir_source, "logic", "checks", "http_request.py"),
_os.path.join(dir_source, "logic", "channels", "_interface.py"),
_os.path.join(dir_source, "logic", "channels", "console.py"),
_os.path.join(dir_source, "logic", "channels", "email.py"),
_os.path.join(dir_source, "logic", "channels", "libnotify.py"),
_os.path.join(dir_source, "logic", "main.py"),
]
path_compilation = _os.path.join(dir_build, "heimdall")
## exec
if (not _os.path.exists(dir_build)):
_os.mkdir(dir_build)
compilation = ""
compilation += "#!/usr/bin/env python3\n\n"
### localization
if True:
localization_data = dict(
map(
lambda entry: (
entry.name.split(".")[0],
_json.loads(file_read(entry.path)),
),
filter(
lambda entry: (entry.is_file() and entry.name.endswith(".json")),
_os.scandir(_os.path.join(dir_source, "localization"))
)
)
)
compilation += string_coin(
"localization_data = {{data}}\n\n",
{
"data": python_data_encode(localization_data),
}
)
### logic
for path in sources_logic:
compilation += (file_read(path) + "\n")
### write to file
if _os.path.exists(path_compilation):
_os.remove(path_compilation)
file_write(path_compilation, compilation)
### postproess
_os.chmod(
path_compilation,
(_stat.S_IRWXU | _stat.S_IXGRP | _stat.S_IXOTH)
)
main()