cligram.state_manager
State management module for presistent application data.
- class cligram.state_manager.JsonState[source]
Bases:
StateJSON-based state implementation.
- changed()[source]
Check if state changed since last reset.
- Return type:
- Returns:
True if state has changed, False otherwise
- ensure_schema(data)[source]
Ensure current data matches schema.
- Parameters:
- Raises:
ValueError – If data does not match schema
- Return type:
- set_changed(changed)[source]
Set the changed status of the state.
This method is used internally to mark the state as changed or unchanged.
- class cligram.state_manager.State[source]
Bases:
ABCAbstract base class for state storage.
Defines interface for loading, exporting, and tracking changes to state data.
- abstractmethod changed()[source]
Check if state changed since last reset.
- Return type:
- Returns:
True if state has changed, False otherwise
- abstractmethod export()[source]
Export current state data.
- Return type:
- Returns:
Current state data
- static parse(content)[source]
Parse state input contents.
Subclasses may override this method to implement custom parsing logic.
The default implementation returns the content as-is.
- class cligram.state_manager.StateManager(data_dir, backup_dir=None)[source]
Bases:
objectManages persistent application state and handles file-based storage operations.
Provides methods to register state types, load/save states, and perform backups/restores of state data.
- backup_dir
Directory for backup files
- data_dir
Directory for state files
- lock
Lock for synchronizing state operations
- classmethod register(name, state_class)[source]
Register a new state type.
This method does not affect existing StateManager instances.