https://github.com/cloudymax/orm-events
File I/O helpers
https://github.com/cloudymax/orm-events
Last synced: 3 months ago
JSON representation
File I/O helpers
- Host: GitHub
- URL: https://github.com/cloudymax/orm-events
- Owner: cloudymax
- Created: 2021-08-10T12:52:48.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2022-04-17T14:51:08.000Z (about 4 years ago)
- Last Synced: 2026-01-14T14:42:38.356Z (5 months ago)
- Language: Python
- Size: 40.3 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ORM-Events
___
Attemptes to recreate C# getter/setter wich will generate events
docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/using-properties
https://docs.microsoft.com/en-us/dotnet/standard/events/
## Usage
- See demo.py for serialization, de-serialization, and format conversion examples.
___
__To Run the demo:__
```bash
# cd to the program folder
cd io_tools
# install dependencies
pip3 install -r requirements.txt
# run the script
python3 demo.py
```
__Step by step in:__
```zsh
python3
```
```python
import io_tools as io
import json
settings = {}
vars = io.Variables(settings)
vars.debug = True
vars.go_steppy = False
vars.yaml_input_file = "pref_input_test.yaml"
vars.json_input_file = "cache.json"
# reads a file of TYPE
vars.yaml_file_contents = io.read_yaml_file(vars.yaml_input_file)
vars.json_file_contents = io.read_json_file(vars.json_input_file)
# print as pretty json
io.print_pretty(vars.json_file_contents, vars.debug, "json")
io.print_pretty(vars.yaml_file_contents, vars.debug, "json")
# print as compact json
print(vars.__dict__)
# Serialize
json_string = print(vars.__dict__)
io.write_file('cache.json', vars.__dict__, vars.debug)
# Can write CSVs as well, but only working properly on non-nested files. WIP.
csv = io.json_to_csv('cache.json')
```
## Class Methods
___
### Datastore
Datastore is a `:` dict that accepts any types and is used for portability. It achieves this by storing all variables in a generic dictionary with the `change()` method overriden to be an event system.
### Variables
Object that holds a list of `Datastore()`s,
When eneabled, the built-in `go_steppy()` function will pause script execution on any memory state change to provide a json formatted diff. for example:

change_value:
Triggered when any variable within the `Datastore()` is updated, or created.
get_current_value:
Returns the current value of a variable within the `Datastore()`, and triggers an event.
diff_values:
When enabled, deepdiffs the current and proposed change to the `Datastore()` object