Extracted class from app.py

This commit is contained in:
Luis Hebendanz 2023-12-01 15:18:05 +01:00
parent a4a16361c9
commit f9b7c5a468
3 changed files with 85 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 KiB

View File

@ -0,0 +1,85 @@
from collections import OrderedDict
from pathlib import Path
from typing import Any
import clan_cli
class VM:
def __init__(
self,
*,
icon: Path,
name: str,
url: str,
path: Path,
running: bool = False,
autostart: bool = False,
) -> None:
self.icon = icon.resolve()
assert self.icon.exists()
assert self.icon.is_file()
self.url = url
self.autostart = autostart
self.running = running
self.name = name
self.path = path.resolve()
print(self.path)
assert self.path.exists()
assert self.path.is_dir()
def list_display(self) -> OrderedDict[str, Any]:
return OrderedDict(
{
"Icon": str(self.icon),
"Name": self.name,
"URL": self.url,
"Running": self.running,
}
)
def list_vms() -> list[VM]:
assets = Path(__file__).parent / "assets"
vms = [
VM(
icon=assets / "cybernet.jpeg",
name="Cybernet Clan",
url="clan://cybernet.lol",
path=Path(__file__).parent.parent / "test_democlan",
running=True,
),
VM(
icon=assets / "zenith.jpeg",
name="Zenith Clan",
url="clan://zenith.lol",
path=Path(__file__).parent.parent / "test_democlan",
),
VM(
icon=assets / "firestorm.jpeg",
name="Firestorm Clan",
url="clan://firestorm.lol",
path=Path(__file__).parent.parent / "test_democlan",
),
VM(
icon=assets / "placeholder.jpeg",
name="Demo Clan",
url="clan://demo.lol",
path=Path(__file__).parent.parent / "test_democlan",
),
]
# vms.extend(vms)
# vms.extend(vms)
# vms.extend(vms)
for path in clan_cli.flakes.history.list_history():
new_vm = {
"icon": assets / "placeholder.jpeg",
"name": "Placeholder Clan",
"url": "clan://placeholder.lol",
"path": path,
}
vms.append(VM(**new_vm))
return vms