[mod]
This commit is contained in:
parent
03e0734598
commit
b4be19fec2
|
|
@ -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})},
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -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))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
):
|
):
|
||||||
|
|
|
||||||
198
source/steer.py
198
source/steer.py
|
|
@ -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,53 +107,100 @@ 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(
|
||||||
"show": args.verbose,
|
_command.directory_create(args.build_directory),
|
||||||
"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,
|
"show": args.verbose,
|
||||||
"excludes": (
|
"run": (not args.dry_run),
|
||||||
[
|
|
||||||
".editorconfig",
|
|
||||||
".env.example",
|
|
||||||
".env",
|
|
||||||
"vendor/",
|
|
||||||
"_ide_helper.php",
|
|
||||||
]
|
|
||||||
+
|
|
||||||
(
|
|
||||||
["composer.lock"]
|
|
||||||
if args.unlock else
|
|
||||||
[]
|
|
||||||
)
|
|
||||||
+
|
|
||||||
(args.excludes or [])
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
),
|
)
|
||||||
{
|
## unlock
|
||||||
"show": args.verbose,
|
if True:
|
||||||
"run": (not args.dry_run),
|
if (not args.unlock):
|
||||||
}
|
pass
|
||||||
)
|
else:
|
||||||
execute(
|
_execute.execute(
|
||||||
command_generic(
|
_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",
|
"composer",
|
||||||
[
|
[
|
||||||
{"value": "install"},
|
{"value": "install"},
|
||||||
|
|
@ -157,25 +212,28 @@ 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"},
|
||||||
{
|
]
|
||||||
"show": args.verbose,
|
),
|
||||||
"run": (not args.dry_run),
|
{
|
||||||
}
|
"directory": args.build_directory,
|
||||||
)
|
"show": args.verbose,
|
||||||
|
"run": (not args.dry_run),
|
||||||
|
}
|
||||||
|
)
|
||||||
elif (args.action == "run"):
|
elif (args.action == "run"):
|
||||||
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,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue