This commit is contained in:
Christian Fraß 2026-09-17 17:01:20 +02:00
parent 03e0734598
commit b4be19fec2
4 changed files with 149 additions and 91 deletions

View file

@ -1,7 +1,7 @@
from string import * import lib.string as _string
def command_generic( def generic(
head, head,
args args
): ):
@ -16,11 +16,11 @@ def command_generic(
template = "--{{name}}" template = "--{{name}}"
else: else:
template = "--{{name}}={{value}}" template = "--{{name}}={{value}}"
return string_coin( return _string.coin(
template, template,
{ {
"name": (arg.get("name", None) or ""), "name": (arg.get("name", None) or ""),
"value": string_wrap( "value": _string.wrap(
(arg.get("value", None) or ""), (arg.get("value", None) or ""),
"'", "'",
"'", "'",
@ -42,10 +42,10 @@ def command_generic(
) )
def command_directory_create( def directory_create(
path path
): ):
return command_generic( return generic(
"mkdir", "mkdir",
[ [
{"value": path}, {"value": path},
@ -54,10 +54,10 @@ def command_directory_create(
) )
def command_remove( def remove(
path path
): ):
return command_generic( return generic(
"rm", "rm",
[ [
{"value": path}, {"value": path},
@ -67,7 +67,7 @@ def command_remove(
) )
def command_copy( def copy(
path_from, path_from,
path_to, path_to,
options = None options = None
@ -80,7 +80,7 @@ def command_copy(
| |
(options or {}) (options or {})
) )
return command_generic( return generic(
"cp", "cp",
[ [
{"value": path_from}, {"value": path_from},
@ -101,7 +101,7 @@ def command_copy(
) )
def command_rsync( def rsync(
path_from, path_from,
path_to, path_to,
options = None options = None
@ -114,7 +114,7 @@ def command_rsync(
| |
(options or {}) (options or {})
) )
return command_generic( return generic(
"rsync", "rsync",
( (
[ [
@ -130,14 +130,14 @@ def command_rsync(
+ +
list( list(
map( map(
lambda exclude: {"name": "exclude", "value": exclude.replace(".", "\\."), "quote": True}, lambda exclude: {"name": "exclude", "value": exclude, "quote": True},
options["excludes"] options["excludes"]
) )
) )
+ +
[ [
{"value": string_coin("{{path}}/.", {"path": path_from})}, {"value": _string.coin("{{path}}/.", {"path": path_from})},
{"value": string_coin("{{path}}", {"path": path_to})}, {"value": _string.coin("{{path}}", {"path": path_to})},
] ]
) )
) )

View file

@ -1,7 +1,7 @@
import sys as _sys import sys as _sys
import os as _os import os as _os
from string import * import lib.string as _string
def execute( def execute(
@ -17,10 +17,10 @@ def execute(
| |
(options or {}) (options or {})
) )
command_complete = string_wrap( command_complete = _string.wrap(
command, command,
string_coin("cd {{directory}} && ", {"directory": (options["directory"] or "")}), _string.coin("cd {{directory}} && ", {"directory": (options["directory"] or "")}),
string_coin(" ; cd - > /dev/null", {}), _string.coin(" ; cd - > /dev/null", {}),
{ {
"mode": (not (options["directory"] is None)) "mode": (not (options["directory"] is None))
} }

View file

@ -1,4 +1,4 @@
def string_wrap( def wrap(
value, value,
character_open, character_open,
character_close, character_close,
@ -18,7 +18,7 @@ def string_wrap(
) )
def string_coin( def coin(
template, template,
arguments arguments
): ):

View file

@ -1,9 +1,9 @@
import os as _os import os as _os
import argparse as _argparse import argparse as _argparse
from lib.string import * import lib.string as _string
from lib.command import * import lib.command as _command
from lib.execute import * import lib.execute as _execute
def main(): def main():
@ -15,8 +15,10 @@ def main():
"action", "action",
type = str, type = str,
choices = [ choices = [
"selftest",
"clear", "clear",
"build", "build",
"init",
"run", "run",
"logs", "logs",
], ],
@ -75,18 +77,24 @@ def main():
"-p", "-p",
"--port", "--port",
type = int, type = int,
default = None, default = 8000,
metavar = "<port>", metavar = "<port>",
) )
args = argument_parser.parse_args() args = argument_parser.parse_args()
## exec ## 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): if (args.build_directory is None):
raise ValueError("build directory required") raise ValueError("build directory required")
else: else:
execute( _execute.execute(
command_remove(args.build_directory), _command.remove(args.build_directory),
{ {
"show": args.verbose, "show": args.verbose,
"run": (not args.dry_run), "run": (not args.dry_run),
@ -99,23 +107,29 @@ def main():
if (args.build_directory is None): if (args.build_directory is None):
raise ValueError("build directory required") raise ValueError("build directory required")
else: else:
execute( ## create build directory
command_directory_create(args.build_directory), if True:
_execute.execute(
_command.directory_create(args.build_directory),
{ {
"show": args.verbose, "show": args.verbose,
"run": (not args.dry_run), "run": (not args.dry_run),
} }
) )
if (not args.unnock): ## unlock
if True:
if (not args.unlock):
pass pass
else: else:
execute( _execute.execute(
command_remove( _command.remove(
_os.path.join(args.build_directory, "composer.lock") _os.path.join(args.build_directory, "composer.lock")
) )
) )
execute( ## copy files
command_rsync( if True:
_execute.execute(
_command.rsync(
args.source_directory, args.source_directory,
args.build_directory, args.build_directory,
{ {
@ -126,6 +140,7 @@ def main():
".env.example", ".env.example",
".env", ".env",
"vendor/", "vendor/",
"storage/",
"_ide_helper.php", "_ide_helper.php",
] ]
+ +
@ -144,8 +159,48 @@ def main():
"run": (not args.dry_run), "run": (not args.dry_run),
} }
) )
execute( ## set up storage
command_generic( 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", "composer",
[ [
{"value": "install"}, {"value": "install"},
@ -157,15 +212,18 @@ def main():
"run": (not args.dry_run), "run": (not args.dry_run),
} }
) )
if (args.env_path is None): ## run migrations
pass if True:
else: _execute.execute(
execute( _command.generic(
command_copy( "php",
args.env_path, [
_os.path.join(args.build_directory, ".env"), {"value": "artisan"},
{"value": "migrate"},
]
), ),
{ {
"directory": args.build_directory,
"show": args.verbose, "show": args.verbose,
"run": (not args.dry_run), "run": (not args.dry_run),
} }
@ -174,8 +232,8 @@ def main():
if (args.port is None): if (args.port is None):
raise ValueError("port required") raise ValueError("port required")
else: else:
execute( _execute.execute(
command_generic( _command.generic(
"php", "php",
[ [
{"value": "artisan"}, {"value": "artisan"},
@ -194,8 +252,8 @@ def main():
if (args.build_directory is None): if (args.build_directory is None):
raise ValueError("build directory required") raise ValueError("build directory required")
else: else:
execute( _execute.execute(
command_generic( _command.generic(
"tail", "tail",
[ [
{"name": "follow"}, {"name": "follow"},
@ -210,7 +268,7 @@ def main():
) )
else: else:
raise ValueError( raise ValueError(
string_coin( _string.coin(
"invalid action: {{action}}", "invalid action: {{action}}",
{ {
"action": args.action, "action": args.action,