core/tools/build

140 lines
3.9 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python3
import sys as _sys
import os as _os
import json as _json
import stat as _stat
2023-03-04 15:10:08 +01:00
import argparse as _argparse
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"
2023-03-04 15:10:08 +01:00
targets = {
"app": {
"sources": [
_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", "checks", "generic_remote.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"),
],
"build": _os.path.join(dir_build, "heimdall"),
},
"test": {
"sources": [
_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", "checks", "generic_remote.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, "test", "test.py"),
],
"build": _os.path.join(dir_build, "heimdall-test"),
},
}
## args
argument_parser = _argparse.ArgumentParser(
)
argument_parser.add_argument(
"-t",
"--target",
type = str,
choices = ["app", "test"],
default = "app",
dest = "target_name",
help = "which target to build",
)
args = argument_parser.parse_args()
## 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
2023-03-04 15:10:08 +01:00
for path in targets[args.target_name]["sources"]:
compilation += (file_read(path) + "\n")
### write to file
2023-03-04 15:10:08 +01:00
if _os.path.exists(targets[args.target_name]["build"]):
_os.remove(targets[args.target_name]["build"])
file_write(targets[args.target_name]["build"], compilation)
### postproess
_os.chmod(
2023-03-04 15:10:08 +01:00
targets[args.target_name]["build"],
(_stat.S_IRWXU | _stat.S_IXGRP | _stat.S_IXOTH)
)
main()