2024-07-14 17:07:46 +03:00
|
|
|
|
import argparse
|
|
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
DEFAULTS = {
|
|
|
|
|
"description": "Очень полезный модуль",
|
2024-08-16 22:42:02 +03:00
|
|
|
|
"author": "Karkas Team",
|
2024-07-14 17:07:46 +03:00
|
|
|
|
"version": "1.0.0",
|
|
|
|
|
"privileged": "false",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_module(args):
|
2024-08-16 22:42:02 +03:00
|
|
|
|
module_dir = os.path.join("src/karkas_blocks/standard", args.module_name)
|
2024-07-14 17:07:46 +03:00
|
|
|
|
os.makedirs(module_dir, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
module_info = {
|
|
|
|
|
"id": args.id,
|
|
|
|
|
"name": args.name,
|
|
|
|
|
"description": args.description,
|
|
|
|
|
"author": args.author,
|
|
|
|
|
"version": args.version,
|
|
|
|
|
"privileged": args.privileged.lower() == "true",
|
|
|
|
|
"dependencies": {},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with open(os.path.join(module_dir, "info.json"), "w", encoding="utf-8") as f:
|
|
|
|
|
json.dump(module_info, f, ensure_ascii=False, indent=4)
|
|
|
|
|
|
|
|
|
|
with open(os.path.join(module_dir, "__init__.py"), "w", encoding="utf-8") as f:
|
|
|
|
|
f.write("# Init file for the module\n")
|
|
|
|
|
|
|
|
|
|
print(f"Module {args.module_name} created successfully.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def interactive_mode(args):
|
|
|
|
|
def get_input(prompt, default=None):
|
|
|
|
|
if default:
|
|
|
|
|
value = input(f"{prompt} [{default}]: ")
|
|
|
|
|
return value if value else default
|
|
|
|
|
else:
|
|
|
|
|
value = input(f"{prompt}: ")
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
module_name = get_input("Введите название модуля (папки)")
|
|
|
|
|
module_id = get_input("Введите ID")
|
|
|
|
|
name = get_input("Введите название модуля")
|
|
|
|
|
description = get_input(
|
|
|
|
|
"Введите описание модуля", args.description or DEFAULTS["description"]
|
|
|
|
|
)
|
|
|
|
|
author = get_input("Введите автора", args.author or DEFAULTS["author"])
|
|
|
|
|
version = get_input("Введите версию", args.version or DEFAULTS["version"])
|
|
|
|
|
privileged = get_input(
|
|
|
|
|
"Модуль привилегированный (true/false)",
|
|
|
|
|
args.privileged or DEFAULTS["privileged"],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
args = argparse.Namespace(
|
|
|
|
|
command="create",
|
|
|
|
|
module_name=module_name,
|
|
|
|
|
id=module_id,
|
|
|
|
|
name=name,
|
|
|
|
|
description=description,
|
|
|
|
|
author=author,
|
|
|
|
|
version=version,
|
|
|
|
|
privileged=privileged,
|
|
|
|
|
dependencies="",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
create_module(args)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
|
description="Утилита для создания директории модуля с файлами."
|
|
|
|
|
)
|
|
|
|
|
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
|
|
|
|
|
|
|
|
create_parser = subparsers.add_parser("create", help="Создать новый модуль")
|
|
|
|
|
create_parser.add_argument("--module_name", help="Название директории модуля")
|
|
|
|
|
create_parser.add_argument("--id", help="ID модуля")
|
|
|
|
|
create_parser.add_argument("--name", help="Название модуля")
|
|
|
|
|
create_parser.add_argument("--description", help="Описание модуля")
|
|
|
|
|
create_parser.add_argument("--author", help="Автор модуля")
|
|
|
|
|
create_parser.add_argument("--version", help="Версия модуля")
|
|
|
|
|
create_parser.add_argument(
|
|
|
|
|
"--privileged", help="Привилегированный модуль (true/false)"
|
|
|
|
|
)
|
|
|
|
|
create_parser.add_argument(
|
|
|
|
|
"--dependencies", help="Список зависимостей в формате имя:версия через запятую"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
if args.command == "create":
|
|
|
|
|
if not all(
|
|
|
|
|
[
|
|
|
|
|
args.module_name,
|
|
|
|
|
args.id,
|
|
|
|
|
args.name,
|
|
|
|
|
args.description,
|
|
|
|
|
args.author,
|
|
|
|
|
args.version,
|
|
|
|
|
args.privileged,
|
|
|
|
|
args.dependencies,
|
|
|
|
|
]
|
|
|
|
|
):
|
|
|
|
|
print("Переход в интерактивный режим...")
|
|
|
|
|
interactive_mode(args)
|
|
|
|
|
else:
|
|
|
|
|
create_module(args)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|