Skip to content

Commit 36ecf62

Browse files
committed
Main commit
Added build function to build files in case create fails Added copy_files.py, incharge of copying the files from assets to their respective places
1 parent f8af0a5 commit 36ecf62

File tree

5 files changed

+101
-21
lines changed

5 files changed

+101
-21
lines changed

src/assets/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ENV MAX_HEAP_SIZE=""
88

99
WORKDIR $SERVER_DIR
1010

11-
COPY scripts/run.sh /usr/local/bin/run.sh
11+
COPY run.sh /usr/local/bin/run.sh
1212
RUN chmod +x /usr/local/bin/run.sh
1313

1414
ENTRYPOINT ["/usr/local/bin/run.sh"]

src/cli/builder.py

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from click import Command, Option
1010
from yaspin import yaspin # type: ignore
1111

12-
from ..core.manage_json import read_json, write_json # type: ignore
12+
from ..core.copy_files import *
13+
from ..core.manage_json import read_json, write_json
1314
from ..core.manage_templates import template_to_file
1415
from ..utils.cli import clear, confirm
1516
from .custom_group import CustomGroup
@@ -22,16 +23,18 @@ def __init__(self) -> None:
2223
super().__init__()
2324

2425
def create(self) -> Command:
25-
help = ""
26+
help = (
27+
"Create all files for the containerization of the server/network."
28+
)
2629
options = [Option(["--network"], is_flag=True, default=False)]
2730

2831
def callback(network: bool = False) -> None:
32+
clear(0)
33+
2934
services: set[dict[str, Any]] = set([])
3035
networks: set[str] = set([])
3136
envs: set[dict[str, Any]] = set([])
3237

33-
clear(0)
34-
3538
if not network:
3639
menu = Menus()
3740
service, env = self.__get_data(menu)
@@ -53,13 +56,14 @@ def callback(network: bool = False) -> None:
5356
services.add(service)
5457
envs.add(env)
5558

56-
clear(1)
59+
clear(0.5)
5760

5861
if not confirm(
5962
msg=f"Want to continue adding services? (Count: {len(services)})",
6063
):
6164
break
6265

66+
clear(0)
6367
self.__save_files(
6468
data={
6569
"compose": {
@@ -69,6 +73,8 @@ def callback(network: bool = False) -> None:
6973
"envs": envs,
7074
}
7175
)
76+
clear(0)
77+
print("Files saved!")
7278

7379
return Command(
7480
name=inspect.currentframe().f_code.co_name, # type: ignore
@@ -78,11 +84,71 @@ def callback(network: bool = False) -> None:
7884
)
7985

8086
def update(self) -> Command:
81-
help = ""
82-
options = [Option()]
87+
help = "Update the contents of the containers."
88+
options = [
89+
Option(["--service"], default=None),
90+
Option(["--add"], is_flag=True, default=False),
91+
Option(["--remove"], is_flag=True, default=False),
92+
]
93+
94+
def callback(
95+
service: str | None = None, add: bool = False, remove: bool = False
96+
) -> None:
97+
clear(0)
98+
99+
path: Path = Path()
100+
101+
if not path.exists():
102+
print("Missing JSON file for services. Use 'create' first.")
103+
return
104+
105+
data: dict[str, Any] = read_json(Path()) or {}
106+
compose: dict[str, Any] = data.get("compose", {}) or {}
107+
108+
services: set[dict[str, Any]] = set(compose.get("services", []))
109+
networks: set[str] = set(compose.get("networks", []))
110+
envs: set[dict[str, Any]] = set(data.get("envs", []))
111+
112+
if networks:
113+
pass
114+
if envs:
115+
pass
116+
117+
if not services:
118+
print("No services found. Use 'create' first.")
119+
return
120+
121+
return Command(
122+
name=inspect.currentframe().f_code.co_name, # type: ignore
123+
help=help,
124+
callback=callback,
125+
params=options, # type: ignore
126+
)
83127

84-
def callback() -> None:
85-
pass
128+
def build(self) -> Command:
129+
help = "Build the files for the containerization in case create failed."
130+
options: list[Option] = []
131+
132+
def callback(
133+
service: str | None = None, add: bool = False, remove: bool = False
134+
) -> None:
135+
clear(0)
136+
137+
path: Path = Path()
138+
139+
if not path.exists():
140+
print("Missing JSON file for services. Use 'create' first.")
141+
return
142+
143+
data: dict[str, Any] = read_json(Path()) or {}
144+
145+
if not data:
146+
print("JSON file is empty. Use 'create' first.")
147+
148+
clear(0)
149+
self.__save_files(data, build=True)
150+
clear(0)
151+
print("Files saved!")
86152

87153
return Command(
88154
name=inspect.currentframe().f_code.co_name, # type: ignore
@@ -94,7 +160,7 @@ def callback() -> None:
94160
def __get_data(
95161
self, menu: Menus, get_service: bool = True, get_env: bool = True
96162
) -> tuple[dict[str, Any], dict[str, Any]]:
97-
clear(1)
163+
clear(0.5)
98164

99165
name = self.__get_name(message="Enter the name of the service: ")
100166

@@ -110,6 +176,7 @@ def __get_data(
110176

111177
def __get_name(self, message: str) -> str:
112178
while True:
179+
clear(0.5)
113180
name: str = inquirer.text( # type: ignore
114181
message=message, validate=EmptyInputValidator()
115182
).execute()
@@ -119,8 +186,10 @@ def __get_name(self, message: str) -> str:
119186

120187
return name
121188

122-
def __save_files(self, data: dict[str, Any]) -> None:
123-
write_json(Path(), data)
189+
@yaspin(text="Creating files...", color="cyan")
190+
def __save_files(self, data: dict[str, Any], build: bool = False) -> None:
191+
if not build:
192+
write_json(Path(), data)
124193

125194
composer: dict[str, Any] = data.get("composer") or {}
126195
template_to_file(Path(), composer, Path())

src/cli/manager.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from InquirerPy.validator import EmptyInputValidator # type: ignore
77
from click import Command, Option
88

9-
from ..utils.cli import clear # type: ignore
9+
from ..utils.cli import clear, confirm # type: ignore
1010
from .custom_group import CustomGroup
1111

1212

@@ -15,9 +15,9 @@ class Manager(CustomGroup):
1515
def __init__(self) -> None:
1616
super().__init__()
1717

18-
def bakcup(self) -> Command:
18+
def backup(self) -> Command:
1919

20-
help = ""
20+
help = "Create a backup of the files inside the containers to their respective build directories."
2121
options = [Option()]
2222

2323
def callback() -> None:
@@ -32,7 +32,7 @@ def callback() -> None:
3232

3333
def delete(self) -> Command:
3434

35-
help = ""
35+
help = "Delete entirely the files related with the containerization of the server/network."
3636
options = [Option()]
3737

3838
def callback() -> None:
@@ -47,7 +47,7 @@ def callback() -> None:
4747

4848
def start(self) -> Command:
4949

50-
help = ""
50+
help = "Start the services."
5151
options = [Option()]
5252

5353
def callback() -> None:
@@ -62,7 +62,7 @@ def callback() -> None:
6262

6363
def stop(self) -> Command:
6464

65-
help = ""
65+
help = "Stop the services."
6666
options = [Option()]
6767

6868
def callback() -> None:

src/cli/menu.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def service(self, name: str) -> dict[str, Any]:
6565

6666
def __get_ports(self) -> None:
6767
while True:
68-
clear(1)
68+
clear(0.5)
6969

7070
port_name = inquirer.text( # type: ignore
7171
message="Add a name for the port: ",
@@ -92,7 +92,7 @@ def __expose(self) -> set[str]:
9292
expose: set[str] = set()
9393

9494
for name, port in self.ports.items():
95-
clear(1)
95+
clear(0.5)
9696

9797
if confirm(msg=f"Want to expose {name} assigned to {port}? "):
9898
expose.add(f"${{{name}}}")
@@ -101,6 +101,8 @@ def __expose(self) -> set[str]:
101101

102102
def __resources(self) -> None:
103103
while True:
104+
clear(0.5)
105+
104106
cpus_limit: float = inquirer.number( # type: ignore
105107
message="Select a limit of CPUs for this service: ",
106108
min_allowed=0,
@@ -162,6 +164,8 @@ def env(self, name: str) -> dict[str, Any]:
162164

163165
def __get_jar(self) -> str:
164166
while True:
167+
clear(0.5)
168+
165169
jar: str = inquirer.text( # type: ignore
166170
message="Enter your .jar file name: ",
167171
validate=EmptyInputValidator(),
@@ -173,6 +177,8 @@ def __get_jar(self) -> str:
173177
return jar
174178

175179
def __use_args(self) -> str:
180+
clear(0.5)
181+
176182
if confirm(msg="Want to use recommended args for the server? "):
177183
with open("", "r+") as f:
178184
data = " ".join(f.readlines())
@@ -181,6 +187,8 @@ def __use_args(self) -> str:
181187

182188
def __get_heaps(self) -> list[str]:
183189
while True:
190+
clear(0.5)
191+
184192
min_heap_size: int = int(
185193
inquirer.number( # type: ignore
186194
message="Select the minimum heap size: ",

src/core/copy_files.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from __future__ import annotations
2+
3+
from pathlib import Path # type: ignore

0 commit comments

Comments
 (0)