diff options
Diffstat (limited to '.config')
| -rw-r--r-- | .config/fastfetch/confgen.py | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/.config/fastfetch/confgen.py b/.config/fastfetch/confgen.py index 22c53bc..e8b1383 100644 --- a/.config/fastfetch/confgen.py +++ b/.config/fastfetch/confgen.py | |||
| @@ -67,14 +67,14 @@ class Node: | |||
| 67 | 67 | ||
| 68 | return module | key | format | text | additional_entries | 68 | return module | key | format | text | additional_entries |
| 69 | 69 | ||
| 70 | def collect_branch(self): | 70 | def collect_branch(self) -> list[dict]: |
| 71 | return [self.construct_module()] + [node.collect_branch() for node in self.children] | 71 | return [self.construct_module()] + [node.collect_branch() for node in self.children] |
| 72 | 72 | ||
| 73 | def add_children(self, *nodes: type["Node"]) -> type["Node"]: | 73 | def add_children(self, *nodes: type["Node"]) -> type["Node"]: |
| 74 | self.children += nodes | 74 | self.children += nodes |
| 75 | return self | 75 | return self |
| 76 | 76 | ||
| 77 | def remove_module(self, module): | 77 | def remove_module(self, module) -> None: |
| 78 | for i, node in enumerate(self.children): | 78 | for i, node in enumerate(self.children): |
| 79 | if node.module == module: | 79 | if node.module == module: |
| 80 | del self.children[i] | 80 | del self.children[i] |
| @@ -82,12 +82,6 @@ class Node: | |||
| 82 | node.remove_module(module) | 82 | node.remove_module(module) |
| 83 | 83 | ||
| 84 | 84 | ||
| 85 | schema = { | ||
| 86 | "$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json" | ||
| 87 | } | ||
| 88 | |||
| 89 | logo = {"padding": {"left": 3, "right": 3, "top": 3}} | ||
| 90 | |||
| 91 | font_effects = { | 85 | font_effects = { |
| 92 | "reset": "#0", | 86 | "reset": "#0", |
| 93 | "software": "\u001b[38;2;0;255;0m", | 87 | "software": "\u001b[38;2;0;255;0m", |
| @@ -204,25 +198,37 @@ roots = [ | |||
| 204 | ) | 198 | ) |
| 205 | ] | 199 | ] |
| 206 | 200 | ||
| 207 | modules = {"modules": list(flatten(root.collect_branch() for root in roots))} | ||
| 208 | 201 | ||
| 209 | with NamedTemporaryFile(mode='w', delete_on_close=False, suffix=".jsonc") as tmp_config: | 202 | def build_config(roots) -> dict[str, type[Any]]: |
| 210 | json.dump(schema | logo | modules, tmp_config) | 203 | schema = { |
| 211 | tmp_config.flush() | 204 | "$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json" |
| 205 | } | ||
| 212 | 206 | ||
| 213 | fastfetch_response = subprocess.run( | 207 | logo = {"padding": {"left": 3, "right": 3, "top": 3}} |
| 214 | ["fastfetch", "--config", tmp_config.name, "--json"], | 208 | |
| 215 | capture_output=True | 209 | modules = {"modules": list(flatten(root.collect_branch() for root in roots))} |
| 216 | ) | 210 | |
| 211 | return schema | logo | modules | ||
| 212 | |||
| 213 | |||
| 214 | def get_test_response() -> list[dict]: | ||
| 215 | with NamedTemporaryFile(mode='w', delete_on_close=False, suffix=".jsonc") as tmp_config: | ||
| 216 | json.dump(build_config(roots), tmp_config) | ||
| 217 | tmp_config.flush() | ||
| 218 | |||
| 219 | fastfetch_response = subprocess.run( | ||
| 220 | ["fastfetch", "--config", tmp_config.name, "--json"], | ||
| 221 | capture_output=True | ||
| 222 | ) | ||
| 217 | 223 | ||
| 218 | fastfetch_data = json.loads(fastfetch_response.stdout) | 224 | return json.loads(fastfetch_response.stdout) |
| 219 | 225 | ||
| 220 | skip_modules = ["Custom"] | ||
| 221 | for response_object in fastfetch_data: | ||
| 222 | if response_object.get("error") and response_object.get("type") not in skip_modules or response_object.get("result") == []: | ||
| 223 | for root in roots: | ||
| 224 | root.remove_module(response_object.get("type").lower()) | ||
| 225 | 226 | ||
| 226 | modules = {"modules": list(flatten(root.collect_branch() for root in roots))} | 227 | def filter_roots(roots) -> list[Node]: |
| 228 | skip_modules = ["Custom"] | ||
| 229 | for response_object in get_test_response(): | ||
| 230 | if response_object.get("error") and response_object.get("type") not in skip_modules or response_object.get("result") == []: | ||
| 231 | for root in roots: | ||
| 232 | root.remove_module(response_object.get("type").lower()) | ||
| 233 | return roots | ||
| 227 | 234 | ||
| 228 | print(json.dumps(modules)) | ||
