|
1 | 1 | // This is free and unencumbered software released into the public domain. |
2 | 2 |
|
| 3 | +use super::{ConfigDirectory, ModuleDirectory, ProgramDirectory}; |
3 | 4 | use asimov_directory::{StateDirectory as _, fs::StateDirectory as FsStateDirectory}; |
4 | 5 | use pyo3::{exceptions::PyRuntimeError, prelude::*, types::PyString}; |
5 | 6 |
|
6 | 7 | /// A state directory stored on a file system (e.g., `$HOME/.asimov/`). |
7 | 8 | #[pyclass(frozen, module = "asimov", str = "{0}")] |
8 | | -pub struct StateDirectory(FsStateDirectory); |
| 9 | +pub struct StateDirectory(pub(crate) FsStateDirectory); |
9 | 10 |
|
10 | 11 | #[pymethods] |
11 | 12 | impl StateDirectory { |
@@ -51,4 +52,34 @@ impl StateDirectory { |
51 | 52 | pub fn has_programs(&self) -> bool { |
52 | 53 | self.0.has_programs() |
53 | 54 | } |
| 55 | + |
| 56 | + /// Opens the configuration directory under this state directory. |
| 57 | + pub fn configs(&self) -> PyResult<ConfigDirectory> { |
| 58 | + let Ok(result) = self.0.configs() else { |
| 59 | + Err(PyErr::new::<PyRuntimeError, _>( |
| 60 | + "Failed to open configuration directory", // TODO |
| 61 | + ))? |
| 62 | + }; |
| 63 | + Ok(ConfigDirectory(result)) |
| 64 | + } |
| 65 | + |
| 66 | + /// Opens the module directory under this state directory. |
| 67 | + pub fn modules(&self) -> PyResult<ModuleDirectory> { |
| 68 | + let Ok(result) = self.0.modules() else { |
| 69 | + Err(PyErr::new::<PyRuntimeError, _>( |
| 70 | + "Failed to open module directory", // TODO |
| 71 | + ))? |
| 72 | + }; |
| 73 | + Ok(ModuleDirectory(result)) |
| 74 | + } |
| 75 | + |
| 76 | + /// Opens the program directory under this state directory. |
| 77 | + pub fn programs(&self) -> PyResult<ProgramDirectory> { |
| 78 | + let Ok(result) = self.0.programs() else { |
| 79 | + Err(PyErr::new::<PyRuntimeError, _>( |
| 80 | + "Failed to open program directory", // TODO |
| 81 | + ))? |
| 82 | + }; |
| 83 | + Ok(ProgramDirectory(result)) |
| 84 | + } |
54 | 85 | } |
0 commit comments