Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tutosrive/Constellations/llms.txt
Use this file to discover all available pages before exploring further.
FilesUtils in src/utils/Files.py provides all file I/O for the Constellations project. Every method is @staticmethod and returns a structured response object — either BaseReturn or DataAndMsgReturn — rather than raising exceptions to the caller. This makes FilesUtils safe to invoke directly inside UI callbacks and controller methods without wrapping calls in try/except blocks.
Response Objects
Two return types are used across all methods:| Class | Fields | Used when |
|---|---|---|
BaseReturn | ok: bool, error: Any | None | Write operations where only success/failure matters |
DataAndMsgReturn | ok, error, msg: str, data: dict | None | Read operations that must carry back file contents |
to_dict() helper and a __str__ representation for logging.
Methods
file_exists
True if the path points to an existing regular file, using pathlib.Path.is_file().
Relative or absolute path to check.
open_file
mode='r', file_exists is checked first; if the file is absent, None is returned immediately. When mode='w', Python creates the file automatically if it does not exist.
Path to the file to open.
Standard Python file mode.
'r' for read, 'w' for overwrite, 'a' for append.Character encoding passed to the built-in
open().read_file
DataAndMsgReturn where data is the raw string content. If open_file returns None (file missing), data remains None.
Path to the text file to read.
read_json
read_file, then parses the result with json.loads. On a JSON parse error, response.error is set to the exception and response.data remains None. If the file does not exist, response.msg is set to a human-readable message and response.data is None.
Path to the
.json file to read and parse.write_file
data to filename. The mode parameter must be either 'w' (overwrite) or 'a' (append); any other value causes response.ok = False and response.error = "The mode isn't valid!". Any OS-level exception during the write is caught and stored in response.error.
Destination file path. Created automatically if it does not exist (when using
'w' or 'a').String content to write.
Must be
'w' (overwrite) or 'a' (append).write_json
data to filename using json.dump with indent=2, sort_keys=True, and ensure_ascii=False. Returns a BaseReturn; on failure, ok is False and error contains the exception message.
Destination file path for the serialised JSON.
The Python dictionary to serialise.
get_filename_from_path
pathlib.Path(path).name.
Any relative or absolute file path string.
Example: Loading a Graph JSON
Example: Writing a Log File
write_json uses ensure_ascii=False so that constellation names containing non-ASCII characters — such as Spanish accented letters (e.g. Ío, Cáncer) — are written verbatim rather than being replaced with \uXXXX escape sequences. This keeps the JSON file human-readable and diff-friendly in version control.