shoestring-assembler 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- shoestring_assembler/__init__.py +5 -0
- shoestring_assembler/assembler.py +683 -0
- shoestring_assembler/cli.py +104 -0
- shoestring_assembler/display.py +64 -0
- shoestring_assembler/minimal_mustache.py +29 -0
- shoestring_assembler/recipe.schema.json +126 -0
- shoestring_assembler-0.0.1.dist-info/AUTHORS.rst +13 -0
- shoestring_assembler-0.0.1.dist-info/LICENSE +674 -0
- shoestring_assembler-0.0.1.dist-info/METADATA +56 -0
- shoestring_assembler-0.0.1.dist-info/RECORD +13 -0
- shoestring_assembler-0.0.1.dist-info/WHEEL +5 -0
- shoestring_assembler-0.0.1.dist-info/entry_points.txt +2 -0
- shoestring_assembler-0.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Console script for shoestring_assembler."""
|
|
2
|
+
|
|
3
|
+
from shoestring_assembler import assembler, display
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
from typing_extensions import Annotated
|
|
7
|
+
import time
|
|
8
|
+
import os
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
from rich.live import Live
|
|
12
|
+
from rich.table import Table
|
|
13
|
+
|
|
14
|
+
__version__ = "0.0.1"
|
|
15
|
+
|
|
16
|
+
typer_app = typer.Typer(name="Shoestring Assembler", no_args_is_help=True)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
cwd = os.getcwd()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@typer_app.command()
|
|
23
|
+
def update(recipe: str = "./recipe.toml"):
|
|
24
|
+
display.print_log(
|
|
25
|
+
"For help - go to [link=https://community.digitalshoestring.net]the Shoestring Community[/link]!"
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@typer_app.command(help="Fetch all base service modules")
|
|
30
|
+
def pull(recipe: str = "./recipe.toml"):
|
|
31
|
+
with Live(console=display.root_console, transient=True) as live:
|
|
32
|
+
live.console.print("[bold blue]Starting work!")
|
|
33
|
+
time.sleep(1)
|
|
34
|
+
live.console.print("1")
|
|
35
|
+
time.sleep(1)
|
|
36
|
+
live.console.print("2")
|
|
37
|
+
time.sleep(1)
|
|
38
|
+
live.console.print("3")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@typer_app.command()
|
|
42
|
+
def bootstrap(
|
|
43
|
+
recipe: str = "./recipe.toml",
|
|
44
|
+
verbose: Annotated[
|
|
45
|
+
bool, typer.Option("--verbose", help="enable verbose output")
|
|
46
|
+
] = False,
|
|
47
|
+
):
|
|
48
|
+
"""
|
|
49
|
+
Uses templates to bootstrap the solution config for the specified sources
|
|
50
|
+
"""
|
|
51
|
+
pass
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@typer_app.command()
|
|
55
|
+
def assemble(
|
|
56
|
+
recipe: str = "./recipe.toml",
|
|
57
|
+
verbose: Annotated[
|
|
58
|
+
bool, typer.Option("--verbose", help="enable verbose output")
|
|
59
|
+
] = False,
|
|
60
|
+
):
|
|
61
|
+
"""
|
|
62
|
+
Assembles the solution using the provided recipe
|
|
63
|
+
"""
|
|
64
|
+
if verbose:
|
|
65
|
+
display.debug = True
|
|
66
|
+
display.root_console.record = True
|
|
67
|
+
try:
|
|
68
|
+
display.print_top_header("Assembling Solution")
|
|
69
|
+
assembler_inst = assembler.Assembler(recipe)
|
|
70
|
+
assembler_inst.load_recipe()
|
|
71
|
+
assembler_inst.validate_recipe()
|
|
72
|
+
assembler_inst.clean()
|
|
73
|
+
assembler_inst.verify_filestructure(check_sources=False)
|
|
74
|
+
assembler_inst.gather_base_service_modules()
|
|
75
|
+
assembler_inst.check_user_config()
|
|
76
|
+
assembler_inst.generate_compose_file()
|
|
77
|
+
display.print_top_header("Finished")
|
|
78
|
+
finally:
|
|
79
|
+
display.root_console.save_html("./console.log")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@typer_app.callback(invoke_without_command=True)
|
|
83
|
+
def main(
|
|
84
|
+
version: Annotated[
|
|
85
|
+
bool, typer.Option("--version", "-v", help="Assembler version")
|
|
86
|
+
] = False,
|
|
87
|
+
):
|
|
88
|
+
if version:
|
|
89
|
+
display.print_log(f"Shoestring Assembler version {__version__}")
|
|
90
|
+
else:
|
|
91
|
+
pass
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def app():
|
|
95
|
+
if os.geteuid() == 0:
|
|
96
|
+
display.print_error(
|
|
97
|
+
"To try prevent you from breaking things, this program won't run with sudo or as root! \nRun it again without sudo or change to a non-root user."
|
|
98
|
+
)
|
|
99
|
+
sys.exit(255)
|
|
100
|
+
typer_app()
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
if __name__ == "__main__":
|
|
104
|
+
app()
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from rich.console import Console
|
|
2
|
+
from rich.panel import Panel
|
|
3
|
+
|
|
4
|
+
root_console = Console()
|
|
5
|
+
debug = False
|
|
6
|
+
|
|
7
|
+
# TODO: tee to file here
|
|
8
|
+
|
|
9
|
+
def _get_console(console):
|
|
10
|
+
if console:
|
|
11
|
+
return console
|
|
12
|
+
else:
|
|
13
|
+
return root_console
|
|
14
|
+
|
|
15
|
+
## Display Utilities
|
|
16
|
+
def print_top_header(text,console=None):
|
|
17
|
+
console = _get_console(console)
|
|
18
|
+
console.rule(f"[bold cyan]{text}", align="center")
|
|
19
|
+
|
|
20
|
+
def print_header(text, console=None):
|
|
21
|
+
console = _get_console(console)
|
|
22
|
+
# console.rule(f"[bold bright_magenta]{text}", style="bright_magenta", align="center")
|
|
23
|
+
console.print(Panel(f"{text}", style="bright_magenta"))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def print_complete(text, console=None):
|
|
27
|
+
console = _get_console(console)
|
|
28
|
+
# console.rule(
|
|
29
|
+
# f"[bold green]:white_check_mark: {text}",
|
|
30
|
+
# style="green",
|
|
31
|
+
# align="center",
|
|
32
|
+
# )
|
|
33
|
+
# console.print(Panel(f":white_check_mark: {text}", style="green"))
|
|
34
|
+
console.print(f":white_check_mark:\t{text}", style="green")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def print_error(text, console=None):
|
|
38
|
+
console = _get_console(console)
|
|
39
|
+
console.print(
|
|
40
|
+
Panel(
|
|
41
|
+
f"[bold red]{text}",
|
|
42
|
+
title="[bold red]:warning: Error",
|
|
43
|
+
title_align="left",
|
|
44
|
+
style="red",
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def print_log(text, console=None):
|
|
50
|
+
console = _get_console(console)
|
|
51
|
+
console.print(text)
|
|
52
|
+
|
|
53
|
+
def print_debug(text,console = None):
|
|
54
|
+
if not debug:
|
|
55
|
+
return
|
|
56
|
+
console = _get_console(console)
|
|
57
|
+
console.print(
|
|
58
|
+
Panel(
|
|
59
|
+
f"[bold grey58]{text}",
|
|
60
|
+
title="[bold grey58]Verbose log",
|
|
61
|
+
title_align="left",
|
|
62
|
+
style="grey58",
|
|
63
|
+
)
|
|
64
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Implementation of a very minimal version of the mustache spec -
|
|
3
|
+
namely only the {{variable}} part. "{{" can be escaped with a preceeding '\'. a "}}" can't be escaped within a variable name.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def render(template:str,data:dict,keep_if_no_match = True):
|
|
8
|
+
out_list = []
|
|
9
|
+
|
|
10
|
+
while template and len(template)>0:
|
|
11
|
+
try:
|
|
12
|
+
text, rest = template.split('{{',1)
|
|
13
|
+
out_list.append(text)
|
|
14
|
+
except ValueError: # no more "{{" in template
|
|
15
|
+
out_list.append(template)
|
|
16
|
+
break
|
|
17
|
+
|
|
18
|
+
if text[-1] == '\\': # escaped
|
|
19
|
+
out_list.append("{{")
|
|
20
|
+
template = rest
|
|
21
|
+
continue
|
|
22
|
+
|
|
23
|
+
variable, template = rest.split('}}')
|
|
24
|
+
if variable in data:
|
|
25
|
+
out_list.append(data[variable])
|
|
26
|
+
else:
|
|
27
|
+
out_list.append(f"{{{{{variable}}}}}" if keep_if_no_match else "")
|
|
28
|
+
|
|
29
|
+
return "".join(out_list)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://digitalshoestring.net/recipe.schema.json",
|
|
4
|
+
"title": "Shoestring Solution Recipe Schema",
|
|
5
|
+
"description": "A product in the catalog",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"recipe_vsn": {
|
|
9
|
+
"description": "Version of the recipe specification that has been used",
|
|
10
|
+
"type": "string",
|
|
11
|
+
"pattern": "^\\d+(?:\\.\\d+){2}$"
|
|
12
|
+
},
|
|
13
|
+
"solution": {
|
|
14
|
+
"description": "",
|
|
15
|
+
"type": "object",
|
|
16
|
+
"properties": {
|
|
17
|
+
"name": {
|
|
18
|
+
"description": "Name of the solution this recipe is for",
|
|
19
|
+
"type": "string"
|
|
20
|
+
},
|
|
21
|
+
"slug": {
|
|
22
|
+
"description": "Name of the solution this recipe is for",
|
|
23
|
+
"type": "string",
|
|
24
|
+
"pattern": "^[a-z_]*$"
|
|
25
|
+
},
|
|
26
|
+
"version": {
|
|
27
|
+
"description": "Version of the solution this recipe creates",
|
|
28
|
+
"type": "string",
|
|
29
|
+
"pattern": "^\\d+(?:\\.\\d+){2}$"
|
|
30
|
+
},
|
|
31
|
+
"description": {
|
|
32
|
+
"description": "A description of the solution",
|
|
33
|
+
"type": "string"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"required": [
|
|
37
|
+
"name",
|
|
38
|
+
"slug",
|
|
39
|
+
"version"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
"source": {
|
|
43
|
+
"description": "Key-Value map relating source names to a source description",
|
|
44
|
+
"type": "object",
|
|
45
|
+
"patternProperties": {
|
|
46
|
+
"^.*$": {
|
|
47
|
+
"description": "Source description",
|
|
48
|
+
"type": "object",
|
|
49
|
+
"properties": {
|
|
50
|
+
"file": {
|
|
51
|
+
"description": "File source description",
|
|
52
|
+
"type": "object",
|
|
53
|
+
"properties": {
|
|
54
|
+
"path": {
|
|
55
|
+
"description": "File system path for the source",
|
|
56
|
+
"type": "string"
|
|
57
|
+
},
|
|
58
|
+
"mode": {
|
|
59
|
+
"description": "Whether the source should be copied(default) or symlinked",
|
|
60
|
+
"enum": [
|
|
61
|
+
"copy",
|
|
62
|
+
"link"
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"required": [
|
|
67
|
+
"path"
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
"git": {
|
|
71
|
+
"description": "Git source description",
|
|
72
|
+
"type": "object",
|
|
73
|
+
"properties": {
|
|
74
|
+
"path": {
|
|
75
|
+
"description": "Path to find the repository. If a url, use as is. If a <username or org>/<slug>, assume github. If a <slug>, assume DigitalShoestringSolutions on github",
|
|
76
|
+
"type": "string"
|
|
77
|
+
},
|
|
78
|
+
"tag": {
|
|
79
|
+
"description": "Specifies the tag to use when pulling the repository (has precedence over branch)",
|
|
80
|
+
"type": "string"
|
|
81
|
+
},
|
|
82
|
+
"branch": {
|
|
83
|
+
"description": "Specifies which branch to pull",
|
|
84
|
+
"type": "string"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"$comment": "Ensures there is a (path and tag) or (path and branch) - will also be ok with all 3",
|
|
88
|
+
"oneOf": [
|
|
89
|
+
{
|
|
90
|
+
"required": [
|
|
91
|
+
"path",
|
|
92
|
+
"tag"
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"required": [
|
|
97
|
+
"path",
|
|
98
|
+
"branch"
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"$comment": "Ensures that either file or git are specified - will also be ok with both",
|
|
105
|
+
"anyOf": [
|
|
106
|
+
{
|
|
107
|
+
"required": [
|
|
108
|
+
"file"
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"required": [
|
|
113
|
+
"git"
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"required": [
|
|
122
|
+
"recipe_vsn",
|
|
123
|
+
"solution",
|
|
124
|
+
"source"
|
|
125
|
+
]
|
|
126
|
+
}
|