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,
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})},
]
)
)

View file

@ -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))
}

View file

@ -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
):

View file

@ -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 = "<port>",
)
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,23 +107,29 @@ def main():
if (args.build_directory is None):
raise ValueError("build directory required")
else:
execute(
command_directory_create(args.build_directory),
## create build directory
if True:
_execute.execute(
_command.directory_create(args.build_directory),
{
"show": args.verbose,
"run": (not args.dry_run),
}
)
if (not args.unnock):
## unlock
if True:
if (not args.unlock):
pass
else:
execute(
command_remove(
_execute.execute(
_command.remove(
_os.path.join(args.build_directory, "composer.lock")
)
)
execute(
command_rsync(
## copy files
if True:
_execute.execute(
_command.rsync(
args.source_directory,
args.build_directory,
{
@ -126,6 +140,7 @@ def main():
".env.example",
".env",
"vendor/",
"storage/",
"_ide_helper.php",
]
+
@ -144,8 +159,48 @@ def main():
"run": (not args.dry_run),
}
)
execute(
command_generic(
## 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,15 +212,18 @@ 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"),
## 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),
}
@ -174,8 +232,8 @@ def main():
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,