File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import json
12import os
23from collections import Counter
34from enum import StrEnum
@@ -128,3 +129,30 @@ def list_incomplete(self):
128129 return [
129130 k for k , v in self .details .items () if v ["status" ] == JobStatus .NOT_CONVERGED
130131 ]
132+
133+ def dumps_status (self , format = "json" ):
134+ """
135+ Dump the folder status (only folder name and status) in JSON or YAML format as a string.
136+
137+ Args:
138+ format (str): Output format, either 'json' or 'yaml'. Defaults to 'json'.
139+
140+ Returns:
141+ str: The folder-to-status mapping serialized in the requested format.
142+
143+ Raises:
144+ ValueError: If the format is not 'json' or 'yaml'.
145+ """
146+ status_map = {k : v ["status" ] for k , v in self .details .items ()}
147+ if format == "json" :
148+ return json .dumps (status_map , indent = 2 )
149+ elif format == "yaml" :
150+ try :
151+ import yaml
152+ except ImportError :
153+ raise ImportError (
154+ "PyYAML is required for YAML output. Install with 'pip install pyyaml'."
155+ )
156+ return yaml .dump (status_map , sort_keys = False )
157+ else :
158+ raise ValueError ("Format must be 'json' or 'yaml'." )
You can’t perform that action at this time.
0 commit comments