2024-02-26 14:33:26 +00:00
|
|
|
from modules.cluster import Cluster
|
|
|
|
from typing import List
|
|
|
|
import os
|
|
|
|
|
|
|
|
class Galaxy:
|
2024-03-01 15:30:49 +00:00
|
|
|
def __init__(self, galaxy_name: str, json_file_name: str, authors: List[str], description: str):
|
|
|
|
self.galaxy_name = galaxy_name
|
|
|
|
self.json_file_name = json_file_name
|
2024-02-26 14:33:26 +00:00
|
|
|
self.authors = authors
|
|
|
|
self.description = description
|
|
|
|
|
2024-03-01 15:30:49 +00:00
|
|
|
self.clusters = {} # Maps uuid to Cluster objects
|
|
|
|
|
|
|
|
def add_cluster(self, uuid, description, value, meta):
|
|
|
|
if uuid not in self.clusters:
|
|
|
|
self.clusters[uuid] = Cluster(uuid=uuid, galaxy=self, description=description, value=value, meta=meta)
|
|
|
|
|
|
|
|
def write_entry(self, path):
|
|
|
|
if not os.path.exists(path):
|
|
|
|
os.mkdir(path)
|
|
|
|
with open(os.path.join(path, f"{self.galaxy_name}.md"), "w") as index:
|
|
|
|
index.write(self.generate_entry())
|
|
|
|
|
|
|
|
def generate_entry(self):
|
|
|
|
entry = ""
|
|
|
|
entry += self._create_metadata_entry()
|
|
|
|
entry += self._create_title_entry()
|
|
|
|
entry += self._create_description_entry()
|
|
|
|
entry += self._create_authors_entry()
|
|
|
|
entry += self._create_clusters_entry()
|
|
|
|
return entry
|
|
|
|
|
2024-02-26 14:33:26 +00:00
|
|
|
def _create_metadata_entry(self):
|
2024-03-01 15:30:49 +00:00
|
|
|
entry = ""
|
|
|
|
entry += "---\n"
|
|
|
|
entry += f"title: {self.galaxy_name}\n"
|
2024-02-26 14:33:26 +00:00
|
|
|
meta_description = self.description.replace('"', "-")
|
2024-03-01 15:30:49 +00:00
|
|
|
entry += f"description: {meta_description}\n"
|
|
|
|
entry += "---\n"
|
|
|
|
return entry
|
2024-02-26 14:33:26 +00:00
|
|
|
|
|
|
|
def _create_title_entry(self):
|
2024-03-01 15:30:49 +00:00
|
|
|
entry = ""
|
|
|
|
entry += f"# {self.galaxy_name}\n"
|
|
|
|
return entry
|
2024-02-26 14:33:26 +00:00
|
|
|
|
|
|
|
def _create_description_entry(self):
|
2024-03-01 15:30:49 +00:00
|
|
|
entry = ""
|
|
|
|
entry += f"{self.description}\n"
|
|
|
|
return entry
|
2024-02-26 14:33:26 +00:00
|
|
|
|
|
|
|
def _create_authors_entry(self):
|
2024-03-01 15:30:49 +00:00
|
|
|
entry = ""
|
2024-02-26 14:33:26 +00:00
|
|
|
if self.authors:
|
2024-03-01 15:30:49 +00:00
|
|
|
entry += f"\n"
|
|
|
|
entry += f'??? info "Authors"\n'
|
|
|
|
entry += f"\n"
|
|
|
|
entry += f" | Authors and/or Contributors|\n"
|
|
|
|
entry += f" |----------------------------|\n"
|
2024-02-26 14:33:26 +00:00
|
|
|
for author in self.authors:
|
2024-03-01 15:30:49 +00:00
|
|
|
entry += f" |{author}|\n"
|
|
|
|
return entry
|
2024-02-26 14:33:26 +00:00
|
|
|
|
2024-03-01 15:30:49 +00:00
|
|
|
def _create_clusters_entry(self):
|
|
|
|
entry = ""
|
|
|
|
for cluster in self.clusters.values():
|
|
|
|
entry += cluster.generate_entry()
|
|
|
|
return entry
|