From b4be19fec28f9e926f41cb911684468e6c93a167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Thu, 17 Sep 2026 17:01:20 +0200 Subject: [PATCH] [mod] --- source/lib/command.py | 30 +++---- source/lib/execute.py | 8 +- source/lib/string.py | 4 +- source/steer.py | 198 +++++++++++++++++++++++++++--------------- 4 files changed, 149 insertions(+), 91 deletions(-) diff --git a/source/lib/command.py b/source/lib/command.py index 36375ee..88c5588 100644 --- a/source/lib/command.py +++ b/source/lib/command.py @@ -1,7 +1,7 @@ -from string import * +import lib.string as _string -def command_generic( +def generic( head, args ): @@ -16,11 +16,11 @@ def command_generic( template = "--{{name}}" else: template = "--{{name}}={{value}}" - return string_coin( + return _string.coin( template, { "name": (arg.get("name", None) or ""), - "value": string_wrap( + "value": _string.wrap( (arg.get("value", None) or ""), "'", "'", @@ -42,10 +42,10 @@ def command_generic( ) -def command_directory_create( +def directory_create( path ): - return command_generic( + return generic( "mkdir", [ {"value": path}, @@ -54,10 +54,10 @@ def command_directory_create( ) -def command_remove( +def remove( path ): - return command_generic( + return generic( "rm", [ {"value": path}, @@ -67,7 +67,7 @@ def command_remove( ) -def command_copy( +def copy( path_from, path_to, options = None @@ -80,7 +80,7 @@ def command_copy( | (options or {}) ) - return command_generic( + return generic( "cp", [ {"value": path_from}, @@ -101,7 +101,7 @@ def command_copy( ) -def command_rsync( +def rsync( path_from, path_to, options = None @@ -114,7 +114,7 @@ def command_rsync( | (options or {}) ) - return command_generic( + return generic( "rsync", ( [ @@ -130,14 +130,14 @@ def command_rsync( + list( map( - lambda exclude: {"name": "exclude", "value": exclude.replace(".", "\\."), "quote": True}, + lambda exclude: {"name": "exclude", "value": exclude, "quote": True}, options["excludes"] ) ) + [ - {"value": string_coin("{{path}}/.", {"path": path_from})}, - {"value": string_coin("{{path}}", {"path": path_to})}, + {"value": _string.coin("{{path}}/.", {"path": path_from})}, + {"value": _string.coin("{{path}}", {"path": path_to})}, ] ) ) diff --git a/source/lib/execute.py b/source/lib/execute.py index 4a4a9f2..8c211db 100644 --- a/source/lib/execute.py +++ b/source/lib/execute.py @@ -1,7 +1,7 @@ import sys as _sys import os as _os -from string import * +import lib.string as _string def execute( @@ -17,10 +17,10 @@ def execute( | (options or {}) ) - command_complete = string_wrap( + command_complete = _string.wrap( command, - string_coin("cd {{directory}} && ", {"directory": (options["directory"] or "")}), - string_coin(" ; cd - > /dev/null", {}), + _string.coin("cd {{directory}} && ", {"directory": (options["directory"] or "")}), + _string.coin(" ; cd - > /dev/null", {}), { "mode": (not (options["directory"] is None)) } diff --git a/source/lib/string.py b/source/lib/string.py index 37d76db..c25716c 100644 --- a/source/lib/string.py +++ b/source/lib/string.py @@ -1,4 +1,4 @@ -def string_wrap( +def wrap( value, character_open, character_close, @@ -18,7 +18,7 @@ def string_wrap( ) -def string_coin( +def coin( template, arguments ): diff --git a/source/steer.py b/source/steer.py index 44f1e23..14aa396 100644 --- a/source/steer.py +++ b/source/steer.py @@ -1,9 +1,9 @@ import os as _os import argparse as _argparse -from lib.string import * -from lib.command import * -from lib.execute import * +import lib.string as _string +import lib.command as _command +import lib.execute as _execute def main(): @@ -15,8 +15,10 @@ def main(): "action", type = str, choices = [ + "selftest", "clear", "build", + "init", "run", "logs", ], @@ -75,18 +77,24 @@ def main(): "-p", "--port", type = int, - default = None, + default = 8000, metavar = "", ) args = argument_parser.parse_args() ## exec - if (args.action == "clear"): + if (args.action == "selftest"): + print( + _command.directory_create( + "/tmp/foo" + ) + ) + elif (args.action == "clear"): if (args.build_directory is None): raise ValueError("build directory required") else: - execute( - command_remove(args.build_directory), + _execute.execute( + _command.remove(args.build_directory), { "show": args.verbose, "run": (not args.dry_run), @@ -99,53 +107,100 @@ def main(): if (args.build_directory is None): raise ValueError("build directory required") else: - execute( - command_directory_create(args.build_directory), - { - "show": args.verbose, - "run": (not args.dry_run), - } - ) - if (not args.unnock): - pass - else: - execute( - command_remove( - _os.path.join(args.build_directory, "composer.lock") - ) - ) - execute( - command_rsync( - args.source_directory, - args.build_directory, + ## create build directory + if True: + _execute.execute( + _command.directory_create(args.build_directory), { - "verbose": args.verbose, - "excludes": ( - [ - ".editorconfig", - ".env.example", - ".env", - "vendor/", - "_ide_helper.php", - ] - + - ( - ["composer.lock"] - if args.unlock else - [] - ) - + - (args.excludes or []) - ), + "show": args.verbose, + "run": (not args.dry_run), } - ), - { - "show": args.verbose, - "run": (not args.dry_run), - } - ) - execute( - command_generic( + ) + ## unlock + if True: + if (not args.unlock): + pass + else: + _execute.execute( + _command.remove( + _os.path.join(args.build_directory, "composer.lock") + ) + ) + ## copy files + if True: + _execute.execute( + _command.rsync( + args.source_directory, + args.build_directory, + { + "verbose": args.verbose, + "excludes": ( + [ + ".editorconfig", + ".env.example", + ".env", + "vendor/", + "storage/", + "_ide_helper.php", + ] + + + ( + ["composer.lock"] + if args.unlock else + [] + ) + + + (args.excludes or []) + ), + } + ), + { + "show": args.verbose, + "run": (not args.dry_run), + } + ) + ## set up storage + if True: + for name in ["sessions", "cache", "views"]: + _execute.execute( + # TODO: {"name": "group", "value": "www-data"}, + _command.generic( + "install", + [ + {"name": "directory"}, + {"name": "mode", "value": "777"}, + {"value": _os.path.join(args.build_directory, "storage", "framework", name)}, + ] + ), + { + "directory": args.build_directory, + "show": args.verbose, + "run": (not args.dry_run), + } + ) + ## place env file + if True: + if (args.env_path is None): + pass + else: + _execute.execute( + _command.copy( + args.env_path, + _os.path.join(args.build_directory, ".env"), + ), + { + "show": args.verbose, + "run": (not args.dry_run), + } + ) + elif (args.action == "init"): + if (args.build_directory is None): + raise ValueError("build directory required") + else: + ## install composer packages + if True: + _execute.execute( + _command.generic( "composer", [ {"value": "install"}, @@ -157,25 +212,28 @@ def main(): "run": (not args.dry_run), } ) - if (args.env_path is None): - pass - else: - execute( - command_copy( - args.env_path, - _os.path.join(args.build_directory, ".env"), - ), - { - "show": args.verbose, - "run": (not args.dry_run), - } - ) + ## run migrations + if True: + _execute.execute( + _command.generic( + "php", + [ + {"value": "artisan"}, + {"value": "migrate"}, + ] + ), + { + "directory": args.build_directory, + "show": args.verbose, + "run": (not args.dry_run), + } + ) elif (args.action == "run"): if (args.port is None): raise ValueError("port required") else: - execute( - command_generic( + _execute.execute( + _command.generic( "php", [ {"value": "artisan"}, @@ -194,8 +252,8 @@ def main(): if (args.build_directory is None): raise ValueError("build directory required") else: - execute( - command_generic( + _execute.execute( + _command.generic( "tail", [ {"name": "follow"}, @@ -210,7 +268,7 @@ def main(): ) else: raise ValueError( - string_coin( + _string.coin( "invalid action: {{action}}", { "action": args.action,