Skip to content

Commit c64757b

Browse files
committed
feat: fully working functionality for spinning up lab instances
1 parent e964ae1 commit c64757b

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

appwrite_lab/_orchestrator.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,25 @@ def __init__(self, state: State, backend: str = "auto"):
4343
Path(__file__).parent / "templates" / "environment" / "dotenv"
4444
)
4545

46-
def get_labs(self):
46+
def get_labs(self, collapsed: bool = False):
4747
"""
4848
Get all labs.
4949
"""
50-
return self.state.get("labs", {})
50+
labs: dict = self.state.get("labs", {})
51+
if collapsed:
52+
headers = ["Name", "Version", "URL", "Admin Email", "Project ID", "API Key"]
53+
return headers, [
54+
[
55+
val["name"],
56+
val["version"],
57+
val["url"],
58+
val["admin_email"],
59+
val["project_id"],
60+
val["api_key"],
61+
]
62+
for val in labs.values()
63+
]
64+
return labs
5165

5266
def get_running_pods(self):
5367
"""
@@ -267,7 +281,6 @@ def deploy_playwright_automation(
267281
if result_file.exists():
268282
with open(result_file, "r") as f:
269283
data = f.read()
270-
print("RESULT FILE", data)
271284
return data
272285
else:
273286
return None

appwrite_lab/cli/list_menu.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from appwrite_lab import get_global_labs
2-
from appwrite_lab.utils import print_table, console
2+
from appwrite_lab.utils import print_table, print_2d_table, console
33
from appwrite_lab._orchestrator import get_template_versions
44
import typer
55

@@ -11,12 +11,12 @@
1111
@list_menu.command(name="labs")
1212
def get_labs():
1313
"""List all ephemeral Appwrite instances."""
14-
pods = labs.orchestrator.get_labs()
15-
console.print(pods)
16-
# print_table(pods, ["Name", "Version", "Status"])
14+
headers, pods = labs.orchestrator.get_labs(collapsed=True)
15+
print_table(pods, headers)
16+
1717

1818
@list_menu.command()
1919
def versions():
2020
"""List all available Appwrite versions."""
2121
versions = get_template_versions()
22-
print_table(versions, ["Version"])
22+
print_table([versions], ["Version"])

appwrite_lab/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ def generate_missing_config(self):
4545
random.choices(string.ascii_letters + string.digits, k=16)
4646
)
4747
if not self.project_name:
48-
self.project_name = "Default_{self.project_id}"
48+
self.project_name = f"Default_{self.project_id}"

appwrite_lab/playwright/functions/create_user_and_api_key.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ async def create_user_and_api_key(playwright: Playwright) -> str:
5555
await browser.close()
5656

5757
try:
58-
with open("result.txt", "w") as f:
59-
print("API KEY", api_key)
58+
with open("/playwright/result.txt", "w") as f:
6059
f.write(api_key)
6160
except Exception as e:
6261
print("ERROR", e)

appwrite_lab/utils.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,19 @@ def ensure_dir():
1818
return True
1919

2020

21-
def print_table(data: list[dict], headers: list[str]):
22-
"""Print a table of data."""
21+
def print_table(data: list[list], headers: list[str]):
22+
"""Print a 2D table of data.
23+
24+
Args:
25+
data: A list of lists of data.
26+
headers: A list of headers.
27+
"""
2328
console = Console()
24-
table = Table(*headers, style="purple")
29+
table = Table(style="purple")
30+
for header in headers:
31+
table.add_column(header, overflow="fold", style="purple")
2532
for row in data:
26-
table.add_row(row)
33+
table.add_row(*row)
2734
console.print(table)
2835

2936

0 commit comments

Comments
 (0)