diff options
| author | Pavel Egorov <[email protected]> | 2025-12-16 14:29:17 +0300 |
|---|---|---|
| committer | Pavel Egorov <[email protected]> | 2025-12-16 14:29:17 +0300 |
| commit | abbdb8e6e57dc7627bcf31282ef0eaf9e4241a4c (patch) | |
| tree | bef202afa1600749e8ad521d166478006de738e0 /.config/fastfetch/confgen.py | |
| parent | 4150244bc05b0adc380c8c1af7a31fea9d7b8a53 (diff) | |
| download | dotfiles-abbdb8e6e57dc7627bcf31282ef0eaf9e4241a4c.tar.gz dotfiles-abbdb8e6e57dc7627bcf31282ef0eaf9e4241a4c.zip | |
[fastfetch] more code cleanup
Diffstat (limited to '.config/fastfetch/confgen.py')
| -rw-r--r-- | .config/fastfetch/confgen.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/.config/fastfetch/confgen.py b/.config/fastfetch/confgen.py index e8b1383..c368582 100644 --- a/.config/fastfetch/confgen.py +++ b/.config/fastfetch/confgen.py | |||
| @@ -199,7 +199,7 @@ roots = [ | |||
| 199 | ] | 199 | ] |
| 200 | 200 | ||
| 201 | 201 | ||
| 202 | def build_config(roots) -> dict[str, type[Any]]: | 202 | def build_config(roots: list[Node]) -> dict[str, type[Any]]: |
| 203 | schema = { | 203 | schema = { |
| 204 | "$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json" | 204 | "$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json" |
| 205 | } | 205 | } |
| @@ -211,9 +211,9 @@ def build_config(roots) -> dict[str, type[Any]]: | |||
| 211 | return schema | logo | modules | 211 | return schema | logo | modules |
| 212 | 212 | ||
| 213 | 213 | ||
| 214 | def get_test_response() -> list[dict]: | 214 | def get_test_response(config: dict[str, type[Any]]) -> list[dict]: |
| 215 | with NamedTemporaryFile(mode='w', delete_on_close=False, suffix=".jsonc") as tmp_config: | 215 | with NamedTemporaryFile(mode='w', delete_on_close=False, suffix=".jsonc") as tmp_config: |
| 216 | json.dump(build_config(roots), tmp_config) | 216 | json.dump(config, tmp_config) |
| 217 | tmp_config.flush() | 217 | tmp_config.flush() |
| 218 | 218 | ||
| 219 | fastfetch_response = subprocess.run( | 219 | fastfetch_response = subprocess.run( |
| @@ -224,11 +224,22 @@ def get_test_response() -> list[dict]: | |||
| 224 | return json.loads(fastfetch_response.stdout) | 224 | return json.loads(fastfetch_response.stdout) |
| 225 | 225 | ||
| 226 | 226 | ||
| 227 | def filter_roots(roots) -> list[Node]: | 227 | def filter_roots(roots: list[Node], data: list[dict]) -> list[Node]: |
| 228 | skip_modules = ["Custom"] | 228 | skip_modules = ["Custom"] |
| 229 | for response_object in get_test_response(): | 229 | for response_object in data: |
| 230 | if response_object.get("error") and response_object.get("type") not in skip_modules or response_object.get("result") == []: | 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: | 231 | for root in roots: |
| 232 | root.remove_module(response_object.get("type").lower()) | 232 | root.remove_module(response_object.get("type").lower()) |
| 233 | return roots | 233 | return roots |
| 234 | 234 | ||
| 235 | |||
| 236 | def main(): | ||
| 237 | test_config = build_config(roots) | ||
| 238 | test_data = get_test_response(test_config) | ||
| 239 | filtered_roots = filter_roots(roots, test_data) | ||
| 240 | final_config = build_config(filtered_roots) | ||
| 241 | print(json.dumps(final_config)) | ||
| 242 | |||
| 243 | |||
| 244 | if __name__ == '__main__': | ||
| 245 | main() | ||
