[ini]
This commit is contained in:
commit
03e0734598
29
readme.md
Normal file
29
readme.md
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
# Laravel Tools
|
||||||
|
|
||||||
|
Sammlung von Skripten und Werkzeugen zur Nutzung von Laravel
|
||||||
|
|
||||||
|
|
||||||
|
## Erstellung
|
||||||
|
|
||||||
|
### Voraussetzungen
|
||||||
|
|
||||||
|
(keine)
|
||||||
|
|
||||||
|
|
||||||
|
### Anweisungen
|
||||||
|
|
||||||
|
- `tools/build` ausführen (Schalter `-h` verwenden für Erklärung)
|
||||||
|
|
||||||
|
|
||||||
|
## Nutzung
|
||||||
|
|
||||||
|
### Voraussetzung
|
||||||
|
|
||||||
|
- Python3
|
||||||
|
|
||||||
|
|
||||||
|
### Anweisungen
|
||||||
|
|
||||||
|
- `tools/install` ausführen
|
||||||
|
- siehe `laravel-steer -h`
|
||||||
|
|
||||||
5
source/__main__.py
Normal file
5
source/__main__.py
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
from steer import *
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
0
source/lib/__init__.py
Normal file
0
source/lib/__init__.py
Normal file
144
source/lib/command.py
Normal file
144
source/lib/command.py
Normal file
|
|
@ -0,0 +1,144 @@
|
||||||
|
from string import *
|
||||||
|
|
||||||
|
|
||||||
|
def command_generic(
|
||||||
|
head,
|
||||||
|
args
|
||||||
|
):
|
||||||
|
def arg_process(arg):
|
||||||
|
if (arg.get("name", None) is None):
|
||||||
|
if (arg.get("value", None) is None):
|
||||||
|
template = None
|
||||||
|
else:
|
||||||
|
template = "{{value}}"
|
||||||
|
else:
|
||||||
|
if (arg.get("value", None) is None):
|
||||||
|
template = "--{{name}}"
|
||||||
|
else:
|
||||||
|
template = "--{{name}}={{value}}"
|
||||||
|
return string_coin(
|
||||||
|
template,
|
||||||
|
{
|
||||||
|
"name": (arg.get("name", None) or ""),
|
||||||
|
"value": string_wrap(
|
||||||
|
(arg.get("value", None) or ""),
|
||||||
|
"'",
|
||||||
|
"'",
|
||||||
|
{
|
||||||
|
"mode": arg.get("quote", False),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return " ".join(
|
||||||
|
[head]
|
||||||
|
+
|
||||||
|
list(
|
||||||
|
map(
|
||||||
|
arg_process,
|
||||||
|
args
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def command_directory_create(
|
||||||
|
path
|
||||||
|
):
|
||||||
|
return command_generic(
|
||||||
|
"mkdir",
|
||||||
|
[
|
||||||
|
{"value": path},
|
||||||
|
{"name": "parents"},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def command_remove(
|
||||||
|
path
|
||||||
|
):
|
||||||
|
return command_generic(
|
||||||
|
"rm",
|
||||||
|
[
|
||||||
|
{"value": path},
|
||||||
|
{"name": "recursive"},
|
||||||
|
{"name": "force"},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def command_copy(
|
||||||
|
path_from,
|
||||||
|
path_to,
|
||||||
|
options = None
|
||||||
|
):
|
||||||
|
options = (
|
||||||
|
{
|
||||||
|
"update": False,
|
||||||
|
"recursive": True,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
(options or {})
|
||||||
|
)
|
||||||
|
return command_generic(
|
||||||
|
"cp",
|
||||||
|
[
|
||||||
|
{"value": path_from},
|
||||||
|
{"value": path_to},
|
||||||
|
]
|
||||||
|
+
|
||||||
|
(
|
||||||
|
[{"name": "update"}]
|
||||||
|
if options["update"] else
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
+
|
||||||
|
(
|
||||||
|
[{"name": "recursive"}]
|
||||||
|
if options["recursive"] else
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def command_rsync(
|
||||||
|
path_from,
|
||||||
|
path_to,
|
||||||
|
options = None
|
||||||
|
):
|
||||||
|
options = (
|
||||||
|
{
|
||||||
|
"verbose": False,
|
||||||
|
"excludes": [],
|
||||||
|
}
|
||||||
|
|
|
||||||
|
(options or {})
|
||||||
|
)
|
||||||
|
return command_generic(
|
||||||
|
"rsync",
|
||||||
|
(
|
||||||
|
[
|
||||||
|
{"name": "update"},
|
||||||
|
{"name": "recursive"},
|
||||||
|
]
|
||||||
|
+
|
||||||
|
(
|
||||||
|
[{"name": "verbose"}]
|
||||||
|
if options["verbose"] else
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
+
|
||||||
|
list(
|
||||||
|
map(
|
||||||
|
lambda exclude: {"name": "exclude", "value": exclude.replace(".", "\\."), "quote": True},
|
||||||
|
options["excludes"]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
+
|
||||||
|
[
|
||||||
|
{"value": string_coin("{{path}}/.", {"path": path_from})},
|
||||||
|
{"value": string_coin("{{path}}", {"path": path_to})},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
32
source/lib/execute.py
Normal file
32
source/lib/execute.py
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
import sys as _sys
|
||||||
|
import os as _os
|
||||||
|
|
||||||
|
from string import *
|
||||||
|
|
||||||
|
|
||||||
|
def execute(
|
||||||
|
command,
|
||||||
|
options = None
|
||||||
|
):
|
||||||
|
options = (
|
||||||
|
{
|
||||||
|
"directory": None,
|
||||||
|
"show": False,
|
||||||
|
"run": True,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
(options or {})
|
||||||
|
)
|
||||||
|
command_complete = string_wrap(
|
||||||
|
command,
|
||||||
|
string_coin("cd {{directory}} && ", {"directory": (options["directory"] or "")}),
|
||||||
|
string_coin(" ; cd - > /dev/null", {}),
|
||||||
|
{
|
||||||
|
"mode": (not (options["directory"] is None))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if (options["show"]):
|
||||||
|
_sys.stderr.write(">> %s\n" % command_complete)
|
||||||
|
if (options["run"]):
|
||||||
|
_os.system(command_complete)
|
||||||
|
|
||||||
29
source/lib/string.py
Normal file
29
source/lib/string.py
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
def string_wrap(
|
||||||
|
value,
|
||||||
|
character_open,
|
||||||
|
character_close,
|
||||||
|
options = None
|
||||||
|
):
|
||||||
|
options = (
|
||||||
|
{
|
||||||
|
"mode": True,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
(options or {})
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
(character_open + value + character_close)
|
||||||
|
if options["mode"] else
|
||||||
|
value
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def string_coin(
|
||||||
|
template,
|
||||||
|
arguments
|
||||||
|
):
|
||||||
|
result = template
|
||||||
|
for (key, value, ) in arguments.items():
|
||||||
|
result = result.replace("{{%s}}" % key, value)
|
||||||
|
return result
|
||||||
|
|
||||||
219
source/steer.py
Normal file
219
source/steer.py
Normal file
|
|
@ -0,0 +1,219 @@
|
||||||
|
import os as _os
|
||||||
|
import argparse as _argparse
|
||||||
|
|
||||||
|
from lib.string import *
|
||||||
|
from lib.command import *
|
||||||
|
from lib.execute import *
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
## args
|
||||||
|
argument_parser = _argparse.ArgumentParser(
|
||||||
|
prog = "laravel-steer",
|
||||||
|
)
|
||||||
|
argument_parser.add_argument(
|
||||||
|
"action",
|
||||||
|
type = str,
|
||||||
|
choices = [
|
||||||
|
"clear",
|
||||||
|
"build",
|
||||||
|
"run",
|
||||||
|
"logs",
|
||||||
|
],
|
||||||
|
metavar = "<action>",
|
||||||
|
)
|
||||||
|
argument_parser.add_argument(
|
||||||
|
"-v",
|
||||||
|
"--verbose",
|
||||||
|
action = "store_true",
|
||||||
|
default = False,
|
||||||
|
)
|
||||||
|
argument_parser.add_argument(
|
||||||
|
"-q",
|
||||||
|
"--dry-run",
|
||||||
|
action = "store_true",
|
||||||
|
default = False,
|
||||||
|
)
|
||||||
|
argument_parser.add_argument(
|
||||||
|
"-s",
|
||||||
|
"--source-directory",
|
||||||
|
type = str,
|
||||||
|
default = None,
|
||||||
|
metavar = "<source-directory>",
|
||||||
|
)
|
||||||
|
argument_parser.add_argument(
|
||||||
|
"-b",
|
||||||
|
"--build-directory",
|
||||||
|
type = str,
|
||||||
|
default = None,
|
||||||
|
metavar = "<build-directory>",
|
||||||
|
)
|
||||||
|
argument_parser.add_argument(
|
||||||
|
"-u",
|
||||||
|
"--unlock",
|
||||||
|
action = "store_true",
|
||||||
|
default = False,
|
||||||
|
help = "do not copy composer.lock",
|
||||||
|
)
|
||||||
|
argument_parser.add_argument(
|
||||||
|
"-x",
|
||||||
|
"--exclude",
|
||||||
|
type = str,
|
||||||
|
action = "append",
|
||||||
|
default = None,
|
||||||
|
metavar = "<exclude>",
|
||||||
|
dest = "excludes",
|
||||||
|
)
|
||||||
|
argument_parser.add_argument(
|
||||||
|
"-e",
|
||||||
|
"--env-path",
|
||||||
|
type = str,
|
||||||
|
default = None,
|
||||||
|
metavar = "<env-path>",
|
||||||
|
)
|
||||||
|
argument_parser.add_argument(
|
||||||
|
"-p",
|
||||||
|
"--port",
|
||||||
|
type = int,
|
||||||
|
default = None,
|
||||||
|
metavar = "<port>",
|
||||||
|
)
|
||||||
|
args = argument_parser.parse_args()
|
||||||
|
|
||||||
|
## exec
|
||||||
|
if (args.action == "clear"):
|
||||||
|
if (args.build_directory is None):
|
||||||
|
raise ValueError("build directory required")
|
||||||
|
else:
|
||||||
|
execute(
|
||||||
|
command_remove(args.build_directory),
|
||||||
|
{
|
||||||
|
"show": args.verbose,
|
||||||
|
"run": (not args.dry_run),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
elif (args.action == "build"):
|
||||||
|
if (args.source_directory is None):
|
||||||
|
raise ValueError("source directory required")
|
||||||
|
else:
|
||||||
|
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,
|
||||||
|
{
|
||||||
|
"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),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
execute(
|
||||||
|
command_generic(
|
||||||
|
"composer",
|
||||||
|
[
|
||||||
|
{"value": "install"},
|
||||||
|
]
|
||||||
|
),
|
||||||
|
{
|
||||||
|
"directory": args.build_directory,
|
||||||
|
"show": args.verbose,
|
||||||
|
"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),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
elif (args.action == "run"):
|
||||||
|
if (args.port is None):
|
||||||
|
raise ValueError("port required")
|
||||||
|
else:
|
||||||
|
execute(
|
||||||
|
command_generic(
|
||||||
|
"php",
|
||||||
|
[
|
||||||
|
{"value": "artisan"},
|
||||||
|
{"value": "serve"},
|
||||||
|
{"name": "host", "value": "0.0.0.0"},
|
||||||
|
{"name": "port", "value": ("%u" % args.port)},
|
||||||
|
]
|
||||||
|
),
|
||||||
|
{
|
||||||
|
"directory": args.build_directory,
|
||||||
|
"show": args.verbose,
|
||||||
|
"run": (not args.dry_run),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
elif (args.action == "logs"):
|
||||||
|
if (args.build_directory is None):
|
||||||
|
raise ValueError("build directory required")
|
||||||
|
else:
|
||||||
|
execute(
|
||||||
|
command_generic(
|
||||||
|
"tail",
|
||||||
|
[
|
||||||
|
{"name": "follow"},
|
||||||
|
{"value": "storage/logs/laravel.log"},
|
||||||
|
]
|
||||||
|
),
|
||||||
|
{
|
||||||
|
"directory": args.build_directory,
|
||||||
|
"show": args.verbose,
|
||||||
|
"run": (not args.dry_run),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise ValueError(
|
||||||
|
string_coin(
|
||||||
|
"invalid action: {{action}}",
|
||||||
|
{
|
||||||
|
"action": args.action,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
34
tools/build
Executable file
34
tools/build
Executable file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
## consts
|
||||||
|
|
||||||
|
dir_source=source
|
||||||
|
|
||||||
|
|
||||||
|
## args
|
||||||
|
|
||||||
|
if [ $# -ge 1 ] ; then dir_build=$1 && shift ; else dir_build=/tmp/laravel-tools ; fi
|
||||||
|
|
||||||
|
|
||||||
|
## vars
|
||||||
|
|
||||||
|
path_steer=${dir_build}/laravel-steer
|
||||||
|
|
||||||
|
|
||||||
|
## exec
|
||||||
|
|
||||||
|
mkdir -p ${dir_build}
|
||||||
|
cd ${dir_source}
|
||||||
|
rm ${path_steer}.zip --force
|
||||||
|
zip \
|
||||||
|
${path_steer}.zip \
|
||||||
|
lib/string.py \
|
||||||
|
lib/command.py \
|
||||||
|
lib/execute.py \
|
||||||
|
lib/__init__.py \
|
||||||
|
steer.py \
|
||||||
|
__main__.py
|
||||||
|
cd -
|
||||||
|
echo "#!/usr/bin/env python3" | cat - ${path_steer}.zip > ${path_steer}
|
||||||
|
chmod +x ${path_steer}
|
||||||
|
rm ${path_steer}.zip
|
||||||
23
tools/install
Executable file
23
tools/install
Executable file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
## consts
|
||||||
|
|
||||||
|
dir_target_scripts=${HOME}/programs/laravel-tools
|
||||||
|
dir_target_executable=${HOME}/.local/bin
|
||||||
|
|
||||||
|
|
||||||
|
## args
|
||||||
|
|
||||||
|
if [ $# -ge 1 ] ; then dir_build=$1 && shift ; else dir_build=/tmp/laravel-tools ; fi
|
||||||
|
|
||||||
|
|
||||||
|
## vars
|
||||||
|
|
||||||
|
path_executable_steer=${dir_target_executable}/laravel-steer
|
||||||
|
|
||||||
|
|
||||||
|
## exec
|
||||||
|
|
||||||
|
mkdir --parent ${dir_target_scripts}
|
||||||
|
cp --recursive ${dir_build}/. ${dir_target_scripts}/
|
||||||
|
ln --force --symbolic ${dir_target_scripts}/laravel-steer ${path_executable_steer}
|
||||||
Loading…
Reference in a new issue