Skip to content

Commit bfdbe9b

Browse files
committed
Implement StateDirectory methods.
1 parent ebf88cf commit bfdbe9b

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

src/directory/config_directory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use pyo3::{exceptions::PyRuntimeError, prelude::*, types::PyString};
55

66
/// A configuration directory stored on a file system (e.g., `$HOME/.asimov/configs/`).
77
#[pyclass(frozen, module = "asimov", str = "{0}")]
8-
pub struct ConfigDirectory(FsConfigDirectory);
8+
pub struct ConfigDirectory(pub(crate) FsConfigDirectory);
99

1010
#[pymethods]
1111
impl ConfigDirectory {

src/directory/module_directory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use pyo3::{exceptions::PyRuntimeError, prelude::*, types::PyString};
55

66
/// A module directory stored on a file system (e.g., `$HOME/.asimov/modules/`).
77
#[pyclass(frozen, module = "asimov", str = "{0}")]
8-
pub struct ModuleDirectory(FsModuleDirectory);
8+
pub struct ModuleDirectory(pub(crate) FsModuleDirectory);
99

1010
#[pymethods]
1111
impl ModuleDirectory {

src/directory/program_directory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use pyo3::{exceptions::PyRuntimeError, prelude::*, types::PyString};
55

66
/// A program directory stored on a file system (e.g., `$HOME/.asimov/libexec/`).
77
#[pyclass(frozen, module = "asimov", str = "{0}")]
8-
pub struct ProgramDirectory(FsProgramDirectory);
8+
pub struct ProgramDirectory(pub(crate) FsProgramDirectory);
99

1010
#[pymethods]
1111
impl ProgramDirectory {

src/directory/state_directory.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// This is free and unencumbered software released into the public domain.
22

3+
use super::{ConfigDirectory, ModuleDirectory, ProgramDirectory};
34
use asimov_directory::{StateDirectory as _, fs::StateDirectory as FsStateDirectory};
45
use pyo3::{exceptions::PyRuntimeError, prelude::*, types::PyString};
56

67
/// A state directory stored on a file system (e.g., `$HOME/.asimov/`).
78
#[pyclass(frozen, module = "asimov", str = "{0}")]
8-
pub struct StateDirectory(FsStateDirectory);
9+
pub struct StateDirectory(pub(crate) FsStateDirectory);
910

1011
#[pymethods]
1112
impl StateDirectory {
@@ -51,4 +52,34 @@ impl StateDirectory {
5152
pub fn has_programs(&self) -> bool {
5253
self.0.has_programs()
5354
}
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+
}
5485
}

0 commit comments

Comments
 (0)